Man Vs MKV

Edit: For the record, the steps below aren’t working yet.  I get a file with x264 video and aac audio which mplayer and movist will play back just fine, but iTunes won’t import it to send to the AppleTV and it’s mute when played on the PS3.  I’m still sorting out the kinks; I wanted to keep this post up so I can refer back to it but I also didn’t want it to cause problems for anyone finding this through Google.

I’ll start by saying that I really don’t have anything against the mkv container, it’s just a little inconvenient.

Hooked up to our TV right now, we have a PS3 (that can play back divx and mp4 files) and an AppleTV (which can play back .mp4, .m4v and .mov) files.  This is a big step forward from only a couple of years ago: companies are starting to accept that video file playback is important to consumers.

Problem is, a couple of years ago is when everything was distributed as divx video in an avi container.  Now it’s all .mkv and nothing we have hooked up to the TV knows what to do with an .mkv file.

So I’ve been looking at converting .mkv files to .m4v so I can import them into iTunes on the Mac Mini that feeds the AppleTV.

This isn’t actually that hard.  I use mencoder to move them from .mkv to x264 video and faac audio wrapped in an avi container, because mencoder seems to crash whenever I ask it to write anything that isn’t an avi file, and then I use ffmpeg to move them into a .m4v container.

I use -acodec=copy and -vcodec=copy on this second step, so there’s no transcoding required and no more loss of quality.

This breaks down if the .mkv file includes soft subtitles, which is most fansubbed anime.  Mencoder CAN burn subtitles into its output file, but doesn’t know how to handle ass/ssa style subtitles, so you get plain white subtitles with no formatting.

This is a pain.

I did, however, come up with a workaround.  Not a good workaround, but at least a starting point.

See, first I take the .mkv file and play it in Mplayer with the -vo yuv4mpeg and -ao pcm options.  This tells Mplayer (which knows how to handle ass/ssa style subtitles) to render every frame of video to a YUV stream file and dump the audio to a .WAV file.

FYI, the YUV stream file for a single 22 minute episode is 47 GB.  As in, forty-seven gigabytes.

THEN I take Mencoder and hand it the YUV file, hand it the WAV file, and tell it to make me a .x264 / faac encoded .avi file out of them, which I can then convert using ffmpeg.

It’s not exactly the most direct solution, and I haven’t worked all the kinks out, but if I can figure out how to get it humming along smoothly and then automate it, I’ll have solved all my pesky .mkv problems.  That’ll be good.

This entry was posted in organization. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.