I have found that a lot of Linux utilities use the MKV (Matroska multimedia container) as a default container for video. However, a lot of other tools (Adobe Premiere Pro) do not support MKV files. In this Linux quick tip we will show you how to convert MKV to MP4 container.
Before you can convert (or remux) an MKV file to an MP4 file, you must first install ffmpeg.
Using ffmpeg to Remux MKV to MP4
FFmpeg is a very powerful suite of video tools. However, there are very few options needed to change containers. Invoke ffmpeg then use the -i
option to specify the input file. Then used the -codec copy
option to instruct ffmpeg to use the same codec, followed the the name of the output file.
Here is an example using a intro we made for our YouTube videos.
savona@putor Videos]$ ffmpeg -i intro.mkv -codec copy intro.mp4
Convert All Files in a Directory from MKV to MP4
If you use something like OBS Studio to create a bunch of videos and want to convert them all, simply use a loop. The code below will loop through all the files in the current directory and convert MKV to MP4 files.
for i in *.mkv; do
ffmpeg -i "$i" -codec copy "${i%.*}.mp4"
done
Conclusion
FFmpeg makes it easy to remux video files from MKV to MP4. Since you are no encoding anything it is often instantaneous. Unless or until the MKV format is more widely used, this is a blessing.
Remux - Copy the file from one container to another (MKV to MP4) without re-encoding. This simply changes the container which delivers the video without making any actual changes to the video content itself.
Encoding - This is the converting of the actual video and audio from one format specification to another.
The above may be an oversimplified explanation of remux vs encode. However, this is beyond the scope of this quick tip.
Resources and Links
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
6 Comments
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
- Uncategorized (1)
Thanks, this was handy.
Does not work:
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature
you have to install third party codecs. this might solve your problem:
sudo apt-get install libavcodec-extra
Muchas gracias, pude convertir 10 películas de una sola vez gracias a ti :3
works perfectly..thanks..linux is so powerful i love it
Oh man - I had never seen the "${i%.*}.mp4" construct before - wish I had seen it 20 years ago... Thanks much for this short and sweet tutorial.