python image frames to video

lovefaithswing picture lovefaithswing · Apr 7, 2011 · Viewed 23.2k times · Source

I am writing a python/django application and it needs to do image manipulation and then combine the images into a video (each image is a frame). Image manipulation is easy. I'm using PIL, but for the convert to video part, I'm stuck. I've found pyffmpeg but that just seems to do decoding of videos to frames, not the other way around. Although I may have missed something. I've also heard that pythonMagick (imagemagick wrapper) can do this, but I can't seem to find anything about encoding in the docs.

This is running on a linux server and must be python (since that is what the application is in).

What should I use?

Answer

Ehsan picture Ehsan · Nov 29, 2016

First install ffmpeg using the following command: sudo apt install ffmpeg

import os
os.system("ffmpeg -f image2 -r 1/5 -i ./images/swissGenevaLake%01d.jpg -vcodec mpeg4 -y ./videos/swissGenevaLake.mp4")

Details:

The aforementioned code creates a video from three images file, stored in the images folder. Each image plays for 5 seconds in the video (because of the argument: -r 1/5). The three files names are: "swissGenevaLake1.jpg", "swissGenevaLake2.jpg" and "swissGenevaLake3.jpg" in images folder.

Hope this helps.