Skip to content

Fix ffmpeg backend misidentifying metadata as audio stream info#157

Open
gaoflow wants to merge 1 commit into
beetbox:mainfrom
gaoflow:fix/ffdec-metadata-audio-colon
Open

Fix ffmpeg backend misidentifying metadata as audio stream info#157
gaoflow wants to merge 1 commit into
beetbox:mainfrom
gaoflow:fix/ffdec-metadata-audio-colon

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 25, 2026

Copy link
Copy Markdown

What

When a file's metadata contains the substring "audio:" (e.g. a
description tag whose value reads "audio: broken"), _get_info() in
the ffmpeg backend stops reading stderr on that metadata line instead of
continuing until the real stream descriptor (Stream #N:M: Audio: …).
This silently produces channels = 0, samplerate = 0, and duration = 0
for the decoded file, which causes playback failures downstream.

Why it happens

# ffdec.py – before fix
elif 'audio:' in line:     # matches metadata lines too
    out_parts.append(line)
    self._parse_info(''.join(out_parts))
    break

ffmpeg prints file metadata before the stream table, so any tag whose
value contains "audio:" hits this branch first:

Input #0, mp3, from 'out.mp3':
  Metadata:
    description     : audio: broken   ← wrong line matched here
    ...
  Duration: 00:00:02.04, ...          ← never reached
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, ...

Fix

Require 'stream #' to also be present on the matched line. ffmpeg
always prefixes stream entries with Stream #N:M:, so the real audio
line always contains both substrings, while metadata value lines never
contain 'stream #'.

elif 'stream #' in line and 'audio:' in line:

Closes #119.


This pull request was prepared with the assistance of AI, under my direction and review.

When a file's metadata contains the substring "audio:" (e.g. a
description tag reading "audio: broken"), _get_info() would stop reading
ffmpeg's stderr on that metadata line instead of continuing to the real
stream descriptor ("Stream #N:M: Audio: …").  This caused all three
parsed values – channels, samplerate, and duration – to be silently set
to 0.

The fix requires the matched line to also contain "stream #", which is
always present in ffmpeg's stream info lines but never in metadata lines.

Fixes beetbox#119.
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.

Incorrect number of channels with ffmpeg

1 participant