Skip to content

Instantly share code, notes, and snippets.

@rpardee
Created December 28, 2025 20:34
Show Gist options
  • Select an option

  • Save rpardee/42ab258ec0d25248af45eec92519a212 to your computer and use it in GitHub Desktop.

Select an option

Save rpardee/42ab258ec0d25248af45eec92519a212 to your computer and use it in GitHub Desktop.
mass transcode MKVs keeping english subtitles
<#
Automates the handbrake CLI (such as it exists) so I can sic this script on a
whole dir of mkvs and have them trimmed down, but with subtitles
The raw command that works:
flatpak run --command=HandBrakeCLI fr.handbrake.ghb `
--input '../The Good Place S02E04.mkv' `
--output 'The Good Place S0204.mkv' `
--multi-pass `
--turbo `
--subtitle-lang-list "eng `
--all-subtitles `
--subname "english `
--encoder x264
#>
$jfin_root = '/media/jellyfin/media/videos/Shows'
$out_root = '/media/legacy/media/videos/Shows'
$big_mkvs = get-childitem -path $jfin_root -Recurse *.mkv | where-object {$_.Length -gt .8GB}
foreach ($mkv in $big_mkvs) {
$in_file = $mkv.FullName
$dest_folder = $mkv.DirectoryName.replace($jfin_root, $out_root)
$out_file = join-path -path $dest_folder -childpath $mkv.name
if (test-path $dest_folder) {
write-host 'path already exists'
} else {
write-host "no such path as $dest_folder--creating it"
new-item -path $dest_folder -type Directory
}
write-host "About to encode '${in_file}' to '${out_file}'"
flatpak run --command=HandBrakeCLI fr.handbrake.ghb `
--input $in_file `
--output $out_file `
--multi-pass `
--turbo `
--subtitle-lang-list "eng" `
--all-subtitles `
--subname "english" `
--encoder x264
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment