Friday, November 28, 2014

Lossless MKV to MP4 (thanks, ffmpeg)

Update

The following all still applies and is sound advice, but you can perform a simple container switch (I think the technical term is demux and remux) or lossless conversion (no re-encode) using VLC, which is pretty common among people who want to view media. I won't re-invent the wheel, and you can google "mkv to mp4 vlc" to see videos on how to do this, but you are basically opening VLC and choosing file>convert/save, then picking the source file (mkv) and clicking convert/save, then select the 'tools' by the profile dropdown and set 'encapsulation' to mp4/mov, and audio and video to 'keep original.' Then just click save and set your destination file and do it.

Keep in mind that mp4 files are, arguably, a little more well received as apple devices can play them and they are a little more friendly for web streaming. That said, I prefer the mkv container as it allows multiple subtitle tracks and allows various codecs such as . The mp4 container, I believe, is only supposed to work with older mpeg or avc/h.264 encoded video and AAC encoded audio.

And soon enough we can re-visit with HEVC/VP9/Daala thoughts...

A long time ago, I wanted to "extract" my video and audio from a mkv and put them into a html5 video friendly .ogv file/container. I wrote about it here.

This is a little more of an update to that post than a new idea, but I was dissapointed at the search results when I googled "lossless mkv to mp4" and hope this may be of some assistance. It probably won't. Here's hope.

It really isn't bad. If you want to be thorough, install MediaInfo and verify the audio code and video codec are compatible. I'm not sure what mp4 accepts, but AVC/h.264 for video and aac for audio seem to be the most common codecs. Technically, you could copy the video and recode the audio if that was needed for your situation. The code would need little modification.

Install ffmpeg. Get the package for your OS (i'm using Windows), then extract it. It doesn't have to install, so pay attention to where you extract to.

Next, open cmd (search from the start-menu search) and browse to where you extracted ffmpeg. Try using 'tab' to auto complete from cmd. It saves tons of time. Tab multiple times to cycle through potential completions.

Type the following, using the video (full location input and output --fun, I know!) for input.mkv and the name you want as output.mp4: C:\videdit\ffmpeg\bin>ffmpeg -i c:\Users\nchapman\Videos\christianeatingwackyburger.mkv -codec copy c:\Users\nchapman\Videos\newchristianeatingwackyburger.mp4

Hope this helps! You can use -acodec mp3 -vcodec copy or something crazy if you prefer.

Also, you can encode all files in a directory by saving this to a .bat file (then, drag a .mkv file onto it):
for %%a in ("*.mkv") do ffmpeg.exe -i "%%a" -vcodec copy -acodec copy "%%~na .mp4" pause

Source (last comment)

No comments: