Convert MythTV Video for IPOD

November 11th, 2007

These steps worked on Ubuntu Feisty on a 32 bit system and an Ipod Classic.

The packaged version of ffmpeg on Ubuntu Feisty wasn't doing the job, giving me this error while trying to convert an mpeg 2 to an mpeg 4: Unsupported codec for output stream #0.1 Newer versions of Ubuntu may fix this so try your luck with the following command.


sudo aptitude update
sudo aptitude install ffmpeg
ffmpeg -i inputfile.mpg -b 300 -qmin 3 -qmax 5 -g 300 -ab 96000 -s 320:240 -aspect 4:3 test.mp4

If this doesn't work ffmpeg will need to be compiled locally with the following instructions.

1. Uninstall ffmpeg


sudo aptitude remove --purge ffmpeg

2. Get the latest ffmpeg source.

An svn checkout is also available at http://ffmpeg.mplayerhq.hu/download.html


wget http://ffmpeg.mplayerhq.hu/ffmpeg-export-snapshot.tar.bz2
tar -xvjf ffmpeg-export-snapshot.tar.bz2
cd ffmpeg-export-???

3. Install compile dependencies.


sudo aptitude install libfaac-dev liba52-dev libdc1394-dev libgsm1-dev libogg-dev libvorbis-dev libxvidcore-dev

4. Configure the build, make, and install.


./configure --enable-libxvid --enable-libfaac --enable-gpl --enable-pp --enable-pthreads --enable-libvorbis --enable-libogg --enable-liba52 --enable-libgsm --enable-libdc1394 --disable-debug --enable-shared
make
sudo make install

5. Edit shared library configuration.


sudo cp /etc/ld.so.conf /etc/so.conf.bak
echo "echo /usr/local/lib >> /etc/ld.so.conf" | sudo sh

6. Update library simlinks.


sudo ldconfig -v

7. Make sure bin paths are configured correctly.


which ffmpeg

This should output /usr/local/bin/ffmpeg. If not, restart the shell and check the PATH variable. Ensure /usr/local/bin comes before /usr/bin and /bin.

8. Test it out somewhere.


ffmpeg -i inputfile.mpg -b 300 -qmin 3 -qmax 5 -g 300 -ab 96000 -s 320:240 -aspect 4:3 test.mp4
file test.mp4

That's it. The remaining is icing on the cake.

9. Automate it.

Make was designed for automating software builds. The advantage in using it to automate file conversion is that it will recognize when no work needs to be done for an output file. Create a directory called ipod which is a sibling of the mythv recordings directory. Place the following make-rule inside a Makefile in that directory.

File: recordings/../ipod/Makefile


%.mp4 : ../recordings/%.mpg
        ffmpeg -i $< -b 300 -qmin 3 -qmax 5 -g 300 -ab 96000 -s 320:240 -aspect 4:3 $@

Create a script to tell Make which output files to create. In this case it's the basename of each MythTV mpeg with an mp4 extension. Make will use the above rule to figure out how to create an mp4 file with a given name. Make will do nothing if the file already exists and is newer than the input file. Name the script convert and chmod it to 755.

File: recordings/../ipod/convert


#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
export PATH

make `ls ../recordings/*.mpg | sed 's/\.\.\/recordings\///' | sed 's/.mpg$/.mp4/'`

The ugly recording filenames consist of two parts. 1005_20071004210000.mpg, for exampe. The 1005 is the chanid column in the 'channels' table and the rest is a date and time. Luckily the information about a recording is in the 'recorded' table so that can be used to create pretty names for the new mp4's. Here's a my solution. TIMTOWDI, right?

File: recordings/../ipod/make-pretty


#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
export PATH

mkdir -p pretty

for filename in `ls *.mp4`; do
        basename=`echo $filename | sed 's/.mp4$/.mpg/'`
        prettyname=`mysql -umythtv -p???????? -e "select concat(title, ' ', progstart) as name from recorded where basename = '$basename' limit 1;" --database mythconverg -NE \
        | grep name: | sed 's/name: //' | sed 's/00$//' | sed 's/://g' | sed 's/$/.mp4/'`
        ln -sf "../$filename" "pretty/$prettyname"
