How to encode video for PSP with ffmpeg and AVC/H.264 MP4 profile

January 8, 2009

I’ll keep this post simple as I don’t fully understand all of the different flags, however I did thoroughly go through various other posts on the x264 codec and the best flags to use for encoding for PSP.

The results below are designed for creating videos at full 720×480 resolution for the PSP with high quality and not super fast encoding in mind. See my earlier post on Encoding video for the PSP for info on alternative methods.

I used a 2-pass encode, but you can use 1-pass if you don’t feel the need, just remove the “-pass 2” code.

ffmpeg -y -i %1 -s 720x480 -r 25 -an -pass 1 -vcodec libx264 -b 1400kb -bt 2000kb -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -refs 2 -me_method umh -me_range 17 -subq 1 -trellis 0 -coder 1 -bf 7 -b_strategy 1 -threads 0 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 %2.mp4

Use the above for the first pass, and the below for the second pass:

ffmpeg -y -i %1 -s 720x480 -r 25 -acodec libfaac -ab 160k -ar 48000 -pass 2 -vcodec libx264 -b 1400kb -bt 2000kb -flags +loop -flags2 +mixed_refs+wpred-fastpskip -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -level 30 -refs 2 -me_method umh -me_range 17 -subq 7 -trellis 2 -coder 1 -bf 7 -b_strategy 1 -threads 0 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 %2.mp4

Note: The “-y” option will automatically overwrite the output file if it uses an existing file name, so remove that if you want to be warned about this by ffmpeg. “-y” forces “yes” as an answer.

I wrote a basic .bat batch script for ms-dos/windows automating this a bit, so you only have to type “ffmpegdos input.file output.name”, these are represented by %1 and %2 respectively in the above ffmpeg examples. You can replace %1 with the actual input file name, and %2 with the actual output filename if you want to just run it manually.

The contents of the .bat file are as follows:

@ECHO OFF
echo about to begin encode process...
pause

echo are you sure you wish to overwrite %2.mp4?
pause
D:InstallFFMpegffmpeg -y -i %1 -s 720x480 -r 25 -an -pass 1 -vcodec libx264 -b 1400kb -bt 2000kb -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -refs 2 -me_method umh -me_range 17 -subq 1 -trellis 0 -coder 1 -bf 7 -b_strategy 1 -threads 0 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 %2.mp4
D:InstallFFMpegffmpeg -y -i %1 -s 720x480 -r 25 -acodec libfaac -ab 160k -ar 48000 -pass 2 -vcodec libx264 -b 1400kb -bt 2000kb -flags +loop -flags2 +mixed_refs+wpred-fastpskip -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -level 30 -refs 2 -me_method umh -me_range 17 -subq 7 -trellis 2 -coder 1 -bf 7 -b_strategy 1 -threads 0 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 %2.mp4
echo DONE!

Just copy paste the above into an empty text file using notepad or similar and save it as ffmpegdos.bat, to run it just open a “Command Prompt” and type ffmpegdos input.file output.name. The .mp4 extension is automatically appended to your output filename.

Good luck!

Advertisements

10 Responses to “How to encode video for PSP with ffmpeg and AVC/H.264 MP4 profile”

  1. […] December 24, 2008 This is a mostly OS X centric post, but it’s just as relevant for linux and windows as it centres around the use of ffmpeg. (If you want specific ffmpeg info read my other post.) […]

  2. Boomhaueruk said

    Hi again,

    I alluded to this in comments to your other post, but do you have some settings for using the OSX GUI for FFMPEGX to achieve this? Wouldn’t know how to run scripts – happy to try but more aiming at getting the GUI Settings for high quality PSP Video if you’re up for helping?

    As I mentioned; I’ve started a thread to discuss FFMPEGX settings here:

    http://forum.videohelp.com/topic367347.html#1961780

    I’m trying to make it quite user friendly, doing everything through the GUI for non script people like myself – your obviously expert help much appreciated (Using PSP Firmware 5.00 at the moment incidentally).

    • 0ffl1n3 said

      Hey – if you want to mess with ffmpeg, the best way is using the command line. Either in Terminal on a Mac /or/ DOS on a PC.

      If you don’t like scripts (which really are no more complicated than messing with ffmpegx) then just do it manually.

      Simply copy and paste the two seperate passes at the top of the post into the command line one at a time (mac or PC) exactly as is. Changing %1 to the input-filename and %2 to the output-filename.

      Otherwise I suggest you look at the documentation for ffmpeg/(x) and find ways to convert those options into ffmpegx compatible ones.

      Again, the script is not important and unnecessary here, all it does is run one command after the other for you. I wouldn’t be affraid of it, but I understand that a UI like ffmpegx can be easier to tweak, so good luck with that.

      P.S. feel free to put a link to my posts in yours.

  3. Jani said

    Hi great example, but where I can download ffmpeg with aac support?

  4. Jani said

    Hi great tutorial, but where I can download ffmpeg with aac support for windows?

    • 0ffl1n3 said

      Depends on your OS, but for instance with OS X or linux you can compile your own ffmpeg with all options, which is what I did. Anyway, you’ve probably found a solution by googling by now.

    • 0ffl1n3 said

      Hei Jani,

      Jos tarvitset windowsin versio piti googlia jotain ffmpeg.exe, sellaisten oli kaytetty mun esimerkiksini…

      For windows, you will have to google for a precompiled binary of ffmpeg, this is what I used in the example above and it worked well.

  5. Jani said

    Hi

    I found enough old windows version which supports aac, in newer versions it has removed due … see: http://ffmpeg.arrozcru.org/autobuilds/blog/2009/05/19/libfaac-removed/

    • 0ffl1n3 said

      Jani,

      Hyvä Suomi.

      Yeh, these days I’m using linux or OS X, so it’s not an issue when you compile the binary yourself.

      Good luck.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: