Ubuntu – How to convert .mkv file into .mp4 file losslessly

.mp4avidemuxffmpegmkvvideo conversion

I need to convert a video file from Matroska container into mp4 container. Matroska file contains one h.264 video track and one AC3 sound track. It should be possible to do this losslessly, but how to do it with native Ubuntu tools?

Transcoding is not an option.

Best Answer

Perhaps the easiest tool for that is ffmpeg, or avconv from the libav-tools package. Libav is a fork of FFmpeg, which Ubuntu switched to for a few years until Ubuntu 15.04. It is one of the backends for many of the GUI tools mentioned in other answers.

Changing container without re-enconding content could not be simpler:

ffmpeg -i input.mkv -codec copy output.mp4
  • It auto-detects a Matroska to MP4 container conversion based on input/output filenames.

  • -codec copy stream copies, or "re-muxes", the streams from the input to the output without re-encoding. Think of it like a copy and paste.

  • Default stream selection behavior is to select only one stream per stream type. For example, if your input has two video streams and one audio stream then only the video stream with the largest frame size will be selected. Add -map 0 if you want to select all streams from the input.

  • Some containers may not support some formats. So check if your chosen container format, be it mkv, mp4 or even avi has support for all the content in your files (video, audio, subtitles, data, etc). For example, mp4 does not support SubRip subtitles (.srt files).