From Matroska to MP4

Problem

Transform the container from Matroska to MP4.

Solution

ffmpeg \
    -i input_file.mkv \
    -c:v copy \
    -c:a aac \
    output_file.mp4

Command syntax

ffmpeg
starts the command
-i input_file.mkv
path, name and extension of the input file
-c:v copy
re-encodes the video stream using the same video codec
-c:a aac
re-encodes the audio stream using the AAC audio codec
output_file.mp4
path, name and extension of the output file

Discussion

The extension for the Matroska container is .mkv.

The video codec is specified by -codec:video, which may be abbreviated as -c:v (or -codec:v or -c:video). We advise to avoid the alias -vcodec.

The audio codec is specified by -codec:audio, which may be abbreviated as -c:a (or -codec:a or -c:audio). We advise to avoid the alias -acodec. As sadly MP4 cannot contain sound encoded by a PCM (Pulse-Code Modulation) audio codec, we use AAC (Advanced Audio Coding): aac is FFmpeg’s native AAC encoder. For silent videos you can replace -c:a aac by -an.

The extension for the MP4 container is .mp4.


2018–05–21