Wednesday, November 22, 2006

Encoding PSP compatible MP4 video on Linux with ffmpeg

[UPDATE] Desktop Linux users rejoice! I've created a new step-by-step tutorial about converting video for the PSP with MPEG-4 AVC (also known as h264) using the graphical tool Avidemux. Check it out! [UPDATE 2 - 08/10/2008] Updated this tutorial with the latest PSP restrictions, and updated the commands to work with the latest version of ffmpeg. It took me a while to figure out (read: have time to investigate) how to convert any movie into a format that works on the PSP, on Linux, but I finally got it to work. First of all, if you're using Ubuntu (like me), you need to recompile ffmpeg with FAAC and FAAD support. You can find a great guide for this here: http://po-ru.com/diary/up-to-date-ffmpeg-on-ubuntu-hardy/. After recompiling ffmpeg, it basicly comes down to this: The PSP firmware has a set of restrictions for MPEG-4 files. If an MPEG-4 file doesn't conform to these restrictions, the PSP simply won't recognize the file. These are the restrictions:
  • The format must be 'psp'
  • Width and height must be a multiple of 16
  • Width*height can't be more than 76800.
  • The video codec must be mpeg4
  • The audio codec must be aac
  • Framerate must be 30000/1001 (~29,97 fps) or 15000/1001 (~14,985 fps)
  • The audio rate must be 24kHz
The native resolution of the PSP's display is 480x272, however, if your video isn't in 16:9 aspect ratio, but in 4:3, I recommend you use 320x240. If you plan on playing your video on a TV set, I recommend you use 720x480, no matter what aspect it is in. Here's two example ffmpeg commands for two-pass encoding: First pass: ffmpeg -i <inputfile> -title "<title>" -vcodec mpeg4 -acodec libfaac -b 672k -ab 96k -ar 24000 -s 480x272 -aspect 16:9 -g 300 -aic 2 -mbd 2 -cmp 3 -precmp 3 -subcmp 3 -trellis 2 -flags +4mv+trell -pass 1 -f psp Video.mp4 Second pass: ffmpeg -i <inputfile> -title "<title>" -vcodec mpeg4 -acodec libfaac -b 672k -ab 96k -ar 24000 -s 480x272 -aspect 16:9 -g 300 -aic 2 -mbd 2 -cmp 3 -precmp 3 -subcmp 3 -trellis 2 -flags +4mv+trell -pass 2 -f psp Video.mp4 The meaning of the options: -i <inputfile> -title <title> -acodec <audio codec> -ab <audio bitrate> -ar <audio rate> -vcodec <video codec> -b <video bitrate> -s <resolution> -aspect <aspect ratio> -f <format> All the other flags are options to optimize the video quality, at the expense of encoding speed.

7 comments:

Nigel said...

New versions of ffmpeg have changed the -b argument. See this post for details.

Thank you for this blog entry - I wouldn't have been able to encode a useable MP4 without it.

Yogarine said...

Thanks for the tip, I changed the post to reflect these changes. :-)

You're welcome!

Anonymous said...

You can also encode PSP files directly with mencoder, in both h264 and mpeg4 formats. Have a look at my site at http://videogeek.com for some good command lines.

Anonymous said...

thanks for the tip!

said...

Didn't work for me. (What else is new?) The video encodes but won't play on PSP.

Anonymous said...

Ditto to HyperHacker's post. I can successfully encode, but the PSP give's me the "Unsupported Data" message.

If I select the video, and hit the "Information" link, the PSP apparently knows that the proper video size, length, resolution, video codec (MPEG-4 -kbps), audio codec (AAC -kbps) and sampling frequency (24.000kHz). Maybe you must specify the kbps i video & audio encoding... I'll play around more.

Mp3 Video Converter said...

Does anyone know if there is a way to import converted songs (with the app MP3 Converter - Free Mp3 Video Converter' to my phone? In fact, there is a button when you click on the converted song into mp3 format easily: Look on: mp3 video converter