How to Convert HEVC MP4 to HLS Stream with ffmpeg

Abstract: Convert HEVC MP4 files to H.264 HLS streams using ffmpeg for broader device compatibility and adaptive bitrate playback.

Created: 2026-10-02 by
To convert an HEVC MP4 file into an HLS stream using ffmpeg, you must first transcode the video to a widely compatible codec like H.264 and split it into small segments. This process ensures that modern devices with limited HEVC support can play the content smoothly via standard HTTP servers. The following guide details the exact commands and parameters required for this transformation.

Understanding the Conversion Requirements

Why Transcode HEVC?

While HEVC (H.265) offers superior compression efficiency, its support across web browsers and older mobile devices is inconsistent. HLS players often default to expecting H.264 video streams. By transcoding the source material, you guarantee broader compatibility without sacrificing too much quality if bitrate settings are managed correctly.

HLS Structure Explained

HTTP Live Streaming divides media into a playlist file (.m3u8) and multiple segment files (.ts). The playlist acts as an index, allowing clients to switch between different quality levels dynamically. This adaptive bitrate streaming is crucial for maintaining playback stability under varying network conditions.

Preparing Your Environment

Before running the conversion, ensure you have a recent version of ffmpeg installed that supports HEVC decoding. You can verify your installation by checking the build flags for -libx264 and -hevc support. If you are working with large files, consider having sufficient disk space, as intermediate segment files can accumulate quickly during the processing phase.

Executing the Conversion Command

The core command combines several options to handle both the audio and video streams effectively. Below is a robust template for converting a single HEVC MP4 into an HLS output directory.
ffmpeg -i input_hevc.mp4 \
-c:v libx264 -preset medium -crf 23 \
-b:v 1000k -maxrate 1200k -bufsize 2000k \
-c:a aac -b:a 128k -ar 44100 \
-f hls \
-hls_time 4 \
-hls_list_size 0 \
-hls_segment_filename segment_%03d.ts \
playlist.m3u8
Let’s break down these parameters:
  • -c:v libx264: Specifies the H.264 encoder for video compatibility.
  • -preset medium: Balances encoding speed and compression efficiency.
  • -crf 23: Sets the Constant Rate Factor for visual quality; lower values mean higher quality but larger files.
  • -b:v, -maxrate, -bufsize: Controls the video bitrate to prevent buffering issues on slower connections.
  • -c:a aac: Encodes audio to AAC, which is universally supported in HLS streams.
  • -f hls: Forces the output format to HLS.
  • -hls_time 4: Sets each segment duration to 4 seconds, a common standard for smooth seeking.
  • -hls_list_size 0: Includes all segments in the playlist, useful for VOD (Video on Demand).
For more advanced setups involving multiple resolutions, you would repeat this process with different bitrates and save outputs to separate directories. This approach allows the client player to select the appropriate stream based on bandwidth. If you need to add subtitles or additional metadata, refer to our guide on adding subtitles to MP4 files, though note that HLS subtitle handling requires specific EXT-X-MAP tags in newer implementations.

Handling Audio and Sync Issues

Audio synchronization is critical when splitting streams. The -ar 44100 flag ensures the sample rate matches standard expectations. If you notice drift between audio and video, check the original container's timestamps. Sometimes, forcing the start time with -ss 0 before the input file helps reset timestamps cleanly. For complex audio tracks, such as converting DTS to AAC, see converting French DTS audio tracks for detailed encoder settings.

Serving the Stream

Once the command completes, you will have a playlist.m3u8 file and a series of segment_*.ts files. These must be served from a web server that supports MIME types for application/vnd.apple.mpegurl and video/mp2t. Nginx or Apache can easily serve these static files. Ensure your server configuration does not cache the playlist aggressively, as clients should re-fetch it to detect any updates.

Troubleshooting Common Errors

If the resulting stream plays back with scrambled frames or black screens, the issue may lie in the keyframe alignment. HLS segments should ideally start with an I-frame (keyframe). FFmpeg handles this automatically in most cases, but if you encounter issues, adding -g 48 (group of pictures size) can help align keyframes with segment boundaries. Additionally, verify that your input file is not corrupted; try playing it locally before conversion. For other frame-related issues, consult our troubleshooting article on scrambled frames during EXR to MP4 conversion, as the principles of frame ordering apply similarly.

Frequently Asked Questions

Can I keep the HEVC codec in the HLS stream?

Yes, but only if your target audience uses devices that fully support HEVC over HLS, such as newer Apple TVs and high-end Android devices. Most web-based players still require H.264 fallbacks.

How do I reduce the file size of the HLS output?

Increase the CRF value (e.g., to 26 or 28) or lower the -b:v bitrate. However, this may degrade visual quality significantly, especially in scenes with fast motion.

What is the ideal segment length for HLS?

Between 2 and 6 seconds is standard. Shorter segments allow faster startup times but increase overhead, while longer segments improve caching efficiency at the cost of latency.

Do I need a special server to host HLS files?

No, any standard HTTP server works as long as it serves the .m3u8 and .ts files with correct MIME types. Cloud storage services like AWS S3 also work well with proper configuration.

Why is my audio out of sync after conversion?

This usually happens due to timestamp inconsistencies in the source file. Using the -fflags +genpts option during input processing can often resolve timestamp gaps.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More