1

I was working through this answer to an FFMPEG question and the command works just fine through the Windows 10 command prompt (I've only changed the input and output filenames):

ffmpeg -i test.mp4  -filter:v "select='gt(scene,0.4)',showinfo" -f null  - 2> test.txt

My Python 3 script gives arguments (as a list) to the subprocess.call() function and works fine for a number of basic FFMPEG operations, but not this one! It seems to be failing at the final null - 2> test.txt part, with the following error messages depending on how I split the arguments:

[NULL @ 000001c7e556a3c0] [error] Unable to find a suitable output format for 'pipe:'
[error] pipe:: Invalid argument

[error] Unrecognized option '2> test.txt'.
[fatal] Error splitting the argument list: Option not found

[error] Unrecognized option '2>'.
[fatal] Error splitting the argument list: Option not found

Here's the basic list of arguments I've been trying:

args=['C:\\Program Files\\ffmpeg\\ffmpeg.exe',
      '-i',
      'test.mp4',
      '-filter:v "select=\'gt(scene,0.4)\',showinfo"',
      '-f null',
      '-',
      '2>',
      'test.txt']

Plus various permutations combining and splitting the last few elements.

Please could somebody help me with the right syntax for running FFMPEG with these arguments through Python 3?

Many thanks - I just can't see where I'm going wrong :(

Peter F
  • 793
  • 8
  • 10
  • why don't you use a wrapper to ffmpeg instead of calling it externally (which is dangerous). e.g.https://github.com/kkroening/ffmpeg-python – Eypros May 08 '18 at 08:16
  • 1
    Thanks Eypros - would like to hear more about why you think it's "dangerous" please? Ultimately doesn't a wrapper have to call ffmpeg externally itself? It's a good thought but here's my reasoning: 1) I'm learning this fresh and after browsing the very wrapper you mentioned, concluded it'll take as long to learn the wrapper syntax as learn the ffmpeg flags themselves; 2) One less dependency, generally good for future-proofing but also I might want to make this project availabile commercially and don't want to have to double check licensing/copyright conditions etc. – Peter F May 08 '18 at 21:05

1 Answers1

1

This doesn't get to the bottom of what was going wrong in my syntax but the following answer provided me with a workaround, essentially using shell=True and passing all arguments as a combined string: subprocess call ffmpeg (command line)

Here's my updated call:

subprocess.call("ffmpeg -i test.mp4 -filter:v \"select='gt(scene,0.4)',showinfo\" -f null - 2> output.txt",shell=True)

Thanks to the nice people at Pythonista Cafe for finding that one for me :)

Peter F
  • 793
  • 8
  • 10