Site icon Bytefreaks.net

ffmpeg to convert MP4 files to MKV files with the libx265 video codec

Advertisements

When working with video files, there are times when you need to convert them from one format to another or modify them in some other way. One of the most popular tools for this is ffmpeg. This command-line tool can do a lot of things related to video processing, including conversion, resizing, cropping, and more. In this blog post, we will explain a script that uses ffmpeg to convert MP4 files to MKV files with the libx265 video codec.

The Script:

Here’s the script that we will be explaining:

for FILE in *.mp4; do
  echo -e "Processing video '\e[32m$FILE\e[0m'";
  ffmpeg -i "${FILE}" -analyzeduration 2147483647 -probesize 2147483647 -c:v libx265 -an -x265-params crf=0 "${FILE%.mp4}.mkv";
done;

Let’s break this script down line by line to understand what it does.

for FILE in *.mp4; do
...
done;

This line starts a loop that goes through all the files in the current directory that have the “.mp4” extension. The loop will execute the commands inside the “do” and “done” keywords for each file that matches this pattern.

echo -e "Processing video '\e[32m$FILE\e[0m'";

This line uses the “echo” command to print a message to the console. The message includes the file’s name being processed, which is stored in the $FILE variable. The “\e[32m” and “\e[0m” are escape sequences that change the color of the text to green. This is just a way to make the message more visually appealing.

ffmpeg -i "${FILE}" -analyzeduration 2147483647 -probesize 2147483647 -c:v libx265 -an -x265-params crf=0 "${FILE%.mp4}.mkv";

This line runs the ffmpeg command to convert the current file from MP4 to MKV format using the libx265 video codec. Let’s break down each of the options:

Conclusion:

The script we’ve just explained is a simple example of how you can use ffmpeg to convert MP4 files to MKV files with the libx265 video codec. It uses a loop to process all the files in the current directory that match the “.mp4” pattern. The script also prints a message to the console for each file

This post is also available in: Greek

Exit mobile version