Convert video files using FFMPEG in Linux

Convert MKV to MP4

ffmpeg -i video_file.mkv output_file.mp4

If you only want to convert MKV to MP4 then you will save quality and a lot of time by just changing the containers. Both of these are just wrappers over the same content so the CPU only needs to do a little work. Don’t re encode as you will definitely lose quality.

It’s very straight forward using ffmpeg:

ffmpeg -i LostInTranslation.mkv -codec copy LostInTranslation.mp4

Here, you are copying the video codec and audio codec so nothing is being encoded.

To convert all MKV files in the current directory, run a simple loop in terminal:

for i in *.mkv; do
    ffmpeg -i "$i" -codec copy "${i%.*}.mp4"
done

Note: If you get an error like this:

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

use

for i in *.mkv; do
ffmpeg
-i "$i" -codec copy -strict -2 "${i%.*}.mp4" done

 

Convert MP4 to AVI

In order to just copy the video and audio bitstream, thus without quality loss:

ffmpeg -i filename.mkv -c:v copy -c:a copy output.avi

If you want FFmpeg to convert video and audio automatically:

ffmpeg -i filename.mkv output.avi

Leave a Reply