Python
Compress MP4


main index


Introduction

You are to develp a python script that will write a ffmpeg script that can compress one or more .MP4 files.

For example, suppose a directory named, say MOVIES, contains three .MP4 files,
    shot_1.MP4
    shot_2.MP4
    shot_3.MP4

Your python script when copied to the MOVIES folder and executed should write a single ffmpeg script named, say, compressMP4.bat. When the .bat file is run by double clicking it will compress all three MP4 files,
    shot_1_compressed.MP4
    shot_2_compressed.MP4
    shot_3_compressed.MP4


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

ffmpeg.exe -i FULLPATH/shot_1.MP4 -vcodec libx264 -crf 20 FULLPATH/shot_1_compressed.mp4
ffmpeg.exe -i FULLPATH/shot_2.MP4 -vcodec libx264 -crf 20 FULLPATH/shot_2_compressed.mp4
ffmpeg.exe -i FULLPATH/shot_3.MP4 -vcodec libx264 -crf 20 FULLPATH/shot_3_compressed.mp4
pause