Python
JPGs to MP4


main index


Introduction

The ffmpeg application is a very powerful image processing suite of utilies but using ffmpeg requires a user to write one or more lines of code. You are to extend the basic python script that we developed in session 4 so that it can generate an ffmpeg script that can convert one or more sequences of .jpg files into their corresponding .mp4 movies.

For example, suppose a directory contains two sequences of jpg files,
    shot_camera1.0001.jpg to shot_camera1.0100.jpg
and
    shot_camera2.0001.jpg to shot_camera2.0100.jpg

Your python script when copied to the images folder and executed should write a file named, say, convertJPGToMP4.bat. When the .bat file is run by double clicking it will create two MP4 files,
    shot_camera1.mp4
and
    shot_camera1.mp4.


The text in the convertJPGToMP4.bat file (written by your python script) will be of the following form.

ffmpeg.exe -i "./shot_camera1.%%04d.jpg" -s 960x640 -codec:v libx264 -r 30 -pix_fmt yuv420p "./shot_camera1.mp4"
ffmpeg.exe -i "./shot_camera2.%%04d.jpg" -s 960x640 -codec:v libx264 -r 30 -pix_fmt yuv420p "./shot_camera2.mp4"
pause