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

These packets do not contain frames, so marking them with `AV_PKT_FLAG_DISCARD` 
helps applications compute correct frame counts.

Unfortunately (as far as I can tell) this requires changing public API through 
`AVCodecParserContext` - if this is a problem and/or there is a better way to 
do this, please let me know.


>From d50460e53d4aa2f82e45fdd3a5da11281c2d4321 Mon Sep 17 00:00:00 2001
From: arch1t3cht <[email protected]>
Date: Tue, 28 Oct 2025 22:46:08 +0100
Subject: [PATCH 1/2] avcodec: Add discard flag to AVCodecParserContext

Enable parsers to set AV_PKT_FLAG_DISCARD flags on packets, just like
they can set AV_PKT_FLAG_KEY via the key_frame field.
---
 doc/APIchanges       | 3 +++
 libavcodec/avcodec.h | 6 ++++++
 libavformat/demux.c  | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index 9086093149..b1283ea3de 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
 
 API changes, most recent first:
 
+2025-10-xx - xxxxxxxxxx - lavc 62.16.100 - avcodec.h
+  Add discard to AVCodecParserContext
+
 2025-10-xx - xxxxxxxxxx - lavu 60.16.100 - pixfmt.h
   Add AVCOL_TRC_EXT_BASE and AVCOL_TRC_L_LOG.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 83a4e56e22..3110513022 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2729,6 +2729,12 @@ typedef struct AVCodecParserContext {
      * one returned by a decoder.
      */
     int format;
+
+    /**
+     * Set to 1 for packets that will be dropped after decoding,
+     * see AV_PKT_FLAG_DISCARD.
+     */
+    int discard;
 } AVCodecParserContext;
 
 typedef struct AVCodecParser {
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 934eb80553..18392df795 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1275,6 +1275,9 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
         if (sti->parser->key_frame == -1 && sti->parser->pict_type 
==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY))
             out_pkt->flags |= AV_PKT_FLAG_KEY;
 
+        if (sti->parser->discard)
+            out_pkt->flags |= AV_PKT_FLAG_DISCARD;
+
         compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts);
 
         ret = avpriv_packet_list_put(&fci->parse_queue,
-- 
2.49.1


>From 7d04d351f9e5afc3c31c0424cf1f8ce051a2aa38 Mon Sep 17 00:00:00 2001
From: arch1t3cht <[email protected]>
Date: Tue, 28 Oct 2025 22:47:41 +0100
Subject: [PATCH 2/2] avcodec/vc1_parser: Set discard for EOS packets

---
 libavcodec/vc1_parser.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c
index 124a7a771f..245eaa2b27 100644
--- a/libavcodec/vc1_parser.c
+++ b/libavcodec/vc1_parser.c
@@ -147,6 +147,10 @@ static int vc1_parse(AVCodecParserContext *s,
         vc1_extract_header(s, avctx, unesc_buffer, unesc_index);
         next = 0;
     }
+
+    if (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)
+        s->discard = 1;
+
     while (i < buf_size) {
         uint8_t b;
         start_code_found = 0;
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to