Zirujauak
Member
- Joined
- Feb 23, 2022
- Messages
- 17
- Likes
- 9
Here's the bash script I use locally, tailored to my habits and needs:
1. I always grab the "original" audio at best resolution
2. If descriptive audio is available, I'll grab that, too, at the lowest resolution, and tack " - Descriptive Audio" to the filename
3. I snag all the english subs.
This script scans the current working directory for MP4 files (ignoring descriptive audio), then matches a descriptive audio MP4 if found, then looks for forced subs, then subs, then CC subs, muxes the whole thing, then does some property edits. There are optional args to change the audio track naming (-a for normal audio, -d for descriptive).
EDIT: This doesn't handle subdirectories at all. Just a lot of errors...
EDIT: Updated to limit find to the current directory
It's pretty specific to how I like things named and ordered, but it isn't hard to customize it. Works as written in gitbash on Windows, but would probably work on linux or osx with a change to the mkvtoolnix base path.
Example - mux everything, using "Surround" as the default audio track name and "Descriptive" for any descriptive audio found:
1. I always grab the "original" audio at best resolution
2. If descriptive audio is available, I'll grab that, too, at the lowest resolution, and tack " - Descriptive Audio" to the filename
3. I snag all the english subs.
This script scans the current working directory for MP4 files (ignoring descriptive audio), then matches a descriptive audio MP4 if found, then looks for forced subs, then subs, then CC subs, muxes the whole thing, then does some property edits. There are optional args to change the audio track naming (-a for normal audio, -d for descriptive).
EDIT: This doesn't handle subdirectories at all. Just a lot of errors...
EDIT: Updated to limit find to the current directory
It's pretty specific to how I like things named and ordered, but it isn't hard to customize it. Works as written in gitbash on Windows, but would probably work on linux or osx with a change to the mkvtoolnix base path.
Example - mux everything, using "Surround" as the default audio track name and "Descriptive" for any descriptive audio found:
Code:
mux.sh -a "Surround" -d "Descriptive"
Code:
#!/bin/bash
mkvtoolnix='/c/Program Files/MKVToolNix'
mkvmerge="${mkvtoolnix}/mkvmerge.exe"
mkvpropedit="${mkvtoolnix}/mkvpropedit.exe"
# Use -a {text} to override the default audio track name
default_audio="5.1 Dolby Digital"
# Use -d {text} to override the descriptive audio track name
descriptive_audio="Descriptive Audio"
while getopts "::a::d" options;
do
case "${options}" in
a)
default_audio="${OPTARG}";;
d)
descriptive_audio="${OPTARG}";;
esac
done
IFS=$'\n'
basenames=$(find . -maxdepth 1 -name '*.mp4' -and -not -name '* - Descriptive Audio.mp4' -exec basename {} .mp4 \;)
for f in $basenames
do
# Assemble args for mkvmerge and mkvpropedit
merge=("-o" "${f}.mkv" "${f}.mp4")
propedit=("${f}.mkv" "-e" "track:a1" "-s" "name=${default_audio}" "-s" "flag-default=1")
# Descriptive audio file, if any
if [ -f "${f} - Descriptive Audio.mp4" ];
then
merge+=("-D" "${f} - Descriptive Audio.mp4")
propedit+=("-e" "track:a2" "-s" "name=${descriptive_audio}" "-s" "flag-default=0")
fi
caption_codes=("en" "en-us" "en-US")
sub_index=1
# Forced captions - first match only
for code in ${caption_codes[*]}
do
if [ -f "${f}.${code}.forced.srt" ];
then
merge+=("${f}.${code}.forced.srt")
propedit+=("-e" "track:s${sub_index}" "-s" "name=Forced" "-s" "flag-default=0" "-s" "flag-forced=1" "-s" "language=${code}")
sub_index=$((sub_index + 1))
break
elif [ -f "${f}.forced.${code}.srt" ];
then
merge+=("${f}.forced.${code}.srt")
propedit+=("-e" "track:s${sub_index}" "-s" "name=Forced" "flag-default=0" "-s" "flag-forced=1" "-s" "language=${code}")
sub_index=$((sub_index + 1))
break
fi
done
# Captions - include everything that matches
for code in ${caption_codes[*]}
do
if [ -f "${f}.${code}.srt" ];
then
merge+=("${f}.${code}.srt")
propedit+=("-e" "track:s${sub_index}" "-s" "flag-default=0" "-s" "language=${code}")
sub_index=$((sub_index + 1))
fi
done
# Closed captions - everything
for code in ${caption_codes[*]}
do
if [ -f "${f}.${code}.cc.srt" ];
then
merge+=("${f}.${code}.cc.srt")
propedit+=("-e" "track:s${sub_index}" "-s" "name=Closed Captions" "-s" "flag-default=0" "-s" "language=${code}")
sub_index=$((sub_index + 1))
fi
done
${mkvmerge} "${merge[@]}"
${mkvpropedit} "${propedit[@]}"
done
Last edited: