Why Convert Codecs?
H.265, also known as High Efficiency Video Coding (HEVC), offers superior compression efficiency compared to H.264. However, many older smart TVs, media players, and streaming devices only support H.264 decoding. Converting the video allows you to play high-quality content on legacy hardware that cannot interpret the newer HEVC stream directly.
Prerequisites and Installation
The most reliable tool for this task is FFmpeg, a powerful command-line utility available on Linux, Windows, and macOS. Ensure you have the latest stable version installed to access all necessary encoders.
- Linux: Install via your package manager (e.g.,
sudo apt install ffmpeg). - Windows: Download from the official FFmpeg website and add the bin folder to your system PATH.
- macOS: Use Homebrew with
brew install ffmpeg.
If you prefer a graphical interface, tools like HandBrake or Shutter Encoder provide front-ends for FFmpeg, but the command line offers precise control over encoding parameters.
Core Conversion Command
To achieve minimal quality loss, you must avoid re-compressing the video aggressively. The key is setting a low Constant Rate Factor (CRF). In FFmpeg, a CRF value between 18 and 23 is considered visually lossless for most content. Lower values mean higher quality and larger file sizes.
ffmpeg -i input_hevc.mp4 -c:v libx264 -crf 18 -preset medium -c:a copy output_h264.mp4
This command performs the following actions:
- -i input_hevc.mp4: Specifies the source H.265 file.
- -c:v libx264: Selects the H.264 encoder.
- -crf 18: Sets the quality level. 18 is nearly indistinguishable from the source for most viewers.
- -preset medium: Balances encoding speed and compression efficiency. Slower presets like
sloworveryslowyield slightly better compression but take much longer. - -c:a copy: Copies the audio stream without re-encoding it, preventing any audio quality degradation and speeding up the process.
Advanced Optimization Techniques
While the basic command works well, certain scenarios require additional tweaks to ensure perfect playback and minimal artifacts.
Handling Interlaced Content
If your source video is interlaced (common in broadcast TV recordings), converting it directly can cause combing artifacts. You should deinterlace during the conversion.
ffmpeg -i input_interlaced.hevc -vf "yadif=0:-1:0" -c:v libx264 -crf 18 -c:a copy output_deinterlaced.mp4
The yadif filter removes interlacing artifacts before encoding. For more complex cases, consider using hqdn3d for noise reduction if the source is particularly grainy.
Audio Stream Management
Sometimes, the audio codec in the H.265 file might not be compatible with the target player. If you encounter audio sync issues or silence, re-encode the audio using AAC.
ffmpeg -i input.hevc -c:v libx264 -crf 18 -c:a aac -b:a 192k output_with_aac.mp4
This forces the audio into AAC format at 192 kbps, which is widely supported and provides good quality for stereo tracks.
Batch Processing Multiple Files
If you need to convert an entire library of videos, manual entry is inefficient. You can use batch scripts to automate the process.
On Linux/macOS (Bash):
for file in *.mp4; do
ffmpeg -i "$file" -c:v libx264 -crf 18 -preset medium -c:a copy "${file%.mp4}_h264.mp4"
done
On Windows (Command Prompt):
for %f in (*.mp4) do ffmpeg -i "%f" -c:v libx264 -crf 18 -preset medium -c:a copy "%~nf_h264.mp4"
This loops through all MP4 files in the directory, converts them, and saves them with a _h264 suffix to distinguish them from the originals.
Verifying Quality and Compatibility
After conversion, always verify the output. Play the file on the target device to ensure smooth playback. You can also check the technical details using ffprobe:
ffprobe output_h264.mp4
Look for Stream #0:0(eng): Video: h264 to confirm the codec change. Compare the file size with the original; since H.264 is less efficient than H.265, expect the file size to increase by approximately 20-40% for the same visual quality.
For related tasks involving different container formats, such as converting MKV HLS streams, you may find A Shorter Way to Convert MKV HLS using FFmpeg useful for understanding advanced muxing techniques.
Frequently Asked Questions
Does lowering the CRF below 18 improve quality noticeably?
No, values below 18 are generally considered "visually lossless" already. Going lower increases file size significantly without providing a perceptible improvement in image clarity for most human observers.
Can I convert H.265 to H.264 without re-encoding the video?
No, you cannot simply change the codec identifier without re-encoding. H.265 and H.264 use fundamentally different compression algorithms, so the pixel data must be decoded and re-encoded into the new format.
What if my old TV doesn't support H.264 Main Profile?
Most modern TVs support H.264 Main or High profiles. If your TV is very old, you may need to specify -profile:v baseline in the FFmpeg command, though this will reduce compression efficiency and increase file size.
Is it faster to convert on a GPU or CPU?
GPU acceleration (using NVENC or QSV) is much faster but often results in lower quality at the same bitrate. For "no quality loss" goals, CPU encoding with libx264 is preferred because it offers finer control over compression algorithms.
Should I keep the original audio track?
Yes, using -c:a copy preserves the original audio bit-for-bit. This avoids generational loss and speeds up processing. Only re-encode audio if the original codec is unsupported by your target device.