This question already has an answer here:

I simply want to convert files, any format to any format (at the moment, I need to convert MKV to MP4-h264), without losing quality. I don't want to resize (scale) the video, I don't want to change its aspect ratio and I don't want it to lose quality (this is very important); all I want is "to change the format", that's all. Reason: my DVD player won't recognize any formats other than AVI or MP4. I don't care about file size, unless the difference between the input and the output files is absurdly huge. So, how do I do that?

I've already tried programs such as WinFF, Arista, Format Junkie, but their presets always change something which I don't want to be changed (size, aspec ratio, etc.). I'm not really sure, but I think the best way to get what I want is to go with the pure ffmpeg commands. But how?

By the way, Ubuntu 13.04 (64-bit), here. Thanks for your time, guys.

marked as duplicate by djeikyb, kiri, don.joey, Jorge Castro, karel Dec 30 '13 at 5:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It seems to be interesting, vivid_vibe. I'll give it a try. Let's see what it can do. Thanks. :) – user229552 Dec 28 '13 at 17:42
  • Dumindu Mahawela, I followed the link you provided and came across this command: "avconv -i input.mkv -codec copy output.mp4". This worked like a charm for me. Thanks for your time. :) – user229552 Dec 28 '13 at 18:46
  • Post it as a answer here. – user224082 Dec 29 '13 at 3:58

If you only want to convert MKV to MP4 then you will save quality and a lot of time by just changing the containers. Both of these are just wrappers over the same content so the CPU only needs to do a little work. Don't re encode as you will definitely lose quality.

It's very straight forward using ffmpeg:

ffmpeg -i LostInTranslation.mkv -codec copy LostInTranslation.mp4

Here, you are copying the video codec and audio codec so nothing is being encoded.

Tip: To convert all MKV files in the current directory, run a simple loop in terminal:

for i in *.mkv; do
    ffmpeg -i "$i" -codec copy "${i%.*}.mp4"

For future conversions, like from AVI to MP4, check out HandBrake.

  • Sayem, I tried your suggestion, but got this result: "[mp4 @ 0x134da20] Application provided invalid, non monotonically increasing dts to muxer in stream 0: -2 >= -2 av_interleaved_write_frame(): Invalid argument". Anyway, I've got what I want with the following command: "avconv -i input.mkv -codec copy output.mp4" which is pretty similar to the one you suggested. Thanks a lot for your time. :) – user229552 Dec 28 '13 at 18:45
  • That for-loop dies when there are spaces in the file names ;-; – EaterOfCode Sep 26 '14 at 10:54
  • 7
    Replace $i by "$i"in the loop and it will work with filenames with spaces. – Xavier Nov 30 '14 at 4:18
  • 2
    Don't parse ls output, just for i in *.mkv; do ...;done. mywiki.wooledge.org/ParsingLs. Also, you could do "${i%.mkv}.mp4" to strip off the string ".mkv" before tacking on .mp4. – Peter Cordes Jan 15 '15 at 2:42
  • 2
    And don't forget -movflags +faststart because mp4 sucks; without that, you can't play a partial file (where the end of the file isn't written yet). – Peter Cordes Jan 15 '15 at 2:44

Here is one you haven't tried. Handbrake

  • TheHerk, I couldn't install it. Added PPA, updated sources, tried to install "handbrake" package, but it says there's no such package to be installed. Go figure! – user229552 Dec 28 '13 at 19:36
  • 2
    Never mind, TheHerk. I found the correct name of the package: handbrake-gtk. Installed it, but didn't like it. But thanks anyway. :) – user229552 Dec 28 '13 at 20:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.