Script for encoding mkv files with ffmpeg – Part 2

I spent more time on this script because it turned out to be a fun exercise – here are a few things that I added:

  • Fix some bugs – especially around non-HDR content handling
  • Retain all audio streams from source
  • Modularize the original code and make the script’s flow more readable

Up to this point, I could prompt AI coding assistant (Gemini) to do things – note that I had to prompt them very specifically and do this incrementally. It seemed to get confused very easily if the steps were too big, if I wanted to change something with some output in a step and continued the same chat etc. Copilot in general was worse than Gemini – it made syntax errors all the time and I didn’t have patience to check for logic errors.

After this, I wanted to show a succinct and useful progress for the script when it is working on files. This turned out to be more involved than I thought. Prompting AI actually led to dead-ends and I was unable to get it to do it. In the end, I figured out the overall structure that I wanted and that I thought was best to accomplish this (have ffmpeg report progress to a fifo, have a background monitoring process parse the progress update and update a global fifo, have a status updater process in the main script that reads the global fifo and displays the progress bar). At each step, I used AI assistant to help me with syntax and other lower level details.

Here’s what the progress bar looks like (I have translucency set in the terminal so ignore the background):

Overall, that worked out well. Here’s the structure for how progress update works:

Here is the fully updated script: https://github.com/ram-nat/scripts/blob/main/reencode.sh

Leave a Reply

Your email address will not be published. Required fields are marked *