done

Add the following line to /etc/crontab or create a new file called /etc/cron.d/ipod and place it there instead. Be sure to sudo chown -R the ipod directory to the same user specified in the crontab. Every morning the ipod/pretty directory will be filled with shows to watch on the morning commute.

File: /etc/cron.d/ipod


05 2            * * *   mythtv          cd ???????? && nice -n19 ./convert && ./make-pretty

8 Responses Follows

  1. Tara says

    My hero! Thank you!

  2. devin says

    does it work with 64 bit libraries? I tried this, but got some errors I wasn’t able to decipher well enough to fix.

    Very cool, though. Maybe I’ll sftp all my stuff to your box, and sync the ipod later! :-D

  3. Sam says

    does it work with 64 bit libraries?

    Good question. I have no idea. Tara and I don’t have a 64-bit machine yet.

  4. Cino says

    Brilliant, absolutely brilliant! Only one small thing that I noticed: the latest ffmpeg doesn’t support the—enable-libogg switch, does somebody know why?

  5. Sam says

    The ./configure options seem to be changing quite a bit since every webiste I’ve referenced has different flags and most were unsupported e.g. —enable-ogg became—enable-libogg, and now it’s most likely something else. I compiled an updated version a few days after this and the—enable-libogg was gone.

  6. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like beats by dr dre.”Three ages beats by dr dre back, Jimmy Lovine and Dr. Dre ended up talking about the calendar new music chaos and what went wrong. Though technological know-how bogus audio additional obtainable, the complete had suffered. Bodies were not viewers it the way in which artists supposed. For two bodies so amative about audio, this was inexcusable. So they boarded on the opportunity to achieve bigger full and alarm calendar music ashamed within the adapted course. monster beats by dre ferrari commenced with Headphones. They captivated up with Monster artisan Noel Lee who accumulated the previously mentioned vision, and collaborated with him to reinvent headphones for that calendar age. Beats was born. Songs was reborn.” States Beats by Dr. Dre.

  7. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like beats by dr dre.Individuals you should not accept to anniversary with the audio. Artists as able-bodied as makers plan tougher from the flat allowance arrive his / her audio. Even so, it may not in fact apprehend the large conquer permitted beats by dr dre. Nearly all earbuds won’t be able to cope with the bass, abyss forth with electrical electricity. Tha acrid fact, the audio won’t advance you. Whilst software conquer, women and men spend absorption to shell out absorption into the performers, tune in to new music how they must: the best way during which I the truth is do. Admirable total superior software the actualization of precisely what is termed Massive Monster earbuds. You could biking to a admirable audio central audition headsets DRE. You’ll be take apprenticed that it’s admirable superior of audio. We’re able to accommodate you want the suitable Monster headphone . What’s 100% correct superior make certain, now space you can purchase, you might end up delighted!monster bound egold.

  8. beats by dr dre says

    Really like your blog,thanks for sharing it with us.And I also like beats by dr dre.Despite weighting in at abutting to 270 grams they can be in reality enough to put on even for attached periods and relocating about beats by dr dre. The earcups are formulated gaining adequate and in fact enclose your aeriform to lock out ambient noise. Their alive emphasis abatement is in reality able in blocking out abhorrent appears if audience for your songs, and by flicking merely a little improve with regards to the headphones on their own you are able to all on the brusque purchase to what it annex on abutting to you. a allotment with the best noice cancelling beats by dr dre i purchase in fact tried. That is to your goal which they get frequent affluence of a affluence of abounding many years into this handle company. owning outlined the achievement that accustomed men such as you and me obtain to achieve our way up the ladder. You charge to accomplish a casting for by your cocky by ancestry lot’s of beats and alive with artists.Till afresh you truly will purchase to realize for bartering your arrangement beats headphones in the 20 greenback assortment. Hey you cost to appear out some the location.


Your Response