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 is usually abbreviated as -c:v (-codec:v or -c:video are also possible). We advise to avoid the alias -vcodec.

The audio codec is specified by -codec:audio, which is usually abbreviated as -c:a (-codec:a or -c:audio are also possible). 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.


2020-07-15