using ffmpeg command line with python's subprocess module

Andreas Perstinger andipersti at gmail.com
Wed Dec 4 04:38:27 EST 2013


iMath <redstone-cold at 163.com> wrote:
>I use the following code to do the test ,but error occurred ,it
>prompts system cannot find specified files ,but the files are indeed
>exists there ,any help ?
>
>with tempfile.TemporaryFile() as fp:
>    fp.write(("file '"+'a1.mp3'+"'\n").encode('utf-8'))
>    fp.write(("file '"+'a2.mp3'+"'\n").encode('utf-8'))
>
>    subprocess.call(['ffmpeg/ffmpeg', '-f', 'concat','-i',fp, '-c',
> 'copy', 'a3.mp3'])

Basic rule: Always copy'n'paste the exact traceback you get.

I don't think you are running the code you have posted because your
subprocess call doesn't work:

>>> import tempfile, subprocess
>>> with tempfile.TemporaryFile() as fp:
...   subprocess.call(["foo", "bar", fp, "baz"])
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/lib/python3.3/subprocess.py", line 520, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.3/subprocess.py", line 820, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.3/subprocess.py", line 1380, in _execute_child
    restore_signals, start_new_session, preexec_fn)
TypeError: Can't convert '_io.BufferedRandom' object to str implicitly

"fp" is a file object, but subprocess expects a list of strings as
its first argument.

Bye, Andreas



More information about the Python-list mailing list