From: James Bunton Date: Sat, 20 Oct 2018 23:48:57 +0000 (+1100) Subject: fix-pal-speedup: delay video track if needed X-Git-Url: https://code.delx.au/transcoding/commitdiff_plain/59178cc821413a5092fc2eba784f83f8b4b59414 fix-pal-speedup: delay video track if needed --- diff --git a/fix-pal-speedup b/fix-pal-speedup index 17e5e01..5b77d45 100755 --- a/fix-pal-speedup +++ b/fix-pal-speedup @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash # Many DVDs released in Australia are sped up from 24fps to 25fps. # This script reverses the procedure, correcting the audio pitch. @@ -10,7 +10,7 @@ if [ -z "$1" -o -z "$2" ]; then exit 1 fi -set -xe +set -o pipefail -eux FORCEFPS="24" SLOWFILTER="-filter asetrate=46080,aresample=osr=48000:resampler=soxr" @@ -19,24 +19,25 @@ function mux_replace_audio { local audiofile="$2" local outfile="$3" - local audiodelay="$(get_audio_delay "$infile")" - local videotrackid="$(get_video_trackid "$infile")" + local audiodelay="$(get_minimum_timestamp "$infile" "audio")" + local videodelay="$(get_minimum_timestamp "$infile" "video")" + local videotrackid="$(get_track_id "$infile" "video")" mkvmerge \ -o "${outfile}" \ --default-duration "${videotrackid}:${FORCEFPS}fps" \ + --sync "${videotrackid}:$((videodelay / 1000000))" \ --no-audio "$infile" \ --sync "0:$((audiodelay / 1000000))" \ "$audiofile" } -function get_video_trackid { - mkvmerge -i "$1" | sed -n 's/Track ID \([0-9]*\): .*video.*/\1/p' +function get_track_id { + mkvmerge -i -F json "$1" | jq -r ".tracks[] | select(.type == \"$2\") | .id" } -function get_audio_delay { - mkvmerge -F json -i "$1" | \ - jq -r '.tracks[] | select(.type == "audio") | .properties.minimum_timestamp' +function get_minimum_timestamp { + mkvmerge -F json -i "$1" | jq -r ".tracks[] | select(.type == \"$2\") | .properties.minimum_timestamp" } function encode_audio {