Skip to content

Fix frame size/length leaking between streams of multi-stream files - #38

Merged
hendriks73 merged 1 commit into
devfrom
hendrik/multistream-frame-fields
Oct 22, 2026
Merged

hendriks73 merged 1 commit into
devfrom
hendrik/multistream-frame-fields

Conversation

@hendriks73

@hendriks73 hendriks73 commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Problem

In create_ffaudiofileformats() (FFAudioFileReader.c), frame_size and frame_length are declared outside the per-stream loop and are only set conditionally:

  • frame_size is set only for PCM streams.
  • frame_length is set only if nb_frames, or a usable duration plus sample rate (and for compressed codecs, a fixed codec frame size), is available.

So in a multi-stream file, a compressed stream that follows a PCM stream reports the PCM stream's frame size and frame length. All other per-stream values are already reassigned on every iteration.

Fix

Reset frame_size and frame_length to -1 (NOT_SPECIFIED) at the start of each stream iteration.

Test

  • New resource test_pcm_vorbis.mkv (93 KB): stream 0 is PCM S16LE stereo 44.1 kHz, stream 1 is Vorbis mono 22.05 kHz, 0.5 s each. Matroska sets no nb_frames, and Vorbis has no fixed codec frame size, so neither value gets set for stream 1. It was generated with:
    ffmpeg -f lavfi -i "sine=frequency=440:sample_rate=44100:duration=0.5" -f lavfi -i "sine=frequency=880:sample_rate=22050:duration=0.5" -filter_complex "[0:a]aformat=channel_layouts=stereo[a0]" -map "[a0]" -map 1:a -c:a:0 pcm_s16le -c:a:1 libvorbis -q:a:1 0 -fflags +bitexact -map_metadata -1 test_pcm_vorbis.mkv
  • New TestFFAudioFileReader#testGetAudioFileFormatsPcmThenVorbisMKVFile. Before the fix it failed with expected:<-1> but was:<4> (Vorbis frame size inherited from the PCM stream). It passes after the fix.
  • Full suite on aarch64 macOS, JDK 25: 163 tests, 0 failures, 2 skipped (pre-existing).

🤖 Generated with Claude Code

create_ffaudiofileformats() declared frame_size and frame_length outside
the per-stream loop and only set them conditionally (frame_size only for
PCM, frame_length only if nb_frames or a usable duration and frame size
are available). A compressed stream following a PCM stream therefore
reported the PCM stream's frame size and frame length.

Reset both at the start of each iteration and add a PCM + Vorbis
Matroska test file covering the case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hendriks73
hendriks73 force-pushed the hendrik/multistream-frame-fields branch from 6006a88 to d92bb47 Compare October 22, 2026 09:45
@hendriks73
hendriks73 merged commit 4c17dac into dev Oct 22, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant