]> code.delx.au - transcoding/blob - fix-pal-speedup
Moved from jamesstuff
[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 slowed and
6 # volume normalised then re-encoded as mp3.
7
8 if [ -z "$1" -o -z "$2" ]; then
9 echo "Usage: $0 destdir infile [infile ...]"
10 exit 1
11 fi
12
13 FORCEFPS="24"
14 SLOWDOWN="0.96"
15
16 destdir="$1"
17 shift
18
19 for infile in "$@"; do
20 outfile="$destdir/$(basename "$infile")"
21
22 if [ -f "$outfile" ]; then
23 echo "Not overwriting $outfile"
24 continue
25 fi
26
27 set -x
28 tmpdir="$(mktemp -d "${TMPDIR:-/var/tmp}/pal-XXXXXXXX")"
29 mplayer -novideo -ao pcm:file="${tmpdir}/audio.wav" -vo null "$infile"
30 sox "${tmpdir}/audio.wav" "${tmpdir}/audio-fixed.wav" speed "${SLOWDOWN}" gain -n
31 lame --preset standard "${tmpdir}/audio-fixed.wav" "${tmpdir}/audio.mp3"
32 trackid="$(mkvmerge -i "$infile" | grep video | sed 's/^Track ID \(.\):.*$/\1/')"
33 mkvmerge -o "${outfile}" --default-duration "${trackid}:${FORCEFPS}fps" --no-audio "$infile" "${tmpdir}/audio.mp3"
34
35 rm -rf "$tmpdir"
36 done
37