avcodec/vc1_parser: report no picture type until one has been read #24439

Merged
michaelni merged 1 commit from superuser404/FFmpeg:vc1-parser-picture-type into master 2026-09-20 12:14:10 +00:00
Contributor

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.

`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`.
avcodec/vc1_parser: report no picture type until one has been read
All checks were successful
Backport / PR (pull_request_target) Has been skipped
Lint / Pre-Commit (pull_request) Successful in 31s
Test / Fate (linux-aarch64, static, 64 bit) (pull_request) Successful in 12m6s
Test / Fate (Full, Linux, aarch64) (pull_request) Successful in 10m16s
Test / Fate (Qemu, Linux, mips64) (pull_request) Successful in 13m41s
Test / Fate (Qemu, Linux, ppc64) (pull_request) Successful in 15m54s
Test / Fate (linux-amd64, shared, 64 bit) (pull_request) Successful in 18m36s
Test / Fate (linux-amd64, static, 32 bit) (pull_request) Successful in 22m0s
Test / Fate (Qemu, Linux, riscv64) (pull_request) Successful in 27m57s
Test / Fate (Full, Wine, win64) (pull_request) Successful in 31m0s
Autolabel / Labeler (pull_request_target) Successful in 14s
3e9abaf05a
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.
Forgejo_Fairy left a comment

LLM-GPT-6-ASTRA: The fix in 3e9abaf05a looks correct, with two non-blocking suggestions.

The assignment takes effect after the generic parser initialization sets AV_PICTURE_TYPE_I. With key_frame == -1, AV_PICTURE_TYPE_NONE selects the existing container-keyframe fallback in parse_packet(). Successful frame-header parsing still replaces the initial value. This fixes FFmpeg’s default classification; it is not a workaround for an external bug.

Both GPT-6-ASTRA drafts reported successful AArch64 comparisons against the parent, and all three drafts reported nine passing VC-1 FATE tests. I independently confirmed:

  • All nine tests selected by make fate-vc1 SAMPLES=/opt/fate-suite pass.
  • The supplied sample remuxed to Matroska or AVI changes from 1,451 key packets to 10, out of 1,451 packets. Both patched flag sequences match -fflags +noparse. Matroska’s PTS, DTS, durations and sizes also match that output; comparing parent and PR, only flags change among these fields in both containers.
  • All six raw VC-1 FATE samples, vc1-wmapro.ism, and Matroska remuxes of each retain identical packet flags, PTS, DTS, durations and sizes between parent and PR.
  1. GPT-6-ASTRA (code and design), GLM-5.3 — minor, optional regression coverage. A FATE test recording packet flags from a small Matroska reproduction containing both key and non-key packets would protect this fix. The existing nine tests check decoded framecrc output rather than this input-packet classification. The reproduction’s ffprobe -show_entries packet=flags approach is suitable, with expected output in tests/ref/fate/. If a new sample is needed, send the sample-upload request to samples-request at ffmpeg dot org.

  2. GPT-6-ASTRA (design) — minor, explanatory corrections. In the commit message, replace ff_read_packet()'s parse path with parse_packet(). In the PR description, replace matroska_parse_block() with mkv_parse_video(), which requests AVSTREAM_PARSE_HEADERS.

I also checked GLM-5.3’s conditional observations. The proposed missing-index AVI example does not establish a regression: avi_sync() generates keyframe index entries, and removing idx1 from the reproduction leaves all 1,451 packet flags identical before and after this patch. The broader claim of lost seeking remains unverified, with no demonstrated affected input. Also, MOV explicitly requests full parsing for VC-1, so the draft’s explanation that MOV does not parse VC-1 is incorrect.

GLM-5.3’s DASH observation is supported by the conditional parsing path: when P-frame fragmentation or trick-mode parsing is active, NONE sets coding_dependency, suppressing an unsupported codingDependency="false" declaration. That is not an established defect, and requiring stream copy does not make the path unreachable. Its runtime behavior was not independently tested here.

I classify this as minor_issues_approve under the supplied rules for minor inconsistencies between explanation and implementation, and for non-blocking suggestions where the PR can merge in its current form. The verified change fixes the reported classification error without a demonstrated regression. The patch-submission checklist asks authors to consider regression tests for existing code; the additional packet-flags test is useful follow-up coverage rather than a reason to block this fix.

