As an Amazon Associate I earn from qualifying purchases.
I needed a quick little piece of code that would go recursively iterate through a folder and its subfolders and convert all of the video files to H.264, so I took advantage of the Handbrake command line interface (CLI) and Python 2.7.x to do the work for me. This code snippet is not long or elaborate, but does the job, so hopefully it will be helpful to others.
Note that the Handbrake CLI options are defined in runstr. As-is, the script will convert videos with AVI, DIVX, FLV, M4V, MKV, MOV, MPG, MPEG, and WMV extensions to H.264 MP4s with the following options:
- “Normal” preset
- Two-pass encoding
- Turbo first pass, which “significantly boost[s] the speed of the first pass – with minimal effect on quality”
Amazon and the Amazon logo are trademarks of Amazon.com, Inc, or its affiliates.