]> code.delx.au - transcoding/blob - fix-pal-speedup
fix-pal-speedup: use fdk aac encoder, no need for separate mplayer dump
[transcoding] / fix-pal-speedup
1 #!/bin/bash -e
2
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. The audio is
6 # slowed, and encoded as AAC, preserving surround sound.
7
8 if [ -z "$1" -o -z "$2" ]; then
9 echo "Usage: $0 destdir infile [infile ...]"
10 exit 1
11 fi
12
13 set -xe
14 FORCEFPS="24"
15 SLOWFILTER="-filter asetrate=46080,aresample=osr=48000:resampler=soxr"
16
17 function mux_replace_audio {
18 local infile="$1"
19 local audiofile="$2"
20 local outfile="$3"
21
22 local trackid="$(mkvmerge -i "$infile" | grep 'Track ID.*video' | sed 's/^Track ID \(.\):.*$/\1/')"
23 mkvmerge -o "${outfile}" --default-duration "${trackid}:${FORCEFPS}fps" --no-audio "$infile" "$audiofile"
24 }
25
26 function encode_audio {
27 ffmpeg \
28 -i "$1" \
29 -vn \
30 $SLOWFILTER \
31 -c:a libfdk_aac -vbr 3 \
32 "$2"
33 }
34
35 function convert_file {
36 local infile="$1"
37 local outfile="$2"
38 local audiofile="${tmpdir}/audiofile.m4a"
39
40 encode_audio "${infile}" "${audiofile}"
41 mux_replace_audio "${infile}" "${audiofile}" "${outfile}"
42 }
43
44
45 destdir="$1"
46 shift
47
48 for infile in "$@"; do
49 outfile="$destdir/$(basename "$infile")"
50
51 if [ -f "$outfile" ]; then
52 echo "Not overwriting $outfile"
53 continue
54 fi
55
56 tmpdir="$(mktemp -d "${TMPDIR:-/var/tmp}/pal-XXXXXXXX")"
57 convert_file "$infile" "$outfile"
58 rm -rf "$tmpdir"
59 done
60