Ffmpeg-python: escape_chars fails in filter() and filter_() (and possibly elsewhere...)

Created on 12 Sep 2018  路  4Comments  路  Source: kkroening/ffmpeg-python

On Win32 systems, the escape_chars function turns berserk and hyper-escapes some symbols.
This result in an invalid parameter in ffmpeg and fails to run.

Testcase

import ffmpeg
testcase = ffmpeg.input("Wildlife.wmv").filter('scale',"320:-2").output("wontwork.mp4")
print(testcase.compile())
testcase.run()

Output

['ffmpeg', '-i', 'Wildlife.wmv', '-filter_complex', '[0]scale=320\\\\\\\\\\\\:-2[s0]', '-map', '[s0]', 'wontwork.mp4']
<some ffmpeg output>
[Parsed_scale_0 @ 00000000005c6c80] Invalid size '320\:-2'
[AVFilterGraph @ 00000000028c6500] Error initializing filter 'scale' with args '320\\\:-2'
Error initializing complex filters.
Invalid argument

Discussion

  • The colon : is escaped by escape_chars although it shouldn't (at least on win32 systems).
  • Saving testbench.compile() to a .bat file, manually removing the six \ and running the command solves the issue.
  • The reason between the fact that there are 12 \ is unclear (would default to 6 passed to Popen, then 3 when parsed by ffmpeg)

Configuration

  • Windows 7
  • Python 3.6.3 :: Anaconda custom (64-bit)
  • ffmpeg-python version 0.1.16
  • ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers

Most helpful comment

Also big props for such a well-written ticket. I appreciate the thought you put into keeping the ticket organized so that it was easy to see what's going on.

All 4 comments

-ffmpeg.input("Wildlife.wmv").filter('scale',"320:-2").output("wontwork.mp4")
+ffmpeg.input("Wildlife.wmv").filter('scale', 320, -2).output("wontwork.mp4")

The reason there are so many \ characters is because of ffmpeg's recursively nested escaping rules. Try using the drawtext filter manually from the command line and see how many backslash escapes it takes to draw the text ":" over a video. It's intended behavior - see the escape_chars test cases.

Understood!
This is more of a filter documentation problem to me then.
Thanks for your answer!

Thanks for the feedback about documentation. We'll keep that in mind as the documentation is improved.

Also big props for such a well-written ticket. I appreciate the thought you put into keeping the ticket organized so that it was easy to see what's going on.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prajwal-mulkalwar picture prajwal-mulkalwar  路  6Comments

cbitterfield picture cbitterfield  路  4Comments

Woolwit picture Woolwit  路  4Comments

Baa14453 picture Baa14453  路  5Comments

lalamax3d picture lalamax3d  路  3Comments