MpegFlowBlogBack to home
← Recipes·H.264 → HEVC·codec conversion

Transcode H.264 to HEVC with FFmpeg: production guide

Convert H.264 to HEVC for ~50% smaller files at equivalent visual quality. Working FFmpeg commands for software (libx265) and GPU (NVENC), plus the Apple-compatibility tag every team forgets.

ByMpegFlow Engineering Team·FFmpeg recipe
·2 variants·May 9, 2026

When to use this

You convert H.264 to HEVC when bandwidth costs more than encoder compute — typically library migrations, mobile-first delivery (iOS plays HEVC natively since iOS 11), and bandwidth-constrained markets. HEVC at CRF 23 is roughly visually equivalent to H.264 at CRF 18, with file sizes ~40-50% smaller. The trade-off: encoding is 2-5× slower on CPU, and you pay HEVC encoder licensing if your distribution requires it.

Command variants

Software encoder (libx265)
ffmpeg -i input.mp4 \
  -c:v libx265 -preset medium -crf 23 \
  -tag:v hvc1 \
  -c:a copy \
  output.mp4

Use this when quality matters more than throughput. CPU-based, slower but typically smaller output than NVENC.

GPU encoder (NVENC)
ffmpeg -hwaccel cuda -i input.mp4 \
  -c:v hevc_nvenc -preset p7 -rc vbr -cq 23 \
  -tag:v hvc1 \
  -c:a copy \
  output.mp4

Use this at scale (>1M minutes/month). 5-10× faster on T4/A10 GPUs at slightly larger file sizes.

What each parameter does

  • -c:v libx265 / hevc_nvenc

    libx265 is the software HEVC encoder; hevc_nvenc is NVIDIA hardware acceleration. NVENC produces visibly different output even at the same CRF — quality calibration is per-encoder.

  • -preset medium / p7

    libx265 presets: ultrafast → veryslow. medium is the standard production choice. NVENC presets: p1 (fastest) → p7 (highest quality).

  • -crf 23 / -cq 23

    Constant rate factor. HEVC CRF 23 ≈ visually equivalent to H.264 CRF 18. Lower is higher quality + larger files.

  • -tag:v hvc1

    Critical for Apple compatibility. Without this, FFmpeg defaults to "hev1" tag which iOS / Safari refuse to play. This single flag is the most common HEVC delivery bug.

  • -c:a copy

    Stream-copy the audio without re-encoding. Saves time and avoids quality loss on the audio side.

What this outputs

A single .mp4 file with HEVC video and the original audio. Expected size: 40-55% smaller than the H.264 source at equivalent visual quality. Decoder support: iOS 11+, Safari, Chrome (with hardware HEVC), Edge, most smart TVs since 2017. Older browsers and Android pre-2017 will not play HEVC.

Pitfalls

  1. Apple devices need the "hvc1" tag, not the FFmpeg default "hev1". Forget this and your iOS users see a black screen with audio. The single most common HEVC mistake.
  2. HEVC encoder licensing: libx265 is GPL, libde265 is GPL, but commercial HEVC distribution may owe royalties to MPEG-LA / HEVC Advance / Velos Media depending on your jurisdiction and use case. Talk to legal before broadcast distribution.
  3. NVENC HEVC at CQ 23 is not visually identical to libx265 CRF 23 — NVENC typically runs ~10-15% larger files at equivalent perceived quality. Calibrate per-encoder if quality bars are tight.
  4. CDN delivery costs differ for HEVC vs H.264 at some providers (AWS CloudFront treats them identically; some providers charge HEVC at premium tiers).
  5. HDR10 metadata is preserved by libx265 but requires explicit master-display + max-cll signaling that must match the source. NVENC HDR support is encoder-version-dependent.

At production scale

At >100K minutes/month, the cost calculus flips: CPU x265 at $0.0055/min on a c5.4xlarge is cheaper than NVENC at $0.0080/min on a g4dn.xlarge — but NVENC delivers 5-10× the throughput per dollar of compute when you account for encoder utilization. The right pattern at production scale: NVENC for the bulk of throughput, libx265 reserved for premium-quality master encodes where the quality delta matters. Encoder version pinning becomes non-negotiable above ~500K minutes/month: a libx265 minor-version upgrade can shift output by a few percent file-size, which QC systems flag.

How MpegFlow handles this

MpegFlow records the encoder version (libx265 vs hevc_nvenc + version) in the per-job audit log, so "did the same encoder produce these two ladders?" has a one-query answer. The pool topology lets you route HEVC jobs to dedicated GPU pools without per-customer routing logic in your application.

Topics
  • FFmpeg
  • hevc
  • h264
  • codec
  • Transcoding
  • nvenc
  • production
See also
  • Engineering blog
    Ffmpeg Presets That Survive Production
  • Recipe
    Abr Ladder Generation
  • Architecture
    Broadcast Grade Vod Transcoding
Running this at scale?

Get the orchestration layer for free.

The h.264 → hevc command above is the easy part. The queue, retries, audit trail, encoder-version pinning, and multi-tenant security around it are what every video team rebuilds from scratch. We did the rebuild — design partners run it free during beta.

Apply More recipes
© 2026 MpegFlow, Inc. · Trust & complianceAll systems nominal·StatusPrivacy