Convert video with subtitles to MP4 for iPhone/iPad (preliminary notes)
Wednesday, 17 August 2011
By now, we know of a few requirements for viewing video on iOS (iPhone/iPad et al.). The video codec should be H.264 or another “standard” MPEG codec, and the audio should be AAC. AC3, as far as I know, is not supported. That’s all fine and dandy, but subtitles have been one of the trickiest things to get working on iOS.
The video should be in an MP4 container, and it’s relatively easy to remux from anything to MP4 in one step using ffmpeg, avidemux, mencoder, and so on. Any unsupported audio should be transcoded into AAC into the process, but remuxing itself should only take a few seconds.
Subtitles need to be extracted with whatever tool you have at your disposal. Mkvextract is the way to go with MKV, but SSA/ASS subs are not supported (if that wasn’t assumed already). There is a script ass2srt.pl that will handle the conversion for you, and iOS can understand ttxt subtitles in addition to srt. MP4Box can convert srt to ttxt and vice-versa, and maybe a couple other formats.
The tricky part is getting all the bits right. Use MP4Box to add the subtitles to the mp4 with something like
MP4Box -add mysubs.srt:hdlr=sbtl:lang=eng myvideo.mp4. However, if MP4Box says it can’t understand the URL even though you’ve typed it correctly, it could be that your MP4Box version is too old to be able to set the “hdlr” field to “sbtl”. If so, run it with just
-add mysubs.srt:lang=eng and then use sed to replace “text” with “sbtl”.
Finally, rename your video file to use the “.m4v” extension instead of “.mp4″ (ugh, really?).
If all goes well, you should see a new subtitle selector pop up next to the play controls when you play the video full-screen on your iDevice.