]> code.delx.au - transcoding/blob - fix-pal-speedup
Convert to 24fps (film) instead of 23.976fps
[transcoding] / fix-pal-speedup
1 #!/bin/bash -e
2
3 # Many DVDs released in Australia are sped up from 23.976fps to 25fps.
4 # This script reverses the procedure, correcting the audio pitch.
5 # Input files are assumed to be mkv files with track 2 audio.
6 # The video framerate is adjusted without re-encoding. The audio is slowed and
7 # normalised then re-encoded as mp3.
8
9 if [ -z "$1" -o -z "$2" ]; then
10 echo "Usage: $0 destdir infile"
11 exit 1
12 fi
13
14 FORCEFPS="24"
15 SLOWDOWN="0.96"
16
17 destdir="$1"
18 infile="$2"
19 outfile="$destdir/$(basename "$infile")"
20 tmpdir="$(tempfile -p 'pal-')"
21 rm "$tmpdir"
22
23 if [ -f "$outfile" ]; then
24 echo "Not overwriting $outfile"
25 exit 0
26 fi
27
28 set -x
29 mkdir "$tmpdir"
30 mkvextract tracks "$infile" 2:"${tmpdir}/audio"
31 mplayer -ao pcm:file="${tmpdir}/audio.wav" -vo null "${tmpdir}/audio"
32 sox "${tmpdir}/audio.wav" "${tmpdir}/audio-fixed.wav" speed "${SLOWDOWN}" gain -n
33 lame --preset standard "${tmpdir}/audio-fixed.wav" "${tmpdir}/audio.mp3"
34 mkvmerge -o "${outfile}" --default-duration "1:${FORCEFPS}fps" --no-audio "$infile" "${tmpdir}/audio.mp3"
35
36 rm -rf "$tmpdir"
37