PR #23142 opened by Diego de Souza (ddesouza) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23142 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23142.patch
H.264 Baseline profile cannot contain B-frames, but the NVENC preset defaults and the max_b_frames-derived frameIntervalP override leave frameIntervalP > 1 when -profile:v baseline is requested. The unconditional check at the end of nvenc_setup_encoder() then sets has_b_frames = 2, which propagates to the muxer and causes compute_muxer_pkt_fields() to back-calculate DTS = PTS - (delay + 1) * frame_duration. The resulting bitstream contains no B-frames, yet every packet has a spurious 3-frame PTS/DTS gap, breaking MPEG-TS/HLS output and DTS-based players. This patch forces frameIntervalP to 1 in the Baseline branch of nvenc_setup_h264_config() and warn if the user (or preset) had asked for B-frames. The later has_b_frames assignment then sees the corrected value and leaves avctx->has_b_frames at 0. Fixes #22727. Signed-off-by: Diego de Souza <[email protected]> >From fc45107d5935b00da4ff97c8ba7389ceb9583d98 Mon Sep 17 00:00:00 2001 From: Diego de Souza <[email protected]> Date: Mon, 18 May 2026 16:05:06 +0200 Subject: [PATCH] avcodec/nvenc: force frameIntervalP=1 for H.264 Baseline profile H.264 Baseline profile cannot contain B-frames, but the NVENC preset defaults and the max_b_frames-derived frameIntervalP override leave frameIntervalP > 1 when -profile:v baseline is requested. The unconditional check at the end of nvenc_setup_encoder() then sets has_b_frames = 2, which propagates to the muxer and causes compute_muxer_pkt_fields() to back-calculate DTS = PTS - (delay + 1) * frame_duration. The resulting bitstream contains no B-frames, yet every packet has a spurious 3-frame PTS/DTS gap, breaking MPEG-TS/HLS output and DTS-based players. This patch forces frameIntervalP to 1 in the Baseline branch of nvenc_setup_h264_config() and warn if the user (or preset) had asked for B-frames. The later has_b_frames assignment then sees the corrected value and leaves avctx->has_b_frames at 0. Fixes #22727. Signed-off-by: Diego de Souza <[email protected]> --- libavcodec/nvenc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index a8dac1ebd3..7b9f7260df 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1358,6 +1358,11 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) case NV_ENC_H264_PROFILE_BASELINE: cc->profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID; avctx->profile = AV_PROFILE_H264_BASELINE; + if (cc->frameIntervalP > 1) { + av_log(avctx, AV_LOG_WARNING, + "B-frames are not supported by H.264 Baseline profile, disabling.\n"); + cc->frameIntervalP = 1; + } break; case NV_ENC_H264_PROFILE_MAIN: cc->profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
