Skip to content

AudioSegment broken for current avprobe (12.3) #285

@markkohdev

Description

@markkohdev

Steps to reproduce

  1. Upgrade to avprobe 12.3 on Mac osX
  2. Try to run AudioSegment.from_file() on an audio file

Expected behavior

AudioSegment should return segment data based on avprobe output

Actual behavior

AudioSegment hits a KeyError

  File "/dejavu/dejavu/decoder.py", line 51, in read
    audiofile = AudioSegment.from_file(filename)
  File "/dejavu/.venv/lib/python3.6/site-packages/pydub/audio_segment.py", line 664, in from_file
    if (audio_streams[0]['sample_fmt'] == 'fltp' and
KeyError: 'sample_fmt'

the new version of avprobe has added a line break to the line containing the sample_fmt.

Avprobe output used to look like this (partial output)

Input #0, mp3, from '/audio/track.mp3':
  Duration: 00:00:33.70, start: 0.000000, bitrate: 232 kb/s
    Stream #0:0: Audio: vorbis, 44100 Hz, stereo, fltp, 320 kb/s

but now looks like this (note the additional line break)

Input #0, mp3, from '/audio/track.mp3':
  Duration: 00:00:33.70, start: 0.000000, bitrate: 232 kb/s
    Stream #0:0: Audio: vorbis
      44100 Hz, stereo, fltp, 320 kb/s

so the parsing of this line https://github.com/markkohdev/pydub/blob/master/pydub/utils.py#L262 no longer works, consequently not setting sample_fmt on this line https://github.com/markkohdev/pydub/blob/master/pydub/utils.py#L291

Thus, this key does not exist and this line fails
https://github.com/markkohdev/pydub/blob/master/pydub/audio_segment.py#L664

The solution to this seems to be to update the utils file regexes to handle the new format, or to use a safe .get('sample_fmt', '<default>') in the audio segmenter

Your System configuration

  • Python version: 3.6
  • Pydub version: 0.22.0
  • ffmpeg or avlib?: avlib
  • ffmpeg/avlib version: 12.3

Is there an audio file you can include to help us reproduce?

schubert.ogg.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions