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.
Thank you so much!!
After upgrading my LG TV, come to find out that while the new one certainly has a nicer picture, it no longer supports DTS! :(
After manually converting the DTS to AAC and being disappointed, then trying again from source into AC3, I just still couldn't live with the lossy to lossy results. I found the special effects were still pretty superb, but surprisingly the speech was a bit muffled (to my ears at least). After trying and failing to convert back from source to truehd (VLC wouldn't even play it), I discovered that LG TV supports FLAC from inside an MP4 container, yas! Sure I could have used mkv but I like mp4 better because most of my other videos (already aac/ac3) are mp4 and I'm ocd I guess. Granted the file size will go up, but going lossy to lossy just wasn't bringing me joy, and isn't that the point? But main thing as well was I was hating my life thinking about opening all those powershell windows and converting the videos one by one again (about 300-400 videos). This worked like a charm!! If anyone is interested, this modified line will copy the video and transcode just the audio to lossless flac. Or if interested in a different format just change the flac part to aac, ac3, mp3 etc etc. Thanks again, I doubt I would have been able to summon this (cheat)code on my own! Just filled in your script with what I needed. The "-strict -2" part is because flac to mp4 container is "experimental" but tested working fine on LG TV from usb input. On any non-tested device would probably recommend sticking with mkv for flac audio. Windows 10/PowerShell:
Get-ChildItem -Filter '*.mkv' | % { &.\ffmpeg -i .$($.BaseName).mkv -acodec flac -vcodec copy -strict -2 .$($.BaseName).mp4 }