mirror of
https://github.com/sbrow/nu-ffmpeg.git
synced 2025-12-29 16:23:11 -05:00
feat: Filters can now be added as new chains, or appending the previous chain.
This commit is contained in:
106
filters.nu
106
filters.nu
@@ -1,56 +1,74 @@
|
||||
#!/usr/bin/env -S nu --stdin
|
||||
|
||||
export def "parse filter" [
|
||||
]: string -> table<name: string params: table<param: string, value: string>> {
|
||||
$in | parse --regex '^(?<name>[^=]+)=(?<params>.*)' | first | update params {
|
||||
parse --regex `(?<param>[^=]+)=(?<value>[^:]+):?`
|
||||
}
|
||||
}
|
||||
use std [assert];
|
||||
|
||||
export def "filter to-string" [
|
||||
]: table<name: string params: table<param: string, value: string>> -> string {
|
||||
each {
|
||||
$'($in.name)=($in.params | format '{param}={value}')'
|
||||
} | str join ':'
|
||||
}
|
||||
|
||||
# Build a record representaion of a complex filter
|
||||
export def complex-filter [
|
||||
name: string
|
||||
params: record = {}
|
||||
]: nothing -> record<name: string params: table<param: string, value: string>> {
|
||||
{
|
||||
name: $name
|
||||
params: ($params | transpose param value | compact param value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export def "complex-filters to-string" [
|
||||
--pretty-print (-p)
|
||||
]: table<input: list<string>, filters: table<name: string, params: table<param: string, value: string>>, output: string> -> string {
|
||||
$in | update filters {
|
||||
flatten | filter to-string
|
||||
} | update input {
|
||||
str join ']['
|
||||
} | format '[{input}]{filters}[{output}]' | str join (";" + (if $pretty_print { "\n" } else { "" })) | str replace --all '[]' ''
|
||||
}
|
||||
|
||||
# =============
|
||||
# Begin Filters
|
||||
# =============
|
||||
use ./ffmpeg.nu ["complex-filter" "cmd filters append"]
|
||||
|
||||
# loop video frames
|
||||
export def loop [
|
||||
--input (-i): list<string>: = []
|
||||
--output (-o): list<string>: = []
|
||||
loop: int # Set the number of loops. Setting this value to -1 will result in infinite loops. Default is 0.
|
||||
size: int # Set maximal size in number of frames. Default is 0.
|
||||
--start (-s): int # Set first frame of loop. Default is 0.
|
||||
--time (-t): float # Set the time of loop start in seconds. Only used if option named start is set to -1.
|
||||
] {
|
||||
complex-filter loop {
|
||||
loop: $loop
|
||||
size: $size
|
||||
start: (if ($time | is-empty) { $start } else { -1 })
|
||||
time: $time
|
||||
}
|
||||
cmd filters append [
|
||||
(complex-filter loop {
|
||||
loop: $loop
|
||||
size: $size
|
||||
start: (if ($time | is-empty) { $start } else { -1 })
|
||||
time: $time
|
||||
} -i $input -o $output)
|
||||
]
|
||||
}
|
||||
|
||||
export def fps [
|
||||
--input (-i): list<string>: = []
|
||||
--output (-o): list<string>: = []
|
||||
--round (-r): string
|
||||
|
||||
fps: int
|
||||
] {
|
||||
cmd filters append [
|
||||
(complex-filter fps {fps: $fps round: $round} -i $input)
|
||||
(complex-filter settb {expr: $'1/($fps)' } -o $output)
|
||||
]
|
||||
}
|
||||
|
||||
export def split [
|
||||
--input (-i): list<string>: = []
|
||||
--output (-o): string
|
||||
] {
|
||||
let cmd = $in;
|
||||
|
||||
let n = ($output | length);
|
||||
|
||||
$cmd | cmd filters append [(complex-filter 'split' (if $n != 2 {
|
||||
{'n': $n}
|
||||
} else {
|
||||
{}
|
||||
}) -i $input -o $output)]
|
||||
}
|
||||
|
||||
# TODO: Finish
|
||||
export def crop [
|
||||
--input: list<string> = []
|
||||
--width (-w): string = 'iw'
|
||||
--height (-h): string
|
||||
x = '0'
|
||||
y = '0'
|
||||
] {
|
||||
cmd filters append [
|
||||
(complex-filter crop {w: $width h: $height x: $x, y: $y} -i $input)
|
||||
]
|
||||
}
|
||||
|
||||
# TODO: Finish
|
||||
export def vflip [
|
||||
...output: string
|
||||
] {
|
||||
cmd filters append [
|
||||
(complex-filter vflip -o $output)
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user