PS3 and Matroska with subtitles

Suppose you have a video file with subtitles, in the Matroska format.  How to play it on a PS3?  Probably set up mediatomb or ps3mediaserver and… I’ve made a number of attempts, and each had certain problems.  Here’s the list of ideas I had:

  • Try to just play .mkv with PS3
    …won’t work because PS3 doesn’t support Matroska.
  • Use ps3mediaserver to recode .mkv on the fly
    …won’t work because ps3mediaserver doesn’t hardsub (doesn’t embed the subtitles in the image).
  • Use mencoder to create an .avi file with embedded subtitles (using mpeg4 for video and mp3 for audio)
    …in theory should work, but my PS3 said it’s an “unsupported format”, no idea why.
  • Use mencoder to create an .mp4 file with embedded subtitles
    …doesn’t work, because mencoder’s mp4 support is broken, causing audio and video to go out of sync.
  • Use mencoder to create an .avi file with embedded subtitles (using mpeg4 for video and mp3 for audio), and use ffmpeg to convert it (without recoding) into MP4
    …doesn’t work, because PS3 won’t play an .mp4 with mp3 audio
  • Use mencoder to create an .avi file with AAC audio (using faac), and use ffmpeg to convert it to MP4
    …does work if you pass -faacopts mpeg=4:raw=1 options to mencoder, but there’s still a problem with a/v going out of sync
  • Add the -mc 0 option
    …fixes the a/v sync problem in most cases, but there’s still the problem with the video being crap quality
  • Use x264 to encode video
    …gives the best results:

I’ve also searched the web to look for encoder options and I came up with the following recipe.  It requires mencoder with x64 and faac support, and ffmpeg.  The following example uses Japanese audio track and English subtitles.  It leaves the intermediate .avi file. The first steps are to set the file names and recode the video and audio content, saving it in an .avi file.

infile=your-source-file.mkv
outfile=your-source-file-good-for-ps3
mencoder -o "${outfile}.avi" \
   -oac faac \
   -faacopts raw=1:mpeg=4 \
   -ovc x264 \
   -x264encopts bitrate=3000:pass=1:threads=auto \
   -mc 0 \
   -vf pullup,softskip,harddup \
   -alang jpn \
   -slang eng \
   "${infile}"

Repeat that with pass=2. After the second pass has completed, it’s time to move the encoded content from the AVI container to the MP4 container.

ffmpeg \
   -acodec copy \
   -vcodec copy \
   -i "${outfile}.avi" \
   "${outfile}.mp4"

The resulting MP4 file should be playable on PS3. This example doesn’t contain any further automation. I’m leaving it to you. Other possible improvement include skipping the audio recoding, if audio is in AAC already.  There’s also a lot of potential for tweaking the x264 options for better video quality. I’ve decided to leave these out for now to keep the example as simple as possible.

Please leave a comment whether it worked for you or not; suggestions for updates and improvements are also appreciated.

References: