FFmpeg Hardware Multi-Bitrate Live Transcoding

This article explains how to efficiently transcode a single live input stream into multiple output bitrates using a single, hardware-accelerated pipeline in FFmpeg. By leveraging GPU acceleration (such as NVIDIA NVENC/NVDEC) and FFmpeg’s hardware filter graph, you can minimize CPU usage, eliminate system memory bottlenecks, and optimize delivery for adaptive bitrate (ABR) live streaming.

The Hardware-Accelerated Pipeline Concept

To achieve maximum performance, the entire transcoding pipeline—decoding, scaling, and encoding—must remain inside the GPU’s video memory (VRAM). Copying video frames back and forth between system RAM (CPU) and VRAM (GPU) introduces latency and consumes significant system bandwidth.

By using NVIDIA’s CUDA-accelerated tools within FFmpeg, we can ingest a stream, decode it to VRAM, split and scale it to various resolutions on the GPU, and encode those streams simultaneously using NVENC.

The FFmpeg Command

Below is a production-ready FFmpeg command that takes a single 1080p live input and transcodes it into three distinct resolutions (1080p, 720p, and 480p) using NVIDIA GPU acceleration, outputting an HLS directory structure with a master playlist.

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i rtmp://localhost/live/input \
-filter_complex "[0:v]split=3[v1][v2][v3]; \
                 [v1]scale_cuda=1920:1080[out1]; \
                 [v2]scale_cuda=1280:720[out2]; \
                 [v3]scale_cuda=854:480[out3]" \
-map "[out1]" -c:v:0 h264_nvenc -b:v:0 5000k -g 50 -keyint_min 50 -sc_threshold 0 \
-map "[out2]" -c:v:1 h264_nvenc -b:v:1 3000k -g 50 -keyint_min 50 -sc_threshold 0 \
-map "[out3]" -c:v:2 h264_nvenc -b:v:2 1400k -g 50 -keyint_min 50 -sc_threshold 0 \
-map 0:a -c:a:0 aac -b:a:0 128k \
-map 0:a -c:a:1 aac -b:a:1 128k \
-map 0:a -c:a:2 aac -b:a:2 96k \
-f hls -hls_time 2 -hls_playlist_type event \
-master_pl_name master.m3u8 \
-var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2" /var/www/html/live/stream_%v.m3u8

How the Pipeline Works

1. GPU Decoding and Memory Management

2. Hardware-Accelerated Filtering

3. Dedicated Hardware Encoding

4. Audio Mapping and HLS Packager