I recently tried unsuccessfully to watch an HD movie on my MythTV box, and while the video was fine the audio (Dolby Digital) kept dropping out. The CPU load on my server was pretty low so this wasn’t the problem and I tried copying the file to the server itself rather than accessing it via NFS from my file server to rule out network bandwidth problems.
I then decided that maybe my Amp couldn’t handle the high AC3 bitrate (640kbps) of this file so I looked into how I could reduce it. After much googling and experimenting I finally managed to create a version of the file with a reduced AC3 bitrate, and thankfully, it played fine. As it turned out the movie was pretty crap, but you get that sometimes.
I put together this script that uses various freely available Linux tools to split the video file into separate audio and video components, re-encodes the audio and then puts it back together in case I need to do this again in the future.
#!/bin/sh
infile=$1
outfile=$1-out
cd /media/Temp
tcprobe -i $infile
echo
echo Extracting AC3 soundtrack ...
echo
tcextract -d2 -i $infile -a0 -x ac3 | tcextract -d2 -x ac3 -t raw > soundtrack.ac3
echo
echo Extracting individual audio channels ...
echo
export AC3_6CH=en
/share/bin/ac3dec -o null soundtrack.ac3
echo
echo Converting individual audio files to WAV ...
echo
for i in *.pcm
do
echo $i
sox -t raw -r 48000 -w -s $i `basename $i .pcm`.wav
done
echo
echo Recreating AC3 soundtrack ...
echo
rm -f 6ch.ac3
multimux -f en_l.wav en_c.wav en_r.wav en_ls.wav en_rs.wav en_lfe.wav
echo
echo Creating Xvid AVI file ...
echo
transcode -i $infile -p 6ch.ac3 -y xvid -e 48000,16,6 -E 48000,16,6 -A -N 0x2000 -o $outfile
rm -f *.pcm *.wav
The hardest part was extracting the individual audio tracks from AC3 and I eventually found this site which had a patched version of an AC3 decoder. I had to do a bit of work to get it to compile on a recent Linux system.