I’m working on a python script that does a custom conversion of videos via ffmpeg.
My problem is that the execution of ffmpeg stops suddenly after a bit of conversion (usually 3-4 mb out of 100mb) with a None exit code.
I’m using the pexpect library. Currently I do not check the progress but I will in a close future. It seems that I am right using pexpect regarding these questions FFMPEG and Pythons subprocess and Getting realtime output from ffmpeg to be used in progress bar (PyQt4, stdout). This is the command that I’m running (I have checked that it’s exactly this one)
nice ffmpeg -i '/full/path' -s 640x360 -strict experimental -vcodec libx264
-f mp4 - coder 0 -bf 0 -refs 1 -flags2 -wpred-dct8x8 -level 30 -crf 26
-bufsize 4000k -maxrate 350k -preset medium -acodec libvo_aacenc
-ar 48000.0 -ab 128K -threads 2 -y '/full/path/out'
I am using nice but I have tried also without it and the result ends up being the same.
I’m running pexpect this way:
output, exit = pexpect.run(self.command(), withexitstatus=True,\
logfile=logfile)
print output
print exit
Of course I have tried the same command on the command line and it works fine.
Any clue on what might be happening?
The problem ended up being a bug in pexpect run function regarding the timeout. I have found the bug that was reported before me (yes, I forget to check ;))
http://sourceforge.net/tracker/?func=detail&aid=3316509&group_id=59762&atid=492077
Sadly the bug is really old and it explains how to solve the little bug. As a workaround I could just rewrite my code using spawn instead.
I don’t really like the idea of using a code with trivial bugs that is still unmaintained so I have writen the code using Popen as Albert suggested.
I will wait some time to make the choice of going taking the chances with pexpect (if the code seems reliable).
For the record, here is my working code:
Thanks for the help.