Using ffmpeg to transcode video for the PS3

From PS3 Wiki

Jump to: navigation, search
   * 1 Linux Users
         o 1.1 pspvc and why you should install it
         o 1.2 Converting video for use on a Standard Resolution (480i) TV
               + 1.2.1 Source video is standard resolution
               + 1.2.2 Source video is in widescreen aspect ratio
         o 1.3 Converting video for use on a High Definition TV

[edit] Linux Users [edit] pspvc and why you should install it

The best tool I have found for converting videos for play on the PSP easily is called pspvc. It is an open source, GTK-based GUI program for converting video for the PSP; you can download it here: http://pspvc.sourceforge.net/

The problem with pspvc for converting video for the PS3 is that pspvc assumes you want the screen resolution of the PSP. Unfortunately, this means that while you *can* use pspvc to convert videos for the PS3, the resolution is really low.

A great side-effect of installing pspvc is that it installs a version of ffmpeg that is able to convert video for the PS3 as well. Normally, this is a really painful and complicated process. Installing pspvc does this for you. One catch, though, is that the install scripts for pspvc are a little screwy and end up installing ffmpeg in a really weird path (they probably meant for it to install in /usr/share or...):

/share/pspvc/bin/ffmpeg

Whether or not you choose to install pspvc or build ffmpeg yourself, the instructions below should allow you to convert video for playback on your psp3! [edit] Converting video for use on a Standard Resolution (480i) TV [edit] Source video is standard resolution

This is an easy conversion. Assuming the pspvc install path of ffmpeg, here's an example:

/share/pspvc/bin/ffmpeg -y -i InputVideoFile.avi -title "Title Of Your Choosing Here" -bitexact    
-vcodec xvid -s 640x480 -r 29.97 -b 1500 -aspect 4:3 -acodec aac -ac 2 -ar 24000 -ab 64 -muxvb 768
OutputFileNameOfYourChoosingHere.mp4

[edit] The above method would not work for me but I was able to get it working with the following command:

ffmpeg -i input_file_name.avi -sameq -s 640x480 output_file_name.mpg

This will encode the video into mpeg1 format which also plays on the PS3. This should work with almost any install of ffmpeg and not just the pspvc version. You can change the -s option to what ever resolution you want but if you set it higher than the input file it wont look any better. For example the video file I'm working with is 480x360 so encoding it with -sameq, -sameq -s 640x480, and -sameq -s 1280x720 all give me the same quality. So I recommend that you just use -sameq unless you want to lower the resolution of the output video.

[edit] Source video is in widescreen aspect ratio

If you use the example above on an input video that has a widescreen (16:9) aspect ratio rather than the standard aspect ratio (4:3) on the PS3, the video will appear stretched vertically and you won't be able to resize it using the display options on the PS3. The solution in the example below is to size the widescreen video down to 640x360 and adding 120 pixels of padding (60 top, 60 bottom) so the resulting video is 640x480 with letterboxing. Your video then will not be stretched! Again, assuming the pspvc install path of ffmpeg:

/share/pspvc/bin/ffmpeg -y -i InputVideoFile.avi
-title "Title of Your Choosing Here" -bitexact -vcodec xvid -s 640x360 -r 29.97 -b 1500 -aspect 16:9
-padtop 60 -padbottom 60 -acodec aac -ac 2 -ar 24000 -ab 64 -muxvb 768
OutputFileNameOfYourChoosingHere.mp4

Converting video for use on a High Definition TV ( PS3 AVC file h264 with High Quality level )

Here it is ! First ,don't know if it works with PS3 Firmware lower 1.82, so ... update ! To make a real h264 video ( MPEG 4 / AVC with AAC ) which is displayed as AVC video on PS3 try the following command as starting point. Not more ... not less. I am using the latest ffmpeg from SVN, don't know if it works with older ones ? So do ...

ffmpeg -i /path/to/your/video -y -vcodec libx264 -acodec libfaac -title 'your title' -f mp4 -mbd rd -flags
4mv+trell+aic+qprd+mv0 -cmp 2 -subcmp 2 -flags2 dct8x8+skiprd -level 41 -b your_video_bitrate -bf 3 -ac
your_channels -ab your_audio_bitrate -threads your_threads -pass 1|2 /path/to/your/putput.mp4


to make it work YOU HAVE to replace your_video_bitrate with desired bitrate ( 1000kb - 20000kb ??? etc. ), your_audio_bitrate ( 64kb - ???? etc. ), your_channels with 2 for stereo or 6 for multichannel ( if source is ac3 ), your_treads with at least 2 when you own a dual core else remove the option or set to 1. Pass means 1 or 2 :-).

Have encoded Elefants_Dreams_HD.avi to Elefants_Dreams_HD.mp4 ... just fine, have fun. For all who tries to get it work with different settings => dont't forget to set -level to 31 or 41, no chance without it yet!

[edit] This page got me started so I am giving back my script that I use for converting files to ps3 format for use with mediatomb :) Use at your own risk, please improve where possible, and update. This script will grab a directory full of *.vob files and move to a format with decent quality, if you are converting from avi or other change the wc (wildcard variable to avi etc..) The additional h264 modifiers were from Robert Swain page, he put some research into getting the best quality out of h264 and I think he's on the money, so I combined those modifiers with the above command lines and got this enjoy:

####BEGIN SCRIPT####
##robert swain suggetsed defaults for h264 vbr combined with ps3 requirements
##added level 31 after -b_strategy 1 - in pass 2 try for ps3
##added loop code to batch convert
##todo - work on aspect ration variables, implement method for cropping to lower file size when possible##
ext=vob
wc=*.$ext
log=batch_logfile.txt
vidbitrate=1050kb
audbitrate=128kb
for srcfile in $(ls $wc)
do
echo "source file is $srcfile" >>$log
bname=`basename $srcfile .$ext`
tempfile="$bname"pass1temp_"$vidbitrate"_"$audbitrate".mp4
echo "temporary file is $tempfile" >>$log
dstfile="$bname"_"$vidbitrate"_"$audbitrate".mp4
echo "destination file is $dstfile" >>$log
title=$bname
echo "title is $title" >>$log
audchannels=6
bittolerance=200kb
threads=2
echo "`date` starting pass 1" >>$log
ffmpeg -i $srcfile -an -pass 1 -vcodec libx264 -b $vidbitrate -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me epzs -subq 1    -trellis 0 -refs 1 -bf 3 -b_strategy 1 -threads $threads -level 31 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt    $bittolerance -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 $tempfile
echo "`date` starting pass 2" >>$log
ffmpeg -i $srcfile -acodec libfaac -title $title -ac $audchannels -ab $audbitrate -async 1 -f mp4 -pass 2 -vcodec libx264 -b $vidbitrate -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -bf 3 -b_strategy 1 -threads 2 -level 31 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt $bittolerance -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 $dstfile
echo "`date` finished look for $dstfile" >>$log
echo "`date` removing $tempfile"
rm -f $tempfile >>$log
done
####END SCRIPT####
Personal tools