PR #25997 opened by Baptiste Coudurier (bcoudurier) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25997 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25997.patch
The libx265 wrapper never set `avctx->has_b_frames`, so the encoder reported no reorder delay even though x265 outputs B-frames by default (libx264 sets it). This reads the parameters back with `encoder_parameters()` after `encoder_open()`, as the x265 CLI does, because opening the encoder can change `bframes` / `b-pyramid` (all-intra, intra refresh, MCSTF, temporal layers). `has_b_frames` is then derived the same way x265 computes its own DTS delay (`bframes ? (bBPyramid ? 2 : 1) : 0`). Checked against the first output DTS with x265 4.2: | x265-params | has_b_frames | first dts | |---|---|---| | (default) | 2 | -2 | | bframes=0 | 0 | 0 | | b-pyramid=0 | 1 | -1 | | keyint=1 | 0 | 0 | | intra-refresh=1 | 1 | -1 | | ref=1 / temporal-layers=3 | 2 | -2 | Without the read-back, keyint=1 and intra-refresh=1 would report 2. 🤖 Generated with [Claude Code](https://claude.com/claude-code) From 9b6dc9d2c3694e58a4555d18260993aababea467 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier <[email protected]> Date: Thu, 12 Nov 2026 13:47:45 -0800 Subject: [PATCH] avcodec/libx265: set has_b_frames The wrapper never reported the encoder's reorder delay, unlike libx264. Export it from the parameters the encoder actually uses, since x265_encoder_open() may change bframes and b-pyramid (all-intra, intra refresh, MCSTF, temporal layers). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Baptiste Coudurier <[email protected]> --- libavcodec/libx265.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 0ec4f87f5fb..a6738aaa9b5 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -608,6 +608,11 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } + /* x265 may adjust the B-frame settings when opening the encoder */ + ctx->api->encoder_parameters(ctx->encoder, ctx->params); + avctx->has_b_frames = ctx->params->bframes ? + ctx->params->bBPyramid ? 2 : 1 : 0; + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { x265_nal *nal; int nnal; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
