Archives 2005

MythTV and a Sony PSP

I’m not really much of a gamer, but after having a go on someone’s PSP, I had to get myself one. They are a wonder of modern technology. A small package that crams just about everything you could want to play games, and more besides. It is sold as a games machine, but it makes a pretty good all round portable multimedia system, playing movies, MP3s and holding your holiday snaps on there too!

Most of the functionality is easy to get to work with linux. Basically it is seen as a mass storage device and files can be copied to and from it with the usb cable. The one area that is problematic under linux is movies. Sony have decided to only support an MP4 media format, and even then it has some strange headers so that only certain MP4 files will play. There’s plenty of information out on the net for converting these files, but it can be hidden in various different sources. I’ve written this article to draw together all those sources into one place. I’ve tried to credit the original supply of the information wherever possible.

First step is to get a working copy of ffmpeg that supports the PSP format. This isn’t as easy as it sounds. I ran into problems with the version of compiler I was using. Most up to date distributions ship with gcc4, which will not let you compile the ffmpeg that you need. On Mandrake and Debian, they also ship a version of gcc3, but unfortunately this has a bug in it which means that you will get halfway through the compile and it will crash. In the end I downloaded the source for the latest version of gcc3 (3.4.5) and compiled that. On Mandrake you change the symlink in /etc/alternatives/gcc to the version you want to use, in Debian the symlink is in /usr/bin/gcc

Feel free to try with the version of compiler you have, but if you have any problems then just get the latest version of gcc3. It may be worth trying seeing as it takes a rather long time to compile gcc!

A few other libraries are needed to get this working, but I found the default ones in Mandrake 2006 to work fine, YYMV. The libraries needed are the libfaad, libfaac, libogg and libvorbis. Don’t forget to get the -devel packages for these (-dev under debian).

Once you are ready to compile, I found the best instructions on the linux PS2 site, in a post by “cronocloud“. Here is the basic gist of the post.

Get a snapshot of the ffmpeg CVS from the 10th March at: http://www.nurs.or.jp/~calcium/3gpp/sources/ffmpeg-050310-0.30.tar.gz, along with a patch from: http://www.nurs.or.jp/~calcium/3gpp/sources/ffmpeg_patched_diff_031.tar.gz.

Uncompress the ffmpeg and patch tarballs into the same directory. Next move the file libavformat/movenc.c from the patch into the ffmpeg/libavformat directory, overwriting the existing one. Then, open the file in an editor and find the section (near the top) that looks like:

#ifdef WIN32_PSP 
 #include "wchar.h" 
 #include "locale.h" 
 #include "windows.h" 
 #endif

Replace this with:

#ifdef WIN32_PSP 
#include "wchar.h" 
#include "locale.h" 
//#include "windows.h" 
 
#define CP_ACP 0 
#define MB_PRECOMPOSED 0 
size_t MultiByteToWideChar(int a, int b, char *src, size_t c, wchar_t *dest, size_t n) { return mbstowcs(dest, src, n) + 1; } 
#define _timezone 0 
#endif

Edit the file ffmpeg/libavformat/Makefile and remove the line:

OBJS+=avisynth.o

Edit the file ffmpeg/libavformat/allformats.c and remove the line:

avs_init(); // [MobileHackerz]

Lastly, edit the file ffmpeg/ffmpeg.c and remove the lines:

setvbuf(stdout, (char *)NULL, _IONBF, 0); // [MobileHackerz] 
setvbuf(stderr, (char *)NULL, _IONBF, 0); // [MobileHackerz] 
_setmode(_fileno(stdout), _O_BINARY); // [MobileHackerz]

Once all this is done, run a configure and make in the main ffmpeg directory. This should go away and compile ffmpeg (hopefully). The configure line to use is:

./configure --enable-gpl --enable-faac --enable-faad --enable-vorbis --enable-ogg

By now, you should hopefully have a ffmpeg binary that will convert just about any movie format into one that can be played on your PSP. Unfortunately, ffmpeg is not the simplest of programs to use, and needs 101 command line options to be specified. I’m not exactly an expert when it comes to video formats, so a lot of these options I specify below come from the “monkey see, monkey do” school of thought! The following is an example of how to convert a NUV video (the kind used in MythTV) to a PSP MP4 format.

./ffmpeg -y -i /home/mythtv/Recordings/1010_20051213180000_20051213183000.nuv -title "The Simpsons - Brothers Little Helper" -bitexact -f psp -s 320x240 -r 29.97 -b 768 -acodec aac -ac 2 -ar 24000 -ab 32 -map 0:0 -map 0:2 ~/M4V00070.MP4

This will take the file and encode it to an output file ~/M4V00070.MP4. The filename must be in this format for the PSP to pick it up. (M4V followed by 5 numbers, ending with .MP4 – All characters must be in upper case). Some options are straight forward (-title!) some others can be tweaked. The frame rate (-r) should be either 29.97 or 14.985. I’ve not been able to get any other rates working. The bitrate (-b) should be either 384 or 768, depending on what type of quality you want. -f specifies the output format is psp (duh!), -acodec is the audio codec to use (aac) and the -map options at the end are so that the audio works with NUV videos (probably not needed for other movies).

