From d65fd5581d7e28dc063a35ccb7ef88ee0b7417f5 Mon Sep 17 00:00:00 2001 From: iSold Leo Date: Mon, 3 Aug 2026 19:43:47 +0800 Subject: [PATCH] avdevice/avfoundation: keep format and frame rate range paired Formats with the same dimensions may expose different frame rates. The selection loop previously updated selected_format for every size match but kept selected_range from an earlier format. This could apply a range to a format that does not support it and make device configuration fail. Only update selected_format together with its matching range. Track a size-only match separately so the muxed-device fallback remains unchanged. Reported-by: MW-de Suggested-by: MW-de Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/22694 Signed-off-by: iSold Leo --- libavdevice/avfoundation.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index 1ba1f83009..8b7e728279 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -394,6 +394,7 @@ static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_dev double framerate = av_q2d(ctx->framerate); NSObject *range = nil; NSObject *format = nil; + NSObject *matching_size_format = nil; NSObject *selected_range = nil; NSObject *selected_format = nil; @@ -411,13 +412,14 @@ static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_dev if ((ctx->width == 0 && ctx->height == 0) || (dimensions.width == ctx->width && dimensions.height == ctx->height)) { - selected_format = format; + matching_size_format = format; for (range in [format valueForKey:@"videoSupportedFrameRateRanges"]) { double max_framerate; [[range valueForKey:@"maxFrameRate"] getValue:&max_framerate]; if (fabs (framerate - max_framerate) < 0.01) { + selected_format = format; selected_range = range; break; } @@ -425,7 +427,7 @@ static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_dev } } - if (!selected_format) { + if (!matching_size_format) { av_log(s, AV_LOG_ERROR, "Selected video size (%dx%d) is not supported by the device.\n", ctx->width, ctx->height); goto unsupported_format; @@ -435,6 +437,7 @@ static int configure_video_device(AVFormatContext *s, AVCaptureDevice *video_dev av_log(s, AV_LOG_ERROR, "Selected framerate (%f) is not supported by the device.\n", framerate); if (ctx->video_is_muxed) { + selected_format = matching_size_format; av_log(s, AV_LOG_ERROR, "Falling back to default.\n"); } else { goto unsupported_format;