Log in

View Full Version : Convert .mkv to .mp4 with FFmpeg, how?


phabian
18th February 2014, 00:49
I've got some .mkv videos that (according to MediaInfo) contain these formats: Video = VC-1, Audio = WMA.

The videos play fine on my Windows machine, but I want to convert them so they can be played on my Android phone as well.

Usually I can convert one container format to another by just copying the streams, like this:

FFmpeg -i input.wmv -vcodec copy -acodec copy output.mp4

This doesn't seem to work for files with VC-1 / WMA content: it says "track 1: could not find tag, codec not currently supported in container".

I guessed track 1 is the sound, so I kept the -vcodec copy and used "-acodec aac", that didn't work either: "Codec is experimental but experimental codecs are not enabled, see -strict -2".
Instead, I tried "-acodec libvorbis" and that seemed to work, but it still can't be played on my Android phone.

I assume I have to transcode the video stream as well. But I have no idea what to fill in there, or what encoding params to specify (or even how to specify them). The aac and libvorbis for audio were more or less guesses (after looking through the help).

What command line should I use to convert input.mkv to output.mp4 so that the output file uses some more compatible audio & video formats? For example, x264 for video and mp3 or aac for audio?

Thanks!

manolito
18th February 2014, 02:58
Try something like this:

FFmpeg -i input.wmv -crf 20.0 -vcodec libx264 -acodec libvo_aacenc -ar 48000 -b:a 128k output.mp4

Change the video CRF value and the audio bitrate according to your needs.

If you are not fixated on using ffmpeg, MkvToMp4 by Oreons is an excellent alternative.


Cheers
manolito

phabian
19th February 2014, 12:57
Awesome, thank you very much sir! :)

Just for my understanding, is there a description somewhere of these parameters and their values?

From what I've read, the -crf 20.0 thing is a quality parameter. What does 20 mean, is that better than 10 or 30? And could I also specify something like "same quality as input"? (well, that's hard to do when transcoding, but I mean roughly the same average bitrate or something)

smok3
19th February 2014, 14:32
x264 --fullhelp
or
http://mewiki.project357.com/wiki/X264_Settings

Mole
27th February 2014, 11:46
-crf 20.0 is about recommended optimum for quality vs file size.
Using lower crf such as 19.0-16.0 will produce higher quality, but also higher file size.
The x264 docs don't recommend using any lower number than 16.0 because you'll only get bigger file size, but not really noticeable improvement in quality.
The difference is only measurable with tools such as PSNR, but when you actually watch it, you won't see any difference because they're so minuscule.

If file size isn't an issue for you, then you could use crf=16. This will more or less equal "same quality as input".