SpinOneSolutions | I waste my time so that you don't have to…



PS3 H264/AAC 5.1 Encoding with FFmpeg

The Problem:

You want to encode video for playback on a PS3 using FFmpeg.

The Solution:

I’ve got a working command line option for you right here.  This is a solution, not the only solution.

My Setup:
Ubuntu 9.10 (Karmic)
libx264 (for encoding H264)
libfaac (for encoding AAC)

I’m also going to assume that your input file is a .mkv containing an H264 video track and an AC-3 audio track.  Most of the time this is fair assumption however, it won’t be correct 100% of the time.

To start, you’re going to need a current build of FFmpeg. It’s been a while since I did the build but I think these were my configuration options.

#cd ~/ffmpeg #make distclean
#svn update #sudo ./configure \
--enable-gpl \
--enable-nonfree \
--enable-postproc \
--enable-pthreads \
--enable-x11grab \
--enable-runtime-cpudetect \
--enable-libdc1394 \
--enable-libfaac \
--enable-libfaad \
--enable-libgsm \
--enable-libmp3lame \
--enable-libtheora \
--enable-libvorbis \
--enable-libx264 \
--enable-libxvid \
#make #sudo checkinstall \
--ftrans=no \
--install=yes \
--pkgname=ffmpeg \
--pkversion "4:0.5.svn'date + %Y%m%d'-12ubuntu3" \

On to what you REALLY wanted to know, here’s my command sequence.

#mkvextract tracks {input-file}.mkv 1:video.h264
#mkvextract tracks {input-file}.mkv 2:audio.ac3
#ffmpeg -i video.h264 -i audio.ac3 \
-vcodec copy \
-acodec libfaac -ab 320k -ac 6 \
-threads 0 -f mp4 \

Let’s break it down line by line so that you can modify it to your needs:
mkvextract tracks {input-file}.mkv 1:video.h264

Extract track 1 to “video.h264″

mkvextract tracks {input-file}.mkv 2:audio.ac3

Extract track 2 to “audio.ac3″

ffmpeg -i video.h264 -i audio.ac3

Input video.h264
Input audio.ac3

-vcodec copy

Copy the video track as is.

-acodec libfaac -ab 320k -ac 6

Transform audio track to AAC using libfaac
Set Audio Bitrate to 320k
Set Audio Channels to 6 (5.1)

-threads 0 -f mp4

Let ffmpeg decide how many threads to use
Set the container format to mp4


Output the file as specified

Checkout the ffmpeg documentation for more information about general options.

I donno about you, but I got tired of typing out three commands for every file I wanted to encode, plus all those options… forget about it!  So I wrote a stupid little shell script to do it for me.

You can download it here: ps3encode.  Just plop it somewhere in your filesystem and then make sure it’s included in your PATH variable and that it has execute permissions.


#ps3encode {input-file}.mkv {output-file}.mp4

Questions and comments welcome!

Be Sociable, Share!

· · ·

1 comment

  • Yunita · November 22, 2015 at 10:05 pm

    thanks for this, a neat solution. for any flolew mac users like me, it works great on a macbook too with a minor modification commenting out the make a static binary and qt-faststart lines. I also ran into a problem in that my ffmpeg doesn’t do aac encoding. However there is a command line utility afconvert on the mac for qt encoding which does the job. So I added an extra line after the MP4Box line:afconvert -f mp4f -b 256000 audio.wav audio.aacand then modified the ffmpeg line to use the file generated above rather than convert on the flyffmpeg -y -i tmp.mp4 -i audio.aac -acodec copy -vcodec copy “$OUT”


Leave a Reply



Theme Design by devolux.nh2.me