Converting MKV files to MP4 with FFMPEG

If you want to watch downloaded movies on your TV instead of on your computer you need to either buy new hardware or convert the movies into a file format that works on your media player. Today I decided to see how easy this was to do.

Why do this? While Blu-rays, for example, play on most computers, few people want to sit and watch the film on the computer. So converting it from a MKV format (after “ripping” the Blu-Ray) to MP4 allows you to pop it on a set-top box (often via USB drive) and watch from your sofa.

The software tested was Ffmpeg. They do a version for us Windows users. It is just a matter of downloading it, decompressing the file and then opening it. No install required.

You can get it here: https://www.ffmpeg.org/download.html for Linux and OSX, or here http://ffmpeg.zeranoe.com/builds/ for Windows.

I downloaded the 32-bit static builds (which gave ffmpeg-latest-win32-static.7z) and unpackaged them with 7-Zip (which gave a folder called ffmpeg-20140702-git-42a92a2-win32-static).

Then I opened the folder and double clicked the ff-prompt and this opened a command prompt for Ffmpeg.

Attempt 1

The most basic way to convert a file is to input a command such as this:

ffmpeg -i whatever.mkv whatever.mp4

However, this did not work for me. The file gave an error on my Sony box. It did work on VLC player I think (cannot confirm as I have deleted it).

Attempt 2

This worked, but poor quality (should be OK for ipads and other tablets):

ffmpeg -i input.mkv -acodec aac -ac 2 -strict experimental -ab 160k -s 1920×1080 -vcodec copy -f mp4 -threads 0 output.mp4

What settings to use?

I was scratching my head over the settings and my pal suggested looking at the properties of a file that does work and look good. One movie had these properties:

Video: Frame width 1920, height 800, data rate 1955kbps, total bitrate 2049lbps, frame rate 23 fps. Audio: dit rate: 93 kbps, channels 2 (stereo), audio sample rate 48 khz ……..

Attempt 3

I used some of the above ideas but this new one resulted in blotchy,  pixellated images at some points in the video (it was not bad, might have been OK on a small screen):

>ffmpeg -i S01.Ep03.mkv -acodec aac -ac 2 -strict experimental -ab 160k -s 1920×800 -vcodec copy -f mp4 -threads 0 S01.Ep03.mp4

>ffmpeg -i S01.Ep03.mkv -acodec aac -strict -2 -ab 160k -s 1024×768 -vcodec copy -f mp4 S01.Ep03.mp4

Attempt 4

Because the sound was good but the video poor, I Googled this issues and discovered the qscale setting. Qscale determines the quality of the video. I assume that unless you specify it some other method of compression is used and that over-eggs the video, making it pixellated.

ffmpeg -i S01.Ep03.mkv -acodec aac -strict -2 -ab 160k -s 1920×1080 -qscale:v 3 -f mp4 S01.Ep03.mp4

It took much longer to process and worked OK on PC.

What does this mean?

I only learned today, and admit that I am still a bit confused. But, this is how I understand it…..

  • ffmpeg – means use the ffmped program
  • -i S01.Ep03.mkv – specifies the file that is to be converted
  • -acodec aac -strict -2 -ab 160k – This is the sound conversion. Means use the AAC codec. Not so sure about the other stuff, bit rates, did not really understand what the strict bit does. But it worked.
  • -s 1920×1080 – This sets the resolution of the new file. This ended up being larger than the resolution of my tele, because I think I needed to keep the aspect ratio the same. My tele has a height of 1024 pixels (same width) so I went with a number close to that for the smallest pixel dimension (sorry about bad jargon!)
  • -qscale:v 3 – this is the bees knees. Adding this improved the quality of the image. Qscale works from 1 to about 40, where 1 is top quality and 40 is crap. I might try one with 4 or 5 to see how that goes, but unless you are converting loads it does not really matter. Smaller numbers mean larger file sizes, but 1.5Gb is pretty reasonable.
  • -f mp4 S01.Ep03.mp4 – this sets the destination (new) file.

Result!

Just watched the start of a movie that I converted from the MKV format (original file was about 6Gb) and it looked and sounded great. No pixellation, no blurryness, blotchiness or distorted images at all. What’s more, the resulting MP4 file in only 1.5 Gb.

Sound is Dolby Prologic instead of surround sound, but considering this allows me to watch ripped Blu-rays on my TV media centre it is well worth it.

Yesterday I thought I was going to either have to make do with a laptop connected to my television, or possibly purchase a new TV media player that supports MKV files, or God forbid, buy another cheap Blu-ray player that hums whenever a disc is spun.

But, at zero cost, I converted the files in the a usable format.

Ffmpeg in action

Pretty exciting huh?

ffmpeg in action

ffmpeg in action

 

  1 comment for “Converting MKV files to MP4 with FFMPEG

  1. Dani
    June 19, 2017 at 8:19 pm

    Thanks … Works perfect for me 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *