>From d7863bab8e1028b6cfb3ce848e216e86ff00eca0 Mon Sep 17 00:00:00 2001 From: cynthia2006 <cynthia2...@proton.me> Date: Tue, 28 May 2024 22:03:50 +0530 Subject: [PATCH] lavc/mjpegdec: add option for ignorning malformed APPx segments X-Unsent: 1 To: ffmpeg-devel@ffmpeg.org
A few cameras, namely Logitech C270 or similar produce MJPEG frames containing malformed APP0 chunks, and as a result of which, FFmpeg spams stdout with "[mjpeg @ 0xcoffeebabe] unable to decode APP fields: Invalid data found when processing input" The issue is explained in full-detail here: https://stackoverflow.com/q/55439184. TL;DR The second APP0 chunk is the culprit here. Issue is mitigated if those segments are ignored. This patch adds a MJPEG decoder private option `-allow_malformed_app` which if enabled, ignores those malformed APP0 segments. Signed-off-by: cynthia2006 <cynthia2...@proton.me> --- libavcodec/mjpegdec.c | 5 +++++ libavcodec/mjpegdec.h | 1 + 2 files changed, 6 insertions(+) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 1481a7f285..b1e26044c0 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -1863,6 +1863,9 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) av_log(s->avctx, AV_LOG_WARNING, "skipping APPx (len=%"PRId32") for bayer-encoded image\n", len); skip_bits(&s->gb, len); return 0; + } else if (s->allow_malformed_app) { + skip_bits(&s->gb, len); + return 0; } else return AVERROR_INVALIDDATA; } @@ -2988,6 +2991,8 @@ static void decode_flush(AVCodecContext *avctx) static const AVOption options[] = { { "extern_huff", "Use external huffman table.", OFFSET(extern_huff), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD }, + { "allow_malformed_app", "Allow (ignore) malformed APPx chunks.", + OFFSET(allow_malformed_app), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD }, { NULL }, }; diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 13c524d597..d7e4f88682 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -138,6 +138,7 @@ typedef struct MJpegDecodeContext { unsigned int ljpeg_buffer_size; int extern_huff; + int allow_malformed_app; AVDictionary *exif_metadata; AVStereo3D *stereo3d; ///!< stereoscopic information (cached, since it is read before frame allocation) -- 2.45.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".