strip_track_except: improve

detect if more than 1 track is present
detect if undesired tracks are present
show progress bar using pv
This commit is contained in:
Lukáš Kucharczyk 2022-10-08 00:30:24 +02:00
parent ec5f7d9379
commit df1f8f4889
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 11 additions and 1 deletions

View File

@ -10,5 +10,15 @@ FILENAME=$1
LANGUAGE_TO_KEEP="${2:-jpn}" LANGUAGE_TO_KEEP="${2:-jpn}"
echo -n "Processing " echo -n "Processing "
colorprint "$FILENAME" colorprint "$FILENAME"
# capture JSON output and remove the excessively large code_private_data field
JSON_OUTPUT=$(mkvmerge -J "$FILENAME" | jq '[ .tracks[] | select(.type=="audio") | del(.properties.codec_private_data) ]')
TRACK_COUNT=$(echo "$JSON_OUTPUT" | jq length)
# check if more than 1 audio track is present
[[ $TRACK_COUNT -lt 2 ]] && echo -e "\tFile has only 1 track, skipping." && exit 1
# check if tracks other than the one to keep are present
UNDESIRED_TRACK_COUNT=$(echo "$JSON_OUTPUT" | jq '[.[] | select(.properties.language!="$LANGUAGE_TO_KEEP")] | length')
[[ $TRACK_COUNT -lt 2 ]] && echo -e "\tFile has only '$LANGUAGE_TO_KEEP' tracks, skipping." && exit 1
FILENAME_WITHOUT_EXT=${FILENAME%.*} FILENAME_WITHOUT_EXT=${FILENAME%.*}
ffmpeg -i "$FILENAME" -map 0:v -map 0:a:m:language:${LANGUAGE_TO_KEEP} -map 0:s -c copy "${FILENAME_WITHOUT_EXT}.converted.mkv" echo -e "\tRemoving all audio tracks except '$LANGUAGE_TO_KEEP' tracks..."
pv "$FILENAME" | ffmpeg -i pipe:0 -map 0:v -map 0:a:m:language:${LANGUAGE_TO_KEEP} -map 0:s -c copy -v warning "${FILENAME_WITHOUT_EXT}.converted.mkv"