Scripting w/ Codex: Batch Video Conversion
Recently, I had a bunch of large *.mkv files that I wanted to transcode to save space and an idea hit me.
In the past, I generally would have used Handbrake to convert the files. Although I knew about FFmpeg, it always seemed too complex for a coding mortal like me. Compared to Handbrake’s familiar GUI, the FFmpeg syntax was barrier that kept me from learning it.
That is until I remembered that I had access to the Codex (GPT-3) code-completion API through OpenAI’s beta program.
Around the time, I was reading a post by Jaiyam Sharma about running computer vision models using OpenCV and PyTorch on top of a live video feed. In addition to a great in-depth explanation of the theory and code behind the “neural style transfer” machine-learning technique, Sharma explains how he used pyvirtualcam and FFmpeg to build parts of the video processing back-end of his application.
Intrigued, I thought this might be a good chance to test out the Codex API and learn a bit about FFmpeg in the process. In particular, I wanted to see if it could get Codex to write a script that used ffmpeg to convert *.mkv files to *.mp4 using the HEVC codec (on an M1 Mac).
Sure enough, I was able to get Codex to generate sensible, executable code in a matter of seconds in response to the prompt:
“write a script to convert all .mkv files in a folder into .mp4 files using ffmpeg and an HEVC encoder.”
That’s it. That’s all I wrote and Codex (DaVinci) did the rest.
Amazing eh? Check out the code below:

Reflection
When I think about the big-picture implications of Codex (and large language models more generally), it’s hard to see how it won’t change the ways coders code.
A core (cognitive) capability that many coders, makers, and other curious life-long learners share is the ability to iterate on an idea and take it from concept to code; from prototype to production; from idea to actuality.
Codex radically accelerates this ability to iterate and see the impact of one’s coding decisions. The ability to go from concept to code rapidly, with the help of AI, is a powerful combination that allows a developer to easily amplify their impact as a coder.
Until next time…I’ll be thinking about all of this in the context of Douglas Rushkoff’s dictum “Program, or be programmed.”

.