I've currently got some images that I'd like to display in the form of a movie. So, I pocked around a bit and found ffmpeg. This is the tutorial I have been going with:
http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/
Since I don't care about reading, I skipped right to the writing section. As far as I can tell, this is what my program should say:
import subprocess as sp
FFMPEG_BIN = "ffmpeg" #I'm on Ubuntu
command = [ FFMPEG_BIN,
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-s', '1000x1000',
'-pix_fmt', 'rgb24',
'-r', '24',
'-i', '-',
'-an',
'-vcodec', 'mpeg',
'my_output_videofile.mp4' ]
pipe = sp.Popen( command, stdin = sp.PIPE, stderr = sp.PIPE)
However, when I run this in spyder, I get the error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/xander/Downloads/python-meep/makeVideo.py", line 15, in <module>
pipe = sp.Popen( command, stdin = sp.PIPE, stderr = sp.PIPE )
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Why is that happening? I'm really suspicious: I never mention the names of my pictures ("Image0.jpeg", "Image1.jpeg", ..., "Image499.jpeg", "Image500.jpeg"). Any help will be greatly appreciated!
P.S. The guy in the tutorial also says that some codecs require a bitrate; I tried that and it didn't work either.
For your -i
argument you are only specifying '-'
and the script is looking for an image named as such.
try:
from subprocess import call
command = [ FFMPEG_BIN,
'-i', './image%d.jpg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-s', '1000x1000',
'-pix_fmt', 'rgb24',
'-r', '24',
'-an',
'-vcodec', 'mpeg',
'my_output_videofile.mp4' ]
call(command)
This will look for images name image0.jpg, image1.jpg etc.
More here: https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images