Coming Underground
« B2evolution antispam listGentoo KDE 4.4 upgrade a day after »

Transcoding LATM packed HE-AAC audio with MythTV

Permalink 2010-02-23 09:01, by jaervosz, Categories: General, Gentoo Tips, Universe/English, Opensource, Mythtv , Tags: hack, mythtv, transcode, userjob

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.

Leave a comment »Send a trackback »

Trackback address for this post

This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

©2010 by admin

Contact Jaervosz