(Re)encoding video under Linux to stream to a PS3

I’ve recently moved to storing my video collection on my home server as a series of .mp4 files, and streaming them (with Mediatomb) to my PS3, which displays them on my TV. This means I can watch any of my DVD’s without having to find the disc, which is very convenient.

However, I started digitising many years ago, so my collection contains a few older “.avi” files that contain video in early Divx and Xvid formats. Normally these “.avi” files can be streamed directly to the PS3 too, but sometimes the PS3 complains of Unsupported data, error 800288bf, or Corrupted data. I’ve failed to discover exactly what causes these problems, but they’re clearly related to the combination of the codecs used for the audio and video streams and the use of the avi container.

To resolve this, I simply convert (re-encode) these unsupported “.avi” videos into the newer more standards-based .mp4 format. This approach will work equally well for video in the many other formats that the PS3 doesn’t understand. To do this, I use ffmpeg, which is the swiss army knife of video & audio conversion for Linux.

If you intend to replicate this, you need to use a recent and full version of ffmpeg; the version in the standard Ubuntu repositories isn’t sufficient, as it doesn’t include support for patent-encumbered codecs, which you will need. Instead, you can get the version you need from the Medibuntu repository.

First find out what bitrates your existing video is using for it’s video and audio streams. Enter “ffmpeg -i video.avi”. Output will be something like:

richard@t60p:~/Data$ ffmpeg -i video.avi
FFmpeg version SVN-r19352-4:0.5+svn20090706-2ubuntu2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: –extra-version=4:0.5+svn20090706-2ubuntu2 –prefix=/usr –enable-avfilter –enable-avfilter-lavf –enable-vdpau –enable-bzlib –enable-libgsm –enable-libschroedinger –enable-libspeex –enable-libtheora –enable-libvorbis –enable-pthreads –enable-zlib –disable-stripping –disable-vhook –enable-gpl –enable-postproc –enable-swscale –enable-x11grab –enable-libdc1394 –extra-cflags=-I/build/buildd/ffmpeg-0.5+svn20090706/debian/include –enable-shared –disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Oct 13 2009 22:15:16, gcc: 4.4.1
Input #0, avi, from ‘video.avi’:
Duration: 01:24:57.64, start: 0.000000, bitrate: 2281 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720×304 [PAR 1:1 DAR 45:19], 25 tbr, 25 tbn, 25 tbc
Stream #0.1: Audio: mp3, 44100 Hz, stereo, s16, 192 kb/s
At least one output file must be specified

I’ve highlighted the interesting parts; the average bitrate for the whole file, and the average bitrate of the audio stream. Take one from the other and you have the average bitrate for the video stream.

Now we need to re-encode the video into a format the PS3 likes. We’ll use H.264 video, AAC audio, in an MP4 container, which the PS3 supports well. I’ve just reused the same bitrates as the input file, but in practice you can probably reduce both a little without affecting quality, as H264 and AAC encoding is more efficient than older encoders:

ffmpeg -i video.avi -vcodec libx264 -sameq -b 2089k -acodec libfaac -ab 192k -t “00:05:00” video.mp4

Notes

  • -sameq keeps video quality the same
  • -b 2089k specifies the output video bitrate
  • -ab 192k specifies the output audio bitrate
  • -t “00:05:00” optionally produces only 5 minutes of output – ideal for testing your settings before you convert a long video
  • Encoding time on my dual core laptop is about 1 second for each second of video. So expect a long wait.
Advertisements

3 thoughts on “(Re)encoding video under Linux to stream to a PS3

  1. Pingback: Digitising DVD’s with Linux to stream to PS3 « Richard's Blog

  2. Pingback: 2010 in review « Richard's Blog

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