Pandemic Journal, Day 614

A few days ago, I wrote about optimizing the process of extracting short segments from a video file to avoid having to copy the entire source video. My improvement was simple, elegant, and wrong – when I looked at the video I created, it didn’t start where I expected; it started and ended early every time. I “fixed” the problem by telling the program to add a little time at the end and by using QuickTime to trim the video by hand, but that seemed silly.

Today I figured out the problem. I’d assumed that when I told ffmpeg to extract a piece of video starting at a particular time, it would do that – but it can’t. It has to back up to the most recent “key frame” in the video, so the starting point will be a little earlier than specified, which threw off the rest of the calculations in the script and gave me a trimmed video that started and ended too early.

So in the end, I wound up writing unnecessary (and ugly) code that did more processing than necessary to extract a clip that I still had to edit manually anyway.

Premature optimization is the root of all evil.