Convert Clip to HEVC (H.265) Video with FFmpeg: Tech Support Guide
In this comprehensive guide, we will walk you through the process of converting a video clip to HEVC (H.265) format using FFmpeg, a powerful and highly versatile open-source multimedia framework. The HEVC codec is an advanced standard for video compression, providing higher quality video and lower file sizes compared to its predecessor, the H.264 codec. Let's dive in!
What is HEVC (H.265)?
HEVC (High Efficiency Video Coding) or H.265 is a video compression standard that offers several advantages over its predecessor, the H.264 codec. HEVC provides better compression efficiency, which, in turn, results in smaller file sizes and higher video quality. HEVC has gained popularity in various video applications, including streaming services and 4K Ultra HD Blu-ray discs.
FFmpeg: A Brief Introduction
FFmpeg is a free and open-source multimedia framework that can handle a wide range of multimedia formats, allowing you to record, convert, and stream audio and video. FFmpeg is highly versatile, with a command-line interface that supports a large number of options for customization. The framework consists of several components: the FFmpeg command-line tool, FFplay, for multimedia player, and FFprobe, for analyzing media files.
HEVC Encoding with FFmpeg
To encode a video clip using the HEVC codec, we can leverage the FFmpeg command-line tool. The basic syntax for FFmpeg encoding involves the ffmpeg command followed by input and output file specifications. Let's take a look at the essential components of the FFmpeg command for HEVC encoding:
-c:the codec flag for specifying the codec to be used for encoding/decoding-crf:the constant rate factor for defining the quality of the encoded video. A lower value corresponds to higher video quality and larger file size, while a higher value implies lower video quality and smaller file size.-preset:the preset for optimizing the encoding process. A slower preset (e.g.,slow) results in higher quality and larger file size, while a faster preset (e.g.,ultrafast) leads to lower quality and smaller file size.
Example FFmpeg Command for HEVC Encoding
The following FFmpeg command converts a video clip called input.mp4 to HEVC (H.265) format with a constant rate factor (CRF) of 23 (medium quality) and a slower preset (slow) for better quality:
ffmpeg -i input.mp4 -c:v hevc -crf 23 -preset slow output.mp4
This command encodes the input file, input.mp4, to HEVC format using the hevc codec and specifies the desired output file, output.mp4.
Adding Subtitles
To include subtitles in a video during HEVC encoding, the FFmpeg command supports an additional flag:
-vf:the video filter chain for applying filters to the video, including subtitle rendering.
With the -vf flag, you can specify the subtitles filter followed by the subtitle file and subtitle text positioning parameters. For example:
ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt:force_style='Fontsize=24'" -c:v hevc -crf 23 output.mp4
In this example, we include subtitles from the subtitle.srt file with a Fontsize of 24, and the other encoding parameters remain the same.
- HEVC (H.265) is a powerful video compression standard that provides higher quality video and lower file sizes compared to the H.264 codec.
- FFmpeg is an open-source multimedia framework that supports handling a wide range of multimedia formats, including HEVC.
- Using FFmpeg, you can encode video clips to HEVC format with the
ffmpeg -i input.mp4 -c:v hevc -crf 23 -preset slow output.mp4command. - Adding subtitles is simple with the
subtitlesfilter, for instance,ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt:force_style='Fontsize=24'" -c:v hevc -crf 23 output.mp4.