]>
code.delx.au - transcoding/blob - fix-pal-speedup
3 # Many DVDs released in Australia are sped up from 24fps to 25fps.
4 # This script reverses the procedure, correcting the audio pitch.
5 # - The video framerate is adjusted without re-encoding.
6 # - The audio is slowed, and encoded as AAC, preserving surround sound.
7 # - Chapters and subtitles are also adjusted to match the new timing.
9 if [ -z "$1" ] ||
[ -z "$2" ]; then
10 echo "Usage: $0 infile outfile"
17 SLOWFILTER
=("-filter" "asetrate=46080,aresample=osr=48000:resampler=soxr")
24 tmpdir
="$(mktemp -d "${TMPDIR:-/var/tmp}/pal-XXXXXXXX
")"
25 local audiofile
="${tmpdir}/audiofile.m4a"
27 encode_audio
"$infile" "$audiofile"
28 remux_file
"$infile" "$audiofile" "$outfile"
33 function encode_audio
{
38 -c:a libfdk_aac
-vbr 3 \
48 audiodelay
="$(get_minimum_timestamp "$infile" "audio
")"
51 videodelay
="$(get_minimum_timestamp "$infile" "video
")"
54 videotrackid
="$(get_track_id "$infile" "video
")"
57 local subtitletrackid
=""
58 while read -r subtitletrackid
; do
59 suboptions
+=("--sync" "${subtitletrackid}:0,${OLDFPS}/${NEWFPS}")
60 done < <(get_track_id
"$infile" "subtitles")
62 local chapteroptions
=()
63 if [ "$(get_chapter_count "$infile")" -gt 0 ]; then
64 chapteroptions
=("--chapter-sync" "0,${OLDFPS}/${NEWFPS}")
69 --default-duration "${videotrackid}:${NEWFPS}fps" \
70 --sync "${videotrackid}:$((videodelay / 1000000))" \
71 "${chapteroptions[@]}" \
73 --no-audio "$infile" \
74 --sync "0:$((audiodelay / 1000000))" \
78 function get_track_id
{
79 mkvmerge
-i -F json
"$1" | jq
-r ".tracks[] | select(.type == \"$2\") | .id"
82 function get_minimum_timestamp
{
83 mkvmerge
-i -F json
"$1" | jq
-r ".tracks[] | select(.type == \"$2\") | .properties.minimum_timestamp"
86 function get_chapter_count
{
87 mkvmerge
-i -F json
"$1" | jq
-r ".chapters | length"