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

`av_parser_init()` leaves `pict_type` at `AV_PICTURE_TYPE_I`, and `vc1_parser` 
only sets it when `vc1_extract_header()` extracts a frame header. A track whose 
frames carry no start codes never gives it one, so the default stands for the 
whole stream, and the parse path in `libavformat/demux.c` marks a packet a key 
frame when the parser reports `AV_PICTURE_TYPE_I` with `key_frame` unset. Every 
packet of such a track therefore leaves the demuxer flagged as a key frame.

Matroska is where this shows up, since `matroska_parse_block()` requests 
`AVSTREAM_PARSE_HEADERS` for a VC-1 track while the frames are stored without 
start codes.

## Reproduction

```
curl -O https://samples.ffmpeg.org/V-codecs/WVC1/Test_1440x576_WVC1_6Mbps.wmv
ffmpeg -i Test_1440x576_WVC1_6Mbps.wmv -c copy -map 0:v:0 wvc1.mkv

ffprobe -v error -select_streams v:0 -show_entries packet=flags -of csv 
wvc1.mkv | grep -c K
```

| | before | after |
|---|---|---|
| parsed | 1451 of 1451 | 10 of 1451 |
| `-fflags +noparse` (the container's own flags) | 10 | 10 |

Ten is what the file carries: the Cues list ten entries, at those same 
timestamps.

## What the change does not touch

A track this parser can read is unaffected, because there it sets the picture 
type per frame. The two shapes that could regress both hold:

- a raw `.vc1` elementary stream carries no container flags at all, and still 
reports its single key frame from the parser (measured on `vc1/SA10143.vc1` and 
`vc1/ilaced_twomv.vc1`, unchanged at 1);
- the same streams remuxed to Matroska, where the frames do carry start codes, 
are unchanged as well.

## FATE

All nine vc1 tests pass: `fate-vc1` (`sa00040`, `sa00050`, `sa10091`, 
`sa10143`, `sa20021`, `ilaced_twomv`), `fate-vc1test_smm0005`, 
`fate-vc1test_smm0015`, `fate-vc1-ism`.



>From 3e9abaf05a20387807a7ee0be99af6188ea8b488 Mon Sep 17 00:00:00 2001
From: Vincent Herbst <[email protected]>
Date: Thu, 10 Sep 2026 12:26:58 +0200
Subject: [PATCH] avcodec/vc1_parser: report no picture type until one has been
 read

av_parser_init() leaves pict_type at AV_PICTURE_TYPE_I, and this parser
only sets it when it extracts a frame header. A track whose frames carry
no start codes yields no header to it at all, so the default stands for
the whole stream. ff_read_packet()'s parse path marks a packet a key
frame when the parser reports AV_PICTURE_TYPE_I with key_frame unset, so
every packet of such a track leaves the demuxer flagged as one.

Matroska is the storage form this shows up in. Measured on
samples.ffmpeg.org/V-codecs/WVC1/Test_1440x576_WVC1_6Mbps.wmv remuxed
with -c copy: 1451 of 1451 packets flagged, against the ten the container
carries and the ten -fflags +noparse reports. After the change the parsed
count matches the container.

Reporting AV_PICTURE_TYPE_NONE leaves the flag to the container, which is
where it comes from for that storage form. A track this parser can read
is unaffected, since it sets the picture type per frame: a raw .vc1
stream, whose container carries no flags at all, still takes its single
key frame from the parser.

All nine vc1 FATE tests pass.
---
 libavcodec/vc1_parser.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c
index 595d066dea..fa7e8120fd 100644
--- a/libavcodec/vc1_parser.c
+++ b/libavcodec/vc1_parser.c
@@ -261,6 +261,11 @@ static int vc1_parse(AVCodecParserContext *s,
 static av_cold int vc1_parse_init(AVCodecParserContext *s)
 {
     VC1ParseContext *vpc = s->priv_data;
+    /* Report no picture type until a frame header has actually been read.
+     * av_parser_init() leaves pict_type at AV_PICTURE_TYPE_I, and libavformat
+     * marks a packet a key frame from that default; a track whose frames carry
+     * no start codes yields no header to this parser at all. */
+    s->pict_type = AV_PICTURE_TYPE_NONE;
     vpc->v.s.slice_context_count = 1;
     vpc->v.first_pic_header_flag = 1;
     vpc->v.parse_only = 1;
-- 
2.52.0

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

Reply via email to