LLM-GPT-6-ASTRA: The fix in 3e9abaf05a20 looks correct, with two non-blocking suggestions. <!-- Scope GPT-6-ASTRA [code review]: Complete single-commit diff and available discussion; full VC-1 parser runtime, parser initialization, demuxer picture-type consumers, Matroska parser selection, developer rules and SMPTE 421M start-code provisions. Reported AArch64 builds, comparisons against the direct parent and nine VC-1 FATE tests; not an exhaustive decoder audit. Scope GPT-6-ASTRA [design review]: Sole commit and available discussion; parser initialization and header extraction, demuxing and timestamp consumers, Matroska setup, FATE definitions, SMPTE 421M Annex G, RFC 9559 and GStreamer VC-1 handling. Reported AArch64 comparisons against the direct parent; other platforms considered by source inspection. Scope GLM-5.3 [code review]: Exhaustive review of the five-line change and a survey of VC-1 parser inputs through Matroska, AVI, ASF, MOV/ISMV, MPEG-TS, raw ES and VC1TEST/RCV; reported master-with/without-patch experiments and nine VC-1 FATE tests. Scope combiner: Verified the commit against its direct parent and read all available discussion; inspected initialization, header extraction, demuxer fallback, Matroska/AVI/MOV/ASF/RCV setup, DASH consumers, FATE definitions, relevant developer rules and supplied specifications. Built on AArch64, ran all nine VC-1 FATE tests, compared packet fields against the parent, and tested AVI with its idx1 index removed. Did not execute a DASH reproduction. --> The assignment takes effect after the generic parser initialization sets `AV_PICTURE_TYPE_I`. With `key_frame == -1`, `AV_PICTURE_TYPE_NONE` selects the existing container-keyframe fallback in [`parse_packet()`](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/libavformat/demux.c#L1296). Successful frame-header parsing still replaces the initial value. This fixes FFmpeg’s default classification; it is not a workaround for an external bug. Both GPT-6-ASTRA drafts reported successful AArch64 comparisons against the parent, and all three drafts reported nine passing VC-1 FATE tests. I independently confirmed: - All nine tests selected by `make fate-vc1 SAMPLES=/opt/fate-suite` pass. - The supplied sample remuxed to Matroska or AVI changes from 1,451 key packets to 10, out of 1,451 packets. Both patched flag sequences match `-fflags +noparse`. Matroska’s PTS, DTS, durations and sizes also match that output; comparing parent and PR, only flags change among these fields in both containers. - All six raw VC-1 FATE samples, `vc1-wmapro.ism`, and Matroska remuxes of each retain identical packet flags, PTS, DTS, durations and sizes between parent and PR. 1. **GPT-6-ASTRA (code and design), GLM-5.3 — minor, optional regression coverage.** A FATE test recording packet flags from a small Matroska reproduction containing both key and non-key packets would protect this fix. The [existing nine tests](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/tests/fate/microsoft.mak#L53) check decoded `framecrc` output rather than this input-packet classification. The reproduction’s `ffprobe -show_entries packet=flags` approach is suitable, with expected output in `tests/ref/fate/`. If a new sample is needed, send the sample-upload request to samples-request at ffmpeg dot org. 2. **GPT-6-ASTRA (design) — minor, explanatory corrections.** In the commit message, replace `ff_read_packet()'s parse path` with `parse_packet()`. In the PR description, replace `matroska_parse_block()` with [`mkv_parse_video()`](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/libavformat/matroskadec.c#L3050), which requests `AVSTREAM_PARSE_HEADERS`. I also checked GLM-5.3’s conditional observations. The proposed missing-index AVI example does not establish a regression: [`avi_sync()` generates keyframe index entries](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/libavformat/avidec.c#L1387), and removing `idx1` from the reproduction leaves all 1,451 packet flags identical before and after this patch. The broader claim of lost seeking remains **unverified**, with no demonstrated affected input. Also, MOV explicitly [requests full parsing for VC-1](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/libavformat/mov.c#L3282), so the draft’s explanation that MOV does not parse VC-1 is incorrect. GLM-5.3’s DASH observation is supported by [the conditional parsing path](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/libavformat/dashenc.c#L2036): when P-frame fragmentation or trick-mode parsing is active, `NONE` sets `coding_dependency`, suppressing an unsupported `codingDependency="false"` declaration. That is not an established defect, and requiring stream copy does not make the path unreachable. Its runtime behavior was not independently tested here. I classify this as **minor_issues_approve** under the supplied rules for minor inconsistencies between explanation and implementation, and for non-blocking suggestions where the PR can merge in its current form. The verified change fixes the reported classification error without a demonstrated regression. The [patch-submission checklist](https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/3e9abaf05a20387807a7ee0be99af6188ea8b488/doc/developer.texi#L962) asks authors to consider regression tests for existing code; the additional packet-flags test is useful follow-up coverage rather than a reason to block this fix.
michaelni merged commit 300e0a8aea into master 2026-09-20 12:14:10 +00:00
michaelni deleted branch vc1-parser-picture-type 2026-09-20 12:14:11 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
FFmpeg/FFmpeg!24439
No description provided.