Skip to content

Instantly share code, notes, and snippets.

@El-Wumbus
Last active June 27, 2025 17:21
Show Gist options
  • Save El-Wumbus/c068fc729a12d21e040d73f2e4102d27 to your computer and use it in GitHub Desktop.
Save El-Wumbus/c068fc729a12d21e040d73f2e4102d27 to your computer and use it in GitHub Desktop.
"Convert video from Dolby Vision profile 7 to 8. Requires dovi_tool, mkvtoolnix-cli, and ffmpeg.
#!/usr/bin/env fish
function dv_p7_to_p8 -a input output skip_clean -d "Convert video from Dolby Vision profile 7 to 8"
if test -z $input || test -z $output
return
end
set -l container (path extension "$output")
set -l video_stream_p8 (path normalize "$(pwd)/$(path change-extension '' $(path basename $input))_video_p8.hevc")
set -l contained_video_stream (path normalize "$(pwd)/$(path change-extension '' $(path basename $input))_video_p8.mkv")
if test container = mp4
echo "Output container is MP4, skipping subtitles..."
else
set -l subflag "-map 1:s?"
end
if not test -f "$video_stream_p8"
echo "Extracting video and converting at path: $video_stream_p8"
mkvextract tracks "$input" 0:/dev/stdout | dovi_tool --mode 2 convert - --output "$video_stream_p8"
end
if not test -f "$contained_video_stream"
echo "Building contained video stream at path: $contained_video_stream"
mkvmerge -o "$contained_video_stream" "$video_stream_p8"
if test -z $skip_clean
rm -vf "$video_stream_p8"
end
end
if not test -f "$output"
echo "Writing final output at path: $output"
ffmpeg -i "$contained_video_stream" -i "$input" -strict experimental \
-map 0:v -map 0:d? \
-map 1:a? $subflag \
-vcodec copy -acodec ac3 -b:a 640k \
"$output"
if test -z $skip_clean
rm -vf "$contained_video_stream"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment