kkroening / ffmpeg-python

Python bindings for FFmpeg - with complex filtering support
Apache License 2.0
10k stars 886 forks source link

Convert -vf to filter_complex, extra escape characters are added #646

Open x674 opened 2 years ago

x674 commented 2 years ago

Please help me how to get rid of reflective characters in the filter? I am trying to make such a filter . -vf "scale=trunc(iw/2)2:trunc(ih/2)2" But in the final line, escape characters are added to the argument.

import ffmpeg

stream = ffmpeg.input('D:\\Projects\\Python\\webmBotPython\\16468991399960.webm')

stream = ffmpeg.filter(stream, 'scale', 'trunc(iw/2)*2:trunc(ih/2)*2')

stream = ffmpeg.output(stream, 'D:\\Projects\\Python\\webmBotPython\\1.mp4',vcodec='h264_nvenc')

ffmpeg.compile(stream)

Output string

['ffmpeg', '-i', 'D:\\Projects\\Python\\webmBotPython\\16468991399960.webm',
 '-filter_complex', '[0]scale=trunc(iw/2)*2\\\\\\\\\\\\:trunc(ih/2)*2[s0]', '-map', '[s0]', '-vcodec', 'h264_nvenc',
 'D:\\Projects\\Python\\webmBotPython\\1.mp4']

Although I expect to see

['ffmpeg', '-i', 'D:\\Projects\\Python\\webmBotPython\\16468991399960.webm',
 '-filter_complex', '[0]scale=trunc(iw/2)*2:trunc(ih/2)*2[s0]', '-map', '[s0]', '-vcodec', 'h264_nvenc',
 'D:\\Projects\\Python\\webmBotPython\\1.mp4']
fsdsabel commented 2 years ago

I just had the same problem. This should do the trick:

ffmpeg.filter(stream, 'scale', 'trunc(iw/2)*2','trunc(ih/2)*2')