The last step I did was to take a script that I found on the MythTV website and extend it a little. Thanks to james at mauibay for the initial script. Extensions on mine include, automatic tracking of movie number, to always create unique movies, and creation of a thumbnail. Also it will produce a log file so you can check on why things went wrong. This script can then be added as a user job in MythTV so that it can be fired off on any recording, or automatically on all.

#!/bin/bash

FILE=$1
TITLE=$2

FFMPEGBIN=/home/mythtv/bin/ffmpeg
OUTDIR=/home/mythtv/PSP
declare -i FILENUM=`cat $OUTDIR/.filenumber`

OUTFILE="M4V`cat $OUTDIR/.filenumber`.MP4"
OUTTHM="M4V`cat $OUTDIR/.filenumber`.THM"

echo "Encoding" > $OUTDIR/.$OUTFILE.log
echo "Input file:  $FILE" >> $OUTDIR/.$OUTFILE.log
echo "Output file: $OUTFILE" >> $OUTDIR/.$OUTFILE.log
echo "Title:       $TITLE" >> $OUTDIR/.$OUTFILE.log

let FILENUM=$FILENUM+1
printf "%05d" $FILENUM > $OUTDIR/.filenumber


$FFMPEGBIN -y -i $FILE -title "$TITLE" -bitexact -f psp -s 320x240 -r 29.97 -b 768 -acodec aac -ac 2 -ar 24000 -ab 32 -map 0:0 -map 0:2 $OUTDIR/$OUTFILE >> $OUTDIR/.$OUTFILE.log

$FFMPEGBIN -y -i $FILE -title "$TITLE" -s 160x90 -padtop 16 -padbottom 14 -r 1 -t 1 -ss 3:00.00 -an -f singlejpeg $OUTDIR/$OUTTHM >> $OUTDIR/.$OUTFILE.log

When setting the MythTV job, don’t forget to put quotes round the title setting!

Hopefully this is easy to follow and has all the information in one place. If you need any more help or know of anything missing from my explanation, feel free to drop me a line.

Web pages moved!

Well, I’ve been playing a lot of online games recently (Day of Defeat mainly) and discovered a slight problem. Previously these web pages, including all the 100’s of pictures, were hosted on my web server in my cellar. Unfortunately this meant that whenever someone was looking at my pictures I got really bad lag and got killed!

I’ve now moved my web pages and pictures to a remote server that I look after, run by my hosting sideline, TinyNetworks. Hopefully everything should have moved across OK. If you spot any problems, let me know! Not that this will improve my gameing any. I’ll still get killed just as often, but at least now I’ve not got an excuse! Also, viewing the pictures may well be a bit faster now!

No ‘net for 24 hours!

Well, not exactly true, I could get on from work, but my home connection was down for an extended period!

But I survived!

Eventually the problem was tracked down to a BT fault, as usual. This has only been my second major outage since getting ADSL (over 3 years now) so its not really bad going.

Normal services will now be resumed!

Lancaster Mesh

Well, I’ve just been looking through the logs for one of my little pet projects, Lancaster Mesh, and noticed that there has been a little bit of traffic to it including some downloads of the software. Will wonders never cease!?

I’ve also heard rumours of people picking up the mesh wireless network (cunningly called lancastermesh) from all sorts of places around Lancaster. Now this means that either people are messing with it and not letting me know (nowt wrong with that.. they’re welcome to!) or other people are trying to do a mesh in Lancaster. In either case, if you pick up a wireless network called lancastermesh, email me and let me know when and where you picked it up from.

On a totally unrelated note, cheers to Olly for getting my map of Lancaster, er I mean Ankh-Morpork signed by Terry Pratchett!

Weblog Vulnerablities – Important

Hi,

Sorry to butt in, but I’ve just had to upgrade the software for this weblog to fix a major security vulnerability. This affects quite a few bits of blog software including PostNuke, WordPress, Drupal, Serendipity, phpAdsNew, phpWiki and phpMyFAQ. If you are running any of these, please upgrade!

Press Release

Thanks,

Darren.

The Wedding!

Thankfully, not my wedding. Today (well, yesterday, Saturday) Matthew Lee and Patricia McGrath tied the knot at the Registry office in Lancaster. Here is a link to some pictures from the (long, exhausting, fun) day.

The Wedding Photos

Congratulations to Matty and Trish!

Darren.

New web hosting

Hello again,

I’ve just been preparing a server for hosting web pages and the like for local bands, etc. and some projects I’m working on. If you happen to be in the market for a small, cheap server, just click the link below. If you sign up through this link I get a discount on my current server 😉 Also, here’s a referer link to the company I buy all my domain names through, so if you want a domain name and click through this link to get it, I get 10% 8)



Bytemark Hosting


So far I’ve got one of my projects hosted there and a couple of bands:

If any one else wants me to do some hosting, give me a shout and we’ll come to an arrangement! 8)

Darren.

House wide MultiMedia System

I’ve just finished getting MythTv working in my house which means that I can watch Freeview on any cheap PC hooked up to a TV. Along with this I can set up recording of programs to my server, pause/rewind of live TV, and a whole list of other stuff including playing MP3’s, watching video files downloaded off the ‘net, check the weather, play DVD’s, view all my photos and even make phone calls!

I’ve gone commercial!

Hello again,

I’m back at work now 🙁 and in my ever running attempt at earning money for doing nothing I’ve put some google adverts and a google search bar on here. Basically if you click on an advert or use the search bar I get a (miniscule) amount of money! so click away! 😎

Darren.