0

tl;dr: how to use a bash ffmpeg command in python

So I'm trying to take one JPEG image and an audio file as input and generate a video file of the same duration as the audio file (by stretching the still image for the whole duration).

So, I found these: https://superuser.com/questions/1041816/combine-one-image-one-audio-file-to-make-one-video-using-ffmpeg

So, I now have the code for the merging: ffmpeg -loop 1 -i image.jpg -i audio.wav -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4

Then I want to use that in python but unable to figure out how to port this to ffmpeg-python or ffpy.

I found this: Combining an audio file with video file in python

So, I tried the same thing as him:

cmd = 'ffmpeg -loop 1 -i image.jpg -i message.mp3 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4'
subprocess.check_output(cmd, shell=True) 
subprocess.call(cmd, shell=True)

But I got "returned non-zero exit status 1". So what did I do wrong?

Tom
  • 571
  • 2
  • 11
  • 29

1 Answers1

0

Please try running the command in a bash shell.

I pasted the same code and it works for me.

exit status 1 indicates the error is with the ffmpeg process and not with python.

If all goes well you will end up with an exit status of 0

DeWil
  • 362
  • 3
  • 10
  • Just to add -----> subprocess.check_output(cmd, shell=True) is used if you want to retrieve some part from the ffmpeg output whereas subprocess.call(cmd, shell=True) simply runs the ffmpeg command – DeWil Oct 06 '18 at 12:24