From patchwork Fri Oct 18 17:30:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cynthia X-Patchwork-Id: 52389 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:143:b0:48e:c0f8:d0de with SMTP id h3csp1078748vqi; Fri, 18 Oct 2024 10:31:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXZetfqfEGWHgao1qDMbBge8MMnLsVNwqxm35CV7VW6Tc/Rw1po41wvRku2a079uFd03q7vc4UCISb9DKyFLxqx@gmail.com X-Google-Smtp-Source: AGHT+IFIu2e9ckaAjHphiBoZe3qwy7GNUnJ3dR9fCg0hE4E5WnlF/FSPbJeYzPwyYnlwDY/oCecJ X-Received: by 2002:a05:6402:35c6:b0:5c9:5bcf:db95 with SMTP id 4fb4d7f45d1cf-5ca0ac627famr2531105a12.16.1729272674973; Fri, 18 Oct 2024 10:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729272674; cv=none; d=google.com; s=arc-20240605; b=Am8Gn/LpbHoRBIlIq0ov3QSCVrQWSyiSg9pCRekMI819G3kX5yvy4OivV+LFWNoRRk yTDmUMkRXS63ZkH38IAiVeOxPRbv8zwwEZTdYC4mSwnzRvcdARmerTx5D8fy050Yhhak r83guRqjn4Kz6yBqvkwR181yYk/R72fTrbm+ffS/WV35eUfxeM7OpHkSNBhyp3kM08I/ F4cAAvpqc0yn6RBy15SnUsfGzblseqmt4AN3W2CQoBK6iKpTYDwJ/89rcLW52b5rTdmp UobvCZkSr1+UI4jvlbRwD7V8ILV75mmIYAfi7yiqqA5o5bcBUaY6gGC6+h45KpehtU0a kNGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:feedback-id:message-id:to :date:delivered-to; bh=b/2OdIvJ8NC1v/2V9gzjGhQzvQvsIFYTXCNuMfPrxDo=; fh=de1HRCVJxXgwnoX/xXuKjtFuMrhP/RqDH5MVYwWzsn0=; b=G0lZoNpBKci+UzVsmIkAl4Yrl0GuRTlRup+f57qN9WUSM6jRFV/qD5aUURcdpXqf8E C982aVHopRK6o+87nr6F/dAt8SgZD3/jQEXkVsTqNtXqdZSDzI8dRu6ckKRGfXRJkIXO CRRcws6+maZb8aI97Eac9/tPlFHaVBb6Sqa18jcnMxerAosgGux3HC+mP2z9qXr9YP8w KgPf+ZnOfMrHkVUHBfil0BQFdRih7hC9SPA5Yckqq1pHOz9kxnhftwMI/gJR9PMMeUq3 rXlAY03tBHBW/A6psIKeregC22bLEgu9v1dSSM7K/tyI5StT+gGVGM4WCWLutP87/5yb pFZA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5ca0e8a9746si657188a12.436.2024.10.18.10.31.14; Fri, 18 Oct 2024 10:31:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB93868DBDB; Fri, 18 Oct 2024 20:31:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40140.protonmail.ch (mail-40140.protonmail.ch [185.70.40.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8AF6468DBDB for ; Fri, 18 Oct 2024 20:31:04 +0300 (EEST) Date: Fri, 18 Oct 2024 17:30:57 +0000 To: "ffmpeg-devel@ffmpeg.org" Message-ID: Feedback-ID: 106526352:user:proton X-Pm-Message-ID: 2dcf6664f40f7638a242b6ce657000480b283e63 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/mjpegdec: Add option for ignorning malformed APPx segments X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Cynthia via ffmpeg-devel From: Cynthia Reply-To: FFmpeg development discussions and patches Cc: Cynthia Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 4rfwyR/vs2l+ From d7863bab8e1028b6cfb3ce848e216e86ff00eca0 Mon Sep 17 00:00:00 2001 From: cynthia2006 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 --- libavcodec/mjpegdec.c | 5 +++++ libavcodec/mjpegdec.h | 1 + 2 files changed, 6 insertions(+) This mail is a resubmission because due to techincal faults my e-mail didn't contain a subject. -- 2.45.1 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)