Essentially just copy the existing video and audio stream as is into a new container, no funny business!
The easiest way to "convert" MKV to MP4, is to copy the existing video and audio streams and place them into a new container. This avoids any encoding task and hence no quality will be lost, it is also a fairly quick process and requires very little CPU power. The main factor is disk read/write speed.
With ffmpeg
this can be achieved with -c copy
. Older examples may use -vcodec copy -acodec copy
which does the same thing.
These examples assume ffmpeg
is in your PATH
. If not just substitute with the full path to your ffmpeg binary.
ffmpeg -i example.mkv -c copy example.mp4
If you want to batch convert multiple MKV files, you can switch into the directory that contains MKV files and run the following, depending on OS. This can be run directly from command line. All MKV files found in the directory will be converted with their original filename.
for f in *.mkv; do ffmpeg -i "$f" -c copy "${f%.mkv}.mp4"; done
for /R %f IN (*.mkv) DO ffmpeg -i "%f" -c copy "%~nf.mp4"
/R
is used to recursively search within sub directories at the target location.
If running within a batch script, you will need to double the percentage signs %%
in order for the command to run properly.
In both examples, the original .mkv extension is removed from the final output to avoid the filename ending up as example.mkv.mp4
which would be a bit weird, although harmless.
THANKS to @Jan02 - I'm on MacOS Catalina 10.15.4 (19E287) using BASH in the MacOS Terminal. This command structure worked for me right away!
To elaborate - I was getting an error when using the more vanilla command of: ffmpeg -i video-title.mkv -c copy video-title.mp4
Pertinent ERROR OUTPUT:
[mp4 @ 0x7fda2f008200] track 1: codec frame size is not set [mp4 @ 0x7fda2f008200] opus in MP4 support is experimental, add '-strict -2' if you want to use it. Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy)
That's what led me here. I read through most of the replies here, and based on my decent knowledge of coding, scripting, and command line work in Linux & MacOS, I chose to go with your suggested commands. As I said, it worked perfectly the first time. Thanks!