mirror of
https://github.com/sbrow/nu-ffmpeg.git
synced 2025-12-29 16:23:11 -05:00
feat: Added loop filter.
This commit is contained in:
46
filters.nu
46
filters.nu
@@ -1,16 +1,31 @@
|
|||||||
#!/usr/bin/env -S nu --stdin
|
#!/usr/bin/env -S nu --stdin
|
||||||
|
|
||||||
export def "parse filter" [
|
export def "parse filter" [
|
||||||
] {
|
]: string -> table<name: string params: table<param: string, value: string>> {
|
||||||
$in | parse --regex '^(?<name>[^=]+)=(?<params>.*)' | first |
|
$in | parse --regex '^(?<name>[^=]+)=(?<params>.*)' | first | update params {
|
||||||
update params { parse --regex `(?<param>[^=]+)=(?<value>[^:]+):?` }
|
parse --regex `(?<param>[^=]+)=(?<value>[^:]+):?`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export def "filter to-string" [] {
|
export def "filter to-string" [
|
||||||
each { |filter| $'($filter.name)=($filter.params | format '{param}={value}')' } |
|
]: table<name: string params: table<param: string, value: string>> -> string {
|
||||||
str join ':'
|
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" [
|
export def "complex-filters to-string" [
|
||||||
--pretty-print (-p)
|
--pretty-print (-p)
|
||||||
]: table<input: list<string>, filters: table<name: string, params: table<param: string, value: string>>, output: string> -> string {
|
]: table<input: list<string>, filters: table<name: string, params: table<param: string, value: string>>, output: string> -> string {
|
||||||
@@ -20,3 +35,22 @@ export def "complex-filters to-string" [
|
|||||||
str join ']['
|
str join ']['
|
||||||
} | format '[{input}]{filters}[{output}]' | str join (";" + (if $pretty_print { "\n" } else { "" })) | str replace --all '[]' ''
|
} | format '[{input}]{filters}[{output}]' | str join (";" + (if $pretty_print { "\n" } else { "" })) | str replace --all '[]' ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# =============
|
||||||
|
# Begin Filters
|
||||||
|
# =============
|
||||||
|
|
||||||
|
# loop video frames
|
||||||
|
export def loop [
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
25
filters_test.nu
Normal file
25
filters_test.nu
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env nu
|
||||||
|
|
||||||
|
use std [assert];
|
||||||
|
|
||||||
|
use ./filters.nu [complex-filter loop "parse filter"];
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
def loop_has_defaults [] {
|
||||||
|
let got = (loop 10 1);
|
||||||
|
let want = (complex-filter 'loop' { loop: 10 size: 1 });
|
||||||
|
assert equal $got $want;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
def setting_time_sets_start_to-1 [] {
|
||||||
|
let got = (loop 10 1 -t 0.5);
|
||||||
|
let want = (complex-filter 'loop' {
|
||||||
|
loop: 10
|
||||||
|
size: 1
|
||||||
|
start: -1
|
||||||
|
time: 0.5
|
||||||
|
});
|
||||||
|
|
||||||
|
assert equal $got $want;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user