| « B2evolution antispam list | Gentoo KDE 4.4 upgrade a day after » |
Transcoding LATM packed HE-AAC audio with MythTV
Since some of the new Danish digital TV channels (on MUX2) are using the HE-AAC audio codec which is not widely supported (ie. on my Pop Corn Hour) I had to transcode the recordings before being able to watch it on my frontend.
I'm using VLC for the transcoding, since ffmpeg couldn't quite grok it yet.
For this I use the following simple script:
#!/bin/bash
vcodec="mp4v"
acodec="a52"
bitrate="VIDEO_BITRATE"
arate="128"
ext="aac"
mux="mp4"
vlc="/usr/bin/vlc"
input=$1
output=$2
#http://www.geekzone.co.nz/forums.asp?forumid=83&topicid=55394
$vlc -v -I dummy "$input" --sout "#transcode{acodec=$acodec,ab=$arate,channels=2,samplerate=48000}:duplicate{dst=std{access=file,mux=ts,dst=\"$output\"}" vlc://quit
exit $?
Note: You have to enable VLC stream support for the --sout to work (USE="stream").
With MythTV I wrap it in the following script for it to work as a normal MythTV UserJob:
#!/bin/bash
VIDEODIR=$1
FILENAME=$2
JOBID=$3
NEWFILENAME=`echo $FILENAME | sed -e "s/\....$//"`.mp4
# Sanity checking, to make sure everything is in order.
if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
echo "Usage: $0 <VideoDirectory> <FileName>"
exit 5
fi
if [ ! -f "$VIDEODIR/$FILENAME" ]; then
echo "File does not exist: $VIDEODIR/$FILENAME"
exit 6
fi
cat << EOF | mysql -h mysqlserver -u mythtv -ppassword mythconverg
UPDATE jobqueue SET comment = "Starting transcoding using vlc." WHERE id = $JOBID;
EOF
# Remove previous mp4 if any
if [ -f $VIDEODIR/$NEWFILENAME ]; then
rm $VIDEODIR/$NEWFILENAME
fi
/home/mythtv/bin/transcodelatm.sh $VIDEODIR/$FILENAME $VIDEODIR/$NEWFILENAME
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "vlc failed for ${FILENAME}.tmp with error $ERROR"
exit $ERROR
fi
#Update MySQL
cat << EOF | mysql -h mysqlserver -u mythtv -ppassword mythconverg
UPDATE recorded SET basename = "$NEWFILENAME", filesize = $(ls -l $VIDEODIR/$NEWFILENAME | awk '{print $5}') WHERE basename = "$FILENAME";
EOF
#Remove previous version
rm $VIDEODIR/$FILENAME
exit 0
I don't update the jobqueue table once the job is finished, since MythTV immediately overwrites my update. The wiki shows how to use a bit of trickery to update the jobqueue table after the job completes, but the above solution is fine for me.