{"id":550,"date":"2025-06-15T19:15:41","date_gmt":"2025-06-16T03:15:41","guid":{"rendered":"https:\/\/nramkumar.org\/tech\/?p=550"},"modified":"2025-06-15T19:15:41","modified_gmt":"2025-06-16T03:15:41","slug":"script-for-encoding-mkv-files-with-ffmpeg-part-2","status":"publish","type":"post","link":"https:\/\/nramkumar.org\/tech\/blog\/2025\/06\/15\/script-for-encoding-mkv-files-with-ffmpeg-part-2\/","title":{"rendered":"Script for encoding mkv files with ffmpeg &#8211; Part 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I spent more time <a href=\"https:\/\/nramkumar.org\/tech\/blog\/2025\/06\/09\/script-for-video-and-audio-re-encoding-for-plex\/\" data-type=\"post\" data-id=\"543\">on this script<\/a> because it turned out to be a fun exercise &#8211; here are a few things that I added:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fix some bugs &#8211; especially around non-HDR content handling<\/li>\n\n\n\n<li>Retain all audio streams from source<\/li>\n\n\n\n<li>Modularize the original code and make the script&#8217;s flow more readable<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Up to this point, I could prompt AI coding assistant (Gemini) to do things &#8211; 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 &#8211; it made syntax errors all the time and I didn&#8217;t have patience to check for logic errors.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what the progress bar looks like (I have translucency set in the terminal so ignore the background):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"42\" src=\"https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/image-1.png\" alt=\"\" class=\"wp-image-552\" style=\"width:449px;height:auto\" srcset=\"https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/image-1.png 706w, https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/image-1-300x18.png 300w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Overall, that worked out well. Here&#8217;s the structure for how progress update works:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"451\" height=\"1024\" src=\"https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-451x1024.png\" alt=\"\" class=\"wp-image-553\" style=\"width:248px;height:auto\" srcset=\"https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-451x1024.png 451w, https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-132x300.png 132w, https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-768x1744.png 768w, https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-676x1536.png 676w, https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-902x2048.png 902w, https:\/\/nramkumar.org\/tech\/wp-content\/uploads\/2025\/06\/Editor-_-Mermaid-Chart-2025-06-16-031257-scaled.png 1127w\" sizes=\"auto, (max-width: 451px) 100vw, 451px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the fully updated script: <a href=\"https:\/\/github.com\/ram-nat\/scripts\/blob\/main\/reencode.sh\">https:\/\/github.com\/ram-nat\/scripts\/blob\/main\/reencode.sh<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent more time on this script because it turned out to be a fun exercise &#8211; here are a few things that I added: Up to this point, I could prompt AI coding assistant (Gemini) to do things &#8211; note that I had to prompt them very specifically and do this incrementally. It seemed&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-550","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts\/550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/comments?post=550"}],"version-history":[{"count":1,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts\/550\/revisions"}],"predecessor-version":[{"id":554,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/posts\/550\/revisions\/554"}],"wp:attachment":[{"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/media?parent=550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/categories?post=550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nramkumar.org\/tech\/wp-json\/wp\/v2\/tags?post=550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}