Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popen.communicate() returns only err when running ffmpeg

I'm trying to run ffmpeg from python and get some reasonable output. Doesn't matter what ffmpeg's log level is set, the only output I get from Popen.communicate() is err one. The content isn't an error however. I tried the same code to run other commands (ls) and it seems to be Ok with both out and err outputs.

I checked here and Google and unfortunately found nothing. Most of the examples use os or commands modules, not subprocess.

This is my test code:

command = [
        'ffmpeg',
        '-v', 'debug',
        '-i', '1.mov',
        '-vcodec', 'libx264',
        '-profile:v', 'high',
        '-preset', 'slower',
        '-b:v', '1000k',
        '-vf', 'scale=-1:720',
        '-threads', '0', 
        '-acodec', 'libfdk_aac',
        '-b:a', '192k',
        '-y',   
        '2.mp4',
        ]
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err =  p.communicate()
f = open('out.log', 'w')
f.write(out)
f.close()
f = open('error.log', 'w')
f.write(err)
f.close()

Have you ever see something like this? Am I doing any mistakes or is there an bug in ffmpeg?

like image 443
Jan Pulpan Avatar asked Dec 06 '25 08:12

Jan Pulpan


1 Answers

I seemed to misinterpreted stdout and stderr in case of ffmpeg. All the "console output" is normally directed to stderr. Redirecting stderr to stdout shall solve the issue. This is how:

p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Sorry for this ... I was too concentrated to Python part that I completely overlooked quite obvious thing. :-)

like image 101
Jan Pulpan Avatar answered Dec 07 '25 21:12

Jan Pulpan