x265 delay, and the per-frame turbulence x265 adds to a pipeline’s timing, comes from slice-type lookahead depth, B-frames and frame threads. The latency-safe baseline we would use is no B-frames, a short or zero lookahead, as few frame threads as throughput allows and a fast preset. From there, move to slower presets only while the per-frame time, measured under production load, stays inside the encoder’s share of the deadline. If the analytics host already has a GPU with an NVENC engine, we would move a deadline-bound encode onto that engine instead.
TechnoLynx profiles the x265 encode stage of a video analytics pipeline against its latency budget and names the preset and threading configuration that meets the deadline without over-provisioning CPU or GPU.
x265 is a tunable stage, not a fixed cost: the same encoder can be configured for a few frames of delay or for many.
x265 Against x264: About Half the Bits for Much More CPU
The HEVC gain over H.264 that matters here is compression. A 2024 arXiv survey of end-to-end streaming pipelines describes HEVC as reaching up to 50% better compression efficiency than H.264 at the same quality, partly by replacing H.264’s 16×16 macroblocks with coding tree units (CTUs) of up to 64×64. The Academy Software Foundation’s encoding guidelines put the file-size reduction at 25-50%. The same survey notes that video encoding is computationally intensive, and slower x265 presets spend more computation to save bits.
For an analytics pipeline, that trade only matters where bits are the scarce resource: camera uplinks on constrained links, long retention archives, or streams forwarded to a remote inference site. Where the encoded stream simply goes to local storage and CPU is already tight, x264 or a hardware encoder may serve the deadline better than the extra compression is worth. If you are migrating rate settings, the ASWF guide quotes a community mapping of x265 CRF ≈ 1.09 × x264 CRF − 4.19, and notes that x265’s default CRF of 28 sits on the low-quality side.
Where x265’s Latency Comes From
For a latency budget, four mechanics matter.
Lookahead. The x265 documentation calls the slice-type decision lookahead “a key determining factor for encoder latency”, with a default of 20 frames. A longer lookahead makes scene-cut decisions more accurate and makes cutree’s adaptive quantisation more effective. That is compression bought with frames of delay.
B-frames. x265 defaults to up to four consecutive B-frames, and the documentation gives --bframes 0 as the way to force all-P/I low-latency encodes. B-frames reference future frames, so the encoder has to hold frames back before it can emit them.
Frame threads. x265 enables frame parallelism by default, and the x265 documentation is explicit about the price: each additional frame thread adds one frame of latency. The default is auto-detected from the CPU core count; the threading documentation lists five frame threads for 16 or more cores and six to eight above 32.
Wavefront Parallel Processing (WPP). WPP lets each CTU row start once the row above is at least two CTUs ahead, which the CLI reference credits with a 3-5x gain in parallelism for about 1% compression overhead. It parallelises CTU rows within a frame, and fewer CTU rows means less parallelism. The threading documentation says 30% to 50% of theoretical perfect threading is typical. Faster presets use 32-pixel CTUs partly to get more rows to encode in parallel.
The practical consequence: WPP is the parallelism to keep, and frame threads are the parallelism to ration.
Settings That Trade Encode Latency Against Compression
| Setting | Effect on latency | What it costs | Deadline-bound starting point |
|---|---|---|---|
--rc-lookahead |
Main driver of encoder latency; default 20 frames | Shorter lookahead weakens scene-cut and cutree decisions | 0 for strict deadlines, a few frames if some delay is tolerable |
--bframes |
0 forces all-P/I low-latency output; default 4 | Loses B-frame compression; memory and full-trellis (b-adapt 2) lookahead work drop with it | 0 |
--frame-threads |
Each extra thread adds one frame of latency | One thread has severe throughput implications | 1, raised only if throughput misses the frame rate |
| WPP | No added frames; 3-5x parallelism | About 1% compression | Leave enabled (default) |
--preset |
Sets per-frame compute, so per-frame wall time | Faster presets lose compression efficiency | Fastest preset that meets the bitrate target, then step slower |
--keyint |
Long GOPs add no encode delay, but set how far a joining decoder waits for a keyframe | Shorter GOPs spend more bits on I-frames | Match the stream’s random-access needs; default 250 |
--tune zerolatency |
Encodes synchronously; frame parallelism off | Compression and throughput | Use as the reference low-latency configuration |
Low-latency tuning flags disable B-frames and lookahead, and in the x265 documentation’s words, “these settings disable frame parallelism, which is an important component for x265 performance”, with x265_encoder_encode() returning each picture’s NALs synchronously. Arunruangsirilert and Katto (2025) ran software HEVC as -tune zerolatency -rc-lookahead 0 -bf 0. They measured a 0.286 dB PSNR drop for x265 in low-latency mode, and a further 0.159 dB PSNR and 0.830 VMAF drop in ultra-low-latency mode, where the hardware encoders they tested showed no change. In that study, removing latency from x265 cost it quality at a fixed bitrate. Moving those hardware encoders from low-latency to ultra-low-latency mode, in that study, did not.
Choosing a Preset to the Deadline, Not to the File Size
x265’s ten presets trade encoding speed against compression efficiency, with medium as the default. The spread is wide. A EUSIPCO 2017 study on a four-core Xeon measured ultrafast at 22 fps and placebo at 0.4 fps, 47× slower. In the same study, ultrafast produced a bitrate 45% higher than placebo, and system energy rose 45× from ultrafast to placebo. The authors concluded that fast, medium and slow gave the best bitrate-to-energy trade-offs. The ASWF guide reaches a similar practical verdict from a CRF 18 comparison: medium or slow is enough, and anything slower is “really not gaining you anything”.
For a live pipeline the governing constraint is speed. Menon et al. (2022) state that live encoders are expected to encode at the video frame rate and usually run the fastest preset to be sure of it. Their CAPS scheme instead picks, per segment, the preset whose predicted encoding time is closest to the target without exceeding it. With x265 that gained 0.83 dB PSNR and 3.81 VMAF at the same bitrate over fastest-preset encoding, by spending CPU time that would otherwise have sat idle. Simpler content encodes faster than the target, and that headroom can buy quality.
That is the method we would apply to an analytics stream, done offline rather than per segment:
- Set the encoder’s slice of the per-frame deadline. At 30 fps the whole frame interval is 33.3 ms, and the encoder gets only part of it.
- Fix the structure first: bframes 0, lookahead at the minimum the stream tolerates, one frame thread.
- Encode representative footage (the busiest scenes, not the quiet ones) at each candidate preset on the production host, under production concurrency.
- Take the slowest preset whose p99 per-frame time fits the slice, and stop there. Gains beyond medium or slow are small anyway.
- Raise frame threads only if throughput, not per-frame time, misses the frame rate, and count each added thread as one more frame of delay.
Busy scenes matter because x265 works harder on textured, high-motion content, and a tail-latency budget is set by the frames that cost most.
What Compression Does to Detection and Tracking Accuracy
What the analytics consumer sees is the detail that survived quantisation. A study encoding with the HEVC reference software (HM 16.20, low-delay configuration) found that the quantisation parameter (QP) had a statistically significant effect on multiple object tracking accuracy (MOTA). Motion search range showed no significant effect for the tracker tested. The study covers one encoder and one tracker, so it is not a general rule. It does suggest where encode effort pays for analytics: in the bits allocated (QP, rate control), not in exhaustive motion search. Work on analytics-oriented encoding goes further and modulates QP per block according to how much each region matters for downstream accuracy.
The useful acceptance test is detection or tracking accuracy on encoded footage at the chosen QP, not PSNR. The pipeline pays for PSNR it never uses.
Does the x265 Encode Stage Have to Meet the Real-Time Deadline?
Only if something downstream waits for the encoded bitstream. When inference reads decoded or raw frames before encoding, and x265 only produces the recording or the archive copy, the encode can run best-effort. It can then use a long lookahead, B-frames, frame threads and a slower preset, provided its queue drains on average and does not hold frames that the analytics path needs. When the encoded stream itself is the transport (an edge device sending HEVC to a central inference service, say), every frame of encoder delay is a frame of detection delay, and the latency-safe settings apply. For splitting a per-stream deadline between stages, see Real-time computing in video analytics pipelines. Offline transcoding with no deadline, such as preparing media for review, is outside this page’s scope; see HEVC transcoding for moderation-ready media.
A best-effort encoder still needs a guard: if its queue grows without bound under peak load, it has quietly become part of the critical path through memory pressure and shared cores.
How Do I Profile x265 Under Production Load?
Use the encoder’s own per-frame statistics, captured on the production host with all of its other streams running. x265 can log per-frame statistics to a CSV file, and the CLI documentation defines the fields that matter for a latency budget:
- Latency: frames between a picture going in and coming out.
- DecideWait ms: how long the frame encoder waited for a frame, “the latency introduced by slicetype decisions (lookahead)”.
- Wall time ms: from the first CTU being ready to the frame’s NALs being complete.
- Total frame time and Avg WPP: total time spent on the frame, and the average number of worker threads active on it, which shows how well wavefront parallelism is working.
Read the distribution, not the mean. The p99 wall time on busy scenes is what decides whether the stage fits its slice. Thread pools are worth checking here: x265 creates one pool per NUMA node and by default one thread per hyperthreaded core, and since version 2.9 frame threads follow --pools rather than the hardware thread count. Several encoder instances each sized for the whole machine will oversubscribe it. Two documented traps recur. Over-allocating frame threads costs memory and often reduces performance, and dedicated lookahead threads can starve the frame encoders.
This is where profiling beats received wisdom. Rules such as “always use medium” or “more threads is faster” only hold for a given core count, content mix and concurrency, which is why the profile is taken on the production host under production load. The same principle, applied to GPU inference, is argued in benchmarking GPUs against your own workload.
When Should I Switch from x265 to NVENC?
Switch when the encode is deadline-bound and the host already carries an NVIDIA GPU for inference. NVIDIA’s documentation describes NVENC as a hardware encoder independent of the graphics and CUDA cores, handling HEVC 8-bit and 10-bit end to end. That leaves the CPU, and the CUDA cores running your models, free for other work. Arunruangsirilert and Katto measured NVIDIA’s encoder at about 7 frames end to end for 4K across nearly all presets and tuning modes; the best ultra-low-latency result, 83 ms (5 frames), came from Intel’s. That is the opposite of x265, where the preset sets the per-frame cost. On cost, NVIDIA’s own benchmark of transcoding and cloud-gaming encodes reports GPU HEVC encoding as 2x-4x cheaper than CPU x265 for its low-latency (LL) and ultra-high-quality (UHQ) tunes. Treat that as a vendor measurement, not a result for your workload.
Keep x265 on the CPU when there is no hardware encoder, when the encode runs best-effort on cores that would otherwise sit idle, or when a deployment needs settings only a software encoder exposes. An NVENC engine left unused beside a CPU encoder that struggles to keep up is a form of the hidden cost of GPU underutilisation.
Who Can Tune the Encode Stage of Our Analytics Pipeline?
TechnoLynx scopes this work as a GPU Performance Audit of the video analytics workload, part of its AI engineering for media, broadcast and telecom. Outside help earns its place when encode, decode and inference share the same hosts and the bottleneck moves as you tune each one.
The Setting That Decides Whether Frames Arrive in Time
Lookahead, B-frames, frame threads and preset each trade compression against delay. Frame threading defaults to an auto-detected count, and on a host with more than 32 cores that default of six to eight frame threads adds several frames of latency. Before reaching for a faster preset or new hardware, check how many frames the encoder holds in flight and whether the downstream analytics needs it to hold any at all.