fix: restore generic decoder fallback for ffmpeg cameras

Extract the "use whatever decoder ffmpeg provides" logic from
FFmpeg_Input into a shared open_fallback_decoder() and call it from
FfmpegCamera, which had lost the fallback: its generic path only ran
inside the preferred-codec loop, so an empty get_decoder_data() result
failed outright instead of trying the codec's default decoder.

The dec_codecs table stays a preference list; a codec present in the
ffmpeg build but absent from the table (e.g. libopenh264 for H264) now
decodes via the fallback instead of requiring a hard-coded entry.

Add tests/zm_ffmpeg_fallback.cpp covering the fallback with a codec not
in dec_codecs (mpeg2video), the optional codec_out argument, and the
no-decoder case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Isaac ConnorandClaude Opus 4.8 committed 2026-07-19 11:26:03 -04:00
1 parent 74a248f1b1
commit 74bf0637f0
6 files changed
+124 -15

No files matched your search

+2 -14
View File
@@ -129,20 +129,8 @@ int FFmpeg_Input::Open(const char *filepath) {
if (!streams[i].context) {
Debug(1, "Failed with known codecs, trying harder");
if ((streams[i].codec = avcodec_find_decoder(input_format_context->streams[i]->codecpar->codec_id))) {
Debug(1, "Using codec (%s) for stream %d", streams[i].codec->name, i);
streams[i].context = avcodec_alloc_context3(streams[i].codec);
avcodec_parameters_to_context(streams[i].context, input_format_context->streams[i]->codecpar);
zm_dump_codec(streams[i].context);
error = avcodec_open2(streams[i].context, streams[i].codec, nullptr);
if (error < 0) {
Error("Could not open input codec (error '%s')", av_make_error_string(error).c_str());
avcodec_free_context(&streams[i].context);
streams[i].context = nullptr;
}
}
streams[i].context = open_fallback_decoder(
input_format_context->streams[i]->codecpar, &streams[i].codec);
}
if (!streams[i].context) {