]> code.delx.au - transcoding/blob - fix-pal-speedup
Script to fix videos from PAL DVDs which have been sped up by 4%
[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 = 24000 / 1001
15 # SLOWDOWN = FORCEFPS / 25
16 FORCEFPS="23.976023976023978"
17 SLOWDOWN="0.9590409590409591"
18
19 destdir="$1"
20 infile="$2"
21 outfile="$destdir/$(basename "$infile")"
22 tmpdir="$(tempfile -p 'pal-')"
23 rm "$tmpdir"
24
25 if [ -f "$outfile" ]; then
26 echo "Not overwriting $outfile"
27 exit 0
28 fi
29
30 set -x
31 mkdir "$tmpdir"
32 mkvextract tracks "$infile" 2:"${tmpdir}/audio"
33 mplayer -ao pcm:file="${tmpdir}/audio.wav" -vo null "${tmpdir}/audio"
34 sox "${tmpdir}/audio.wav" "${tmpdir}/audio-fixed.wav" speed "${SLOWDOWN}" gain -n
35 lame --preset standard "${tmpdir}/audio-fixed.wav" "${tmpdir}/audio.mp3"
36 mkvmerge -o "${outfile}" --default-duration "1:${FORCEFPS}fps" --no-audio "$infile" "${tmpdir}/audio.mp3"
37
38 rm -rf "$tmpdir"
39