ffmpeg-python
ffmpeg-python copied to clipboard
Add option to skip escaping for filter
I'm having the case where I found not other option than to monkey-patch the escape_chars function as it just did the wrong thing for me: ffmpeg.nodes.escape_chars = lambda x, y:x
I tried to translate the following ffmpeg command
ffmpeg -i out.mp3 -filter_complex [0:a]loudnorm=print_format=json[s0] -map [s0] -f null -
By doing
ffmpeg.input('out.mp3').audio.filter('loudnorm', 'print_format=json').output('-', format='null')
However, escape_chars always resulted in this call:
ffmpeg -i out.mp3 -filter_complex [0:a]loudnorm=print_format\\\\\\=json[s0] -map [s0] -f null - which in the end produced syntax errors.
If a proper escaping is not possible, it would be splendid to at least be able to pass an escape=False argument do the filter() method.
With most filters, this can be avoided by providing each filter argument as a separate function argument:
filter("loudnorm", I=-16, TP=-1.5, LRA=6, print_format="json")
I'm having the same problem with implementing the pan filter though. The filter seems to expect the channel mapping within a single argument so I'm providing the following:
filter("pan", "1|c0=1*c0")
Resulting in:
[Parsed_pan_0 @ 000001498ca13cc0] Syntax error after channel name in "c0\=1*c0" [AVFilterGraph @ 000001498c244f40] Error initializing filter 'pan' with args '1|c0\\\=1*c0'
@jh42 I solved the pan issue by calling it with an dictionary of arguments, like this:
filter("pan", **{"1|c0":"1*c0"})
which results on a proper call without escaping.
I tried the dictionary solution for pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE (comes from here), and it gave the following error:
[Parsed_pan_7 @ 0x55919028d3c0] This syntax is deprecated. Use '|' to separate the list items ('stereo||FL\\\=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR\\\=0.5*FC+0.707*FR+0.707*BR+0.5*LFE' instead of 'stereo:|FL\\\=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR\\\=0.5*FC+0.707*FR+0.707*BR+0.5*LFE')
[AVFilterGraph @ 0x5591901a7a40] Error initializing filter 'pan' with args 'stereo:|FL\\\=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR\\\=0.5*FC+0.707*FR+0.707*BR+0.5*LFE'
Which is a combination of the result of the escape_chars function but also the 'pan' function not accepting colons for some reason.
for -af pan="mono: c0=FL"
I'm not sure how to apply the dictionary or if it makes sense to apply. Anyway, It seems I should use a | as a separator and the : is deprecated.