pythonffmpegsubprocess

Why does ffmpeg command work in terminal but not subprocess.call


I reviewed the "similar questions", but those seem to refer to using the full path for ffmpeg to ensure using the same version, which I am already doing so posting my question.

I am using a Mac runnning Sequoia 15.5, python 3, and ffmpeg 4.2.1.

I'm trying to write a script that can convert flac to mp3 320k.

If I use the following command in terminal everything works as intended:

/usr/local/bin/ffmpeg -i "/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.flac" -b:a 320k -map_metadata 0 -id3v2_version 3 "/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.mp3"

But when trying to do the same thing with subprocess.call with the following:

command = ['/usr/local/bin/ffmpeg', '-i', '/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.flac', '-b:a 320k', '-map_metadata 0', '-id3v2_version 3', '/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.mp3']
p = subprocess.call(command)

I get this as a result:

Unrecognized option 'id3v2_version 3'.
Error splitting the argument list: Option not found

If I remove the '-id3v2_version 3', then the subprocess.call results in the following error:

[mp3 @ 0x7fae2c008200] Invalid stream specifier: a 320k.

Why does Terminal understand but subprocess.call doesn't when I've verified I'm using the same version of ffmpeg?


Solution

  • You are passing the options incorrectly. -b:a 320k is not a single argument to the command, otherwise your command line would have enclosed it in quotes ("-b:a 320k"). You need to pass '-b:a' and '320k' as separate arguments, and similarly with the other options that include arguments.

    specifically:

    command = [
            '/usr/local/bin/ffmpeg',
            '-i',
            '/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.flac',
            '-b:a',
            '320k',
            '-map_metadata',
            '0',
            '-id3v2_version',
            '3',
            '/Volumes/MainData/Media/Media Server/_Stage/03 - People Like Us - Aaron Tippin.mp3',
            ]