Converting jpg's to mp4 using FFmPy


Converting jpg's to mp4 using FFmPy



I have a file full of jpg images that I would like to convert into an mp4 video. I have managed to do this on the command line using


cat path/to/pictures/%d.jpg | ffmpeg -f image2pipe -i - output.mp4



However when I try and go about doing it via FFmPy:


ff = ffmpy.FFmpeg(
inputs={'path/to/pictures/%d.jpg': None},
outputs={'output.mp4': None})

ff.cmd
ff.run()



I will run into the error:


FFRuntimeError: `ffmpeg -i path/to/pictures/1.jpg -f output.mp4` exited with status 1

STDOUT:


STDERR:



I'm really not sure what the issue is here, any change I make results in the same error. Any help would be appreciated, thanks.





What happens if you run the command from the error directly? Rather than the piping command.
– FamousJameous
Jun 29 at 15:55





If you mean run the ff.cmd output in the command line directly, it will get to /path/to/pictures/101.jpg and ask 'File '/home/matthewl/Downloads/Eyes_side_to_side/101.jpg' already exists. Overwrite ? [y/N], continuously till the last jpg`
– Matt
Jun 29 at 16:01



/path/to/pictures/101.jpg


'File '/home/matthewl/Downloads/Eyes_side_to_side/101.jpg' already exists. Overwrite ? [y/N]





Are you using a python for-loop? How is the %d in '/path/to/pictures/%d.jpg' getting substituted by numeric strings? (We need to prevent that from happening...)
– unutbu
Jun 29 at 16:06


%d


'/path/to/pictures/%d.jpg'





I'm not using any loops, literally just the code above, it's more or less a copy from the examples FFmPy give in their documentation, i thought the %d would list all my jpg files which are '1.jpg' all the way to '500.jpg'
– Matt
Jun 29 at 16:10


%d





I mean if it helps get to the core of the problem, I can write the path incorrectly or just try and convert one image to an mp4 and I will still get the same error.
– Matt
Jun 29 at 16:19




1 Answer
1



Since you know the ffmpeg command which works from the command line, it might be easier to simply call it using subprocess:


ffmpeg


subprocess


import subprocess

cmd = ['ffmpeg', '-i', '/path/to/pictures/%d.jpg', 'output.mp4']
retcode = subprocess.call(cmd)
if not retcode == 0:
raise ValueError('Error {} executing command: {}'.format(retcode, ' '.join(cmd)))






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift