H.265 to H.264 conversions often result in blocky, low-quality video because default FFmpeg settings prioritize speed over fidelity. To fix this, you must explicitly set a high Constant Rate Factor (CRF), use the libx264 encoder with a slow preset, and ensure proper pixel format handling. This approach restores visual clarity and eliminates compression artifacts during transcoding.
Understanding the Quality Drop
When converting from High Efficiency Video Coding (HEVC/H.265) to Advanced Video Coding (AVC/H.264), the decoder and encoder operate independently. If you do not specify quality parameters, FFmpeg may use a default CRF of 23 or higher, which introduces visible macroblocking, especially in complex scenes like screen recordings with text or sharp edges. The issue is rarely the source file but rather the lack of explicit encoding instructions that tell FFmpeg to preserve detail.
Core Encoding Parameters
The most critical adjustment is the
-crf value. This stands for Constant Rate Factor and controls the quality on a scale from 0 to 51. Lower numbers mean higher quality and larger file sizes. For H.264 output, a CRF between 18 and 23 is generally considered visually lossless or very high quality. Setting it to 18 ensures that the conversion retains as much detail from the original H.265 source as possible.
Another vital parameter is the
-preset. This tells the encoder how much time to spend calculating optimal compression strategies. Common presets include
ultrafast,
superfast,
medium, and
slow. Using
slow or
veryslow allows the encoder to make better decisions about motion estimation and quantization, significantly reducing blockiness compared to faster presets. While encoding takes longer, the visual improvement is substantial.
Handling Pixel Formats
H.265 sources often use different pixel formats, such as
yuv420p10le or
yuva420p, which may not be directly compatible with standard H.264 players without conversion. You should explicitly set the output pixel format using
-pix_fmt yuv420p. This ensures broad compatibility across devices and web browsers while maintaining sufficient color subsampling for high-quality playback. Without this flag, FFmpeg might attempt an automatic conversion that degrades color accuracy or introduces artifacts.
Complete Command Example
Below is a robust command structure that addresses common quality issues. Replace
input.mp4 with your source file and
output.mp4 with your desired destination.
ffmpeg -i input.mp4 -c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p output.mp4
This command forces the use of the
libx264 software encoder, sets a high-quality CRF of 18, uses the
slow preset for better compression efficiency, and explicitly defines the pixel format. If you are dealing with audio, you can add
-c:a aac -b:a 192k to ensure high-quality audio transcoding as well.
For users who need to add text overlays during this process, consider reviewing
Slide Text Using Drawtext in FFmpeg: A Tech Support Guide to integrate annotations without compromising video quality. Additionally, if you ever need to modify existing H.264 files without re-encoding,
Modifying H.264 Video Without Re-encoding: A Special Case provides insights into stream copying techniques.
Advanced Tuning Options
If blockiness persists, you can experiment with the
-profile:v high flag to ensure the highest profile support. Some encoders benefit from
-x264-opts "keyint=25:min-keyint=auto" to control keyframe intervals, which can improve seeking performance and overall stability. However, these advanced options are usually unnecessary for standard conversions unless you have specific streaming requirements.
Always verify the output by playing the video in a player that supports detailed bitrate information. Tools like VLC Media Player can display real-time encoding statistics, allowing you to confirm that the CRF is being applied correctly. If the bitrate fluctuates wildly, check your source file for variable frame rates, which may require additional filtering to stabilize.
Frequently Asked Questions
Why does my converted video look worse than the original?
This usually happens when FFmpeg uses a default CRF that is too high or a fast preset that sacrifices quality for speed. Always specify
-crf 18 and
-preset slow to maximize fidelity during the H.265 to H.264 transition.
Can I convert H.265 to H.264 without losing any quality?
While no lossless conversion exists between different codecs due to algorithmic differences, a CRF of 18 is visually indistinguishable from the source for most viewers. It represents the practical limit of perceptual quality for H.264 encoding.
What causes blocky artifacts in screen recordings?
Screen recordings often contain sharp edges and text, which are difficult for compressors to handle efficiently. Using a lower CRF and a slower preset helps the encoder allocate more bits to these complex areas, reducing visible blocking.
Is it faster to use hardware acceleration for this conversion?
Hardware accelerators like NVENC or QuickSync are faster but typically produce lower quality at equivalent bitrates compared to software encoding with
libx264. For maximum quality, stick to software encoding despite the longer processing time.
Do I need to change the audio codec during conversion?
Not necessarily, but if your source audio is uncompressed or uses a rare codec, adding
-c:a aac ensures compatibility. AAC is the standard for H.264 videos and provides good quality at moderate bitrates like 192kbps.