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.
Exactly; that was my main issue, since I started using the far-too simple command
ffmpeg -i video.mkv -c copy video.mp4
having no prior knowledge opus was involved in my original file.... And when I looked on the ffmpeg website in documentation, there's "OPUS", then "libopus" which talks about needing "to explicitly configure the build with --enable-libopus" then goes on to state "Most libopus options are modeled after the opusenc utility from opus-tools" and gets more convoluted from there. Simply breaking out the codecs as you did in your command/code just solved the issue, full stop:-vcodec -copy -acodec -aac
- It worked from then on out, no errors, no issue, no loss of quality, nor file size, and I've used that command on I think 48 videos over the last week. URL For reference: https://ffmpeg.org/ffmpeg-codecs.html#opusSometimes I get so far into trying to solve a specific error message &/or figure something out, I'm not able to realize the simplest answer was staring me in the face the entire time.... Basically a textbook "unable to see the forest through the tress" scenario, lol.
Anyway, thanks again Jan02 - I'm new(er) on githib so hopefully I'm not breaking any rules with this conversational type of reply. I just figured it was worth elaborating on how & why this solved my issue, after you replied & mentioned the OPUS portion of my error message. Also thanks to @talesam for the script!
Cheers.