[FFmpeg-devel] [PATCH] avcodec/mjpegdec: decode only SOF fields when finding stream info (PR #20219)

ramiro code at ffmpeg.org
Mon Aug 11 19:58:04 EEST 2025


PR #20219 opened by ramiro
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20219
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20219.patch

When called from avformat_find_stream_info(), we are only interested in
decoding SOF fields.

This patch makes the decoder skip all other fields (including SOI, SOS,
and EOI). This also prevents the decoder from incorrectly printing the
warning "EOI missing, emulating" (which is the case since 2ae82788).

Fixes: #20119


From 5d7f8d5ec2e7e5c439ae6efcf4aa1db3520bcc4b Mon Sep 17 00:00:00 2001
From: Ramiro Polla <ramiro.polla at gmail.com>
Date: Mon, 11 Aug 2025 18:32:45 +0200
Subject: [PATCH] avcodec/mjpegdec: decode only SOF fields when finding stream
 info

When called from avformat_find_stream_info(), we are only interested in
decoding SOF fields.

This patch makes the decoder skip all other fields (including SOI, SOS,
and EOI). This also prevents the decoder from incorrectly printing the
warning "EOI missing, emulating" (which is the case since 2ae82788).

Fixes: #20119
---
 libavcodec/mjpegdec.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 15a4ebc7f1..87d1d02077 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2463,9 +2463,6 @@ redo_for_pal8:
             case SOF2:
             case SOF3:
             case SOF48:
-            case SOI:
-            case SOS:
-            case EOI:
                 break;
             default:
                 goto skip;
@@ -2541,7 +2538,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
             break;
         case EOI:
 eoi_parser:
-            if (!avctx->hwaccel && avctx->skip_frame != AVDISCARD_ALL &&
+            if (!avctx->hwaccel &&
                 s->progressive && s->cur_scan && s->got_picture)
                 mjpeg_idct_scan_progressive_ac(s);
             s->cur_scan = 0;
@@ -2556,10 +2553,6 @@ eoi_parser:
                 if (s->bottom_field == !s->interlace_polarity)
                     break;
             }
-            if (avctx->skip_frame == AVDISCARD_ALL) {
-                s->got_picture = 0;
-                goto the_end_no_picture;
-            }
             if (avctx->hwaccel) {
                 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
                 if (ret < 0)
@@ -2588,10 +2581,6 @@ eoi_parser:
             s->raw_scan_buffer_size = buf_end - buf_ptr;
 
             s->cur_scan++;
-            if (avctx->skip_frame == AVDISCARD_ALL) {
-                skip_bits(&s->gb, get_bits_left(&s->gb));
-                break;
-            }
 
             if ((ret = ff_mjpeg_decode_sos(s, NULL, 0, NULL)) < 0 &&
                 (avctx->err_recognition & AV_EF_EXPLODE))
@@ -2616,6 +2605,18 @@ eoi_parser:
             break;
         }
 
+        if (avctx->skip_frame == AVDISCARD_ALL) {
+            switch(start_code) {
+            case SOF0:
+            case SOF1:
+            case SOF2:
+            case SOF3:
+            case SOF48:
+                s->got_picture = 0;
+                goto the_end_no_picture;
+            }
+        }
+
 skip:
         /* eof process start code */
         buf_ptr += (get_bits_count(&s->gb) + 7) / 8;
-- 
2.49.1



More information about the ffmpeg-devel mailing list