mkv2m4v Gem Version Code Climate

Converts audio and video tracks from a MKV (Matroska Media) container into a format compatible with Apple TVs.

It attempts to pass through as many codecs as possible.

  • It assumes that the video track is already in H.264/MPEG-4 (Advanced Video Codec).
  • It will convert a DTS audio track into separate AAC and AC3 tracks.
  • If no DTS, it will pass through the original AAC and/or AC3 tracks.

How You Can Help

Gratipay Bitcoin Book a Codementor session

If you like this project, donate via Gratipay, buy me a coffee with Bitcoin 1rmm5tv6f997JK5bLcGbRCZyVjZUPkQ2m, or book a session with me on Codementor.


mkv2m4v is dependent upon mediainfo, ffmpeg, mkvextract, and MP4Box.

$ brew install mediainfo
$ brew install ffmpeg --with-tools --with-fdk-aac
$ brew install gpac
$ brew install mkvtoolnix # version >= 6 required
$ gem install mkv2m4v

Note: gpac includes MP4Box:

If you have any trouble after installing the mkdv2m4v gem, you can test the dependencies using the --check argument:

$ mkv2m4v --check


$ mkv2m4v some-video.mkv


I got fed up with the reliability of the conversion tools out there for converting MKV video containers to Apple TV compatible videos. Many of the existing tools appear to have potential on the surface, but they fail under certain scenarios.

Handbrake is still the most realiable existing tool out there, but it re-encodes h.264 video tracks, which is not ideal and very slow.

The goal is to get a better, more automated tool to accomplish the task of generating Apple TV compatible videos. Nothing more. It should generate an M4V media file with the best possible quality given the original source and the defaults should require no additional human interaction.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request