
Then we are running another sub command to generate the output file name. In the for loop this variable is called by ‘$file’. We are telling it to use the variable file in our for loop for each operation. The ‘| grep mkv’ is taking the output from the ls command and asking to filter out anything that doesn’t contain the string mkv. If there are other files in that directory then you might want to use $(ls | grep mkv). That list is a sub command, this is denoted by the $(), that is asking you computer ‘give me a list of all the files in the directory I am in’. In this case we are stepping through the items in the list $(ls). It will take in a list and step through each item in that list. To break that command down, the start is a for loop. You are going to spend a lot of time converting, especially if they are movies. I would suggest getting a device that can play those files though. That should work if your working directory is the one you have the video files in. For file in $(ls) do ffmpeg -i $file -f mp4 -vcodec h264 -acodec aac $(echo “$file” | sed ‘s/.mkv/.mp4/g’) done MacOS/Linux: for f in *.mkv do ffmpeg -i "$f" -c copy "$ \ All MKV files found in the directory will be converted with their original filename.

This can be run directly from command line. 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. Single file conversion example ffmpeg -i example.mkv -c copy example.mp4 If not just substitute with the full path to your ffmpeg binary. These examples assume ffmpeg is in your PATH.

Older examples may use -vcodec copy -acodec copy which does the same thing. With ffmpeg this can be achieved with -c copy. The main factor is disk read/write speed.

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 easiest way to "convert" MKV to MP4, is to copy the existing video and audio streams and place them into a new container.

Converting mkv to mp4 with ffmpeg Essentially just copy the existing video and audio stream as is into a new container, no funny business!
