MediaCapture: Don't crash if video codec supports 0 formats

This commit is contained in:
Stenzek 2025-07-27 01:36:13 +10:00
parent 44237146ef
commit 2b18df0910
No known key found for this signature in database

View File

@ -2278,17 +2278,20 @@ bool MediaCaptureFFmpeg::InternalBeginCapture(float fps, float aspect, u32 sampl
return false; return false;
} }
#else #else
if (!vcodec->pix_fmts) supported_pixel_formats = vcodec->pix_fmts;
if (supported_pixel_formats)
{
while (supported_pixel_formats[num_supported_pixel_formats] != AV_PIX_FMT_NONE)
num_supported_pixel_formats++;
}
#endif
if (!supported_pixel_formats || num_supported_pixel_formats == 0)
{ {
Error::SetStringView(error, "Video codec supports no formats."); Error::SetStringView(error, "Video codec supports no formats.");
return false; return false;
} }
supported_pixel_formats = vcodec->pix_fmts;
while (supported_pixel_formats[num_supported_pixel_formats] != AV_PIX_FMT_NONE)
num_supported_pixel_formats++;
#endif
// Prefer YUV420 given the choice, but otherwise fall back to whatever it supports. // Prefer YUV420 given the choice, but otherwise fall back to whatever it supports.
sw_pix_fmt = supported_pixel_formats[0]; sw_pix_fmt = supported_pixel_formats[0];
for (int i = 0; i < num_supported_pixel_formats; i++) for (int i = 0; i < num_supported_pixel_formats; i++)