Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioSegment broken for current avprobe (12.3) #285

Closed
markkohdev opened this issue Jun 5, 2018 · 5 comments
Closed

AudioSegment broken for current avprobe (12.3) #285

markkohdev opened this issue Jun 5, 2018 · 5 comments

Comments

@markkohdev
Copy link

markkohdev commented Jun 5, 2018

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

@ElizarovEugene
Copy link

ElizarovEugene commented Jun 8, 2018

I have the same issue :(
Python 2.7.10
Pydub version: 0.22.0
ffmpeg or avlib?: avlib
ffmpeg/avlib version: 12.3

and MacOS 10.13.5

@skar404
Copy link
Contributor

skar404 commented Jun 13, 2018

Error in version Pydub 0.22.0, not problem in 0.21.0

info:
Python 3.6.4
ffmpeg or avlib?: ffmpeg
ffmpeg 9.1.0
macOS 10.13.4

@skar404
Copy link
Contributor

skar404 commented Jun 13, 2018

Fix line: https://github.com/jiaaro/pydub/blob/master/pydub/audio_segment.py#L664

replace audio_streams[0]['sample_fmt'] with audio_streams[0].get('sample_fmt')

@jiaaro
Copy link
Owner

jiaaro commented Jun 14, 2018

I will apply the patch in #290 as a temporary fix, but long term we should switch to using ffprobe’s json output instead of parsing the human readable output with a regex. If I have time I’ll look at that approach first.

@markkohdev Thank you for taking the time to write this detailed report :)

@skar404
Copy link
Contributor

skar404 commented Jun 14, 2018

@jiaaro I've rewritten the regular expression, now it should be suitable for all cases (but still not all tests pass on macOS)

@jiaaro jiaaro closed this as completed Jun 15, 2018
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

No branches or pull requests

4 participants