beetbox / audioread

cross-library (GStreamer + Core Audio + MAD + FFmpeg) audio decoding for Python
MIT License
482 stars 108 forks source link

Support for Seeking to a frame? #71

Open pconerly opened 5 years ago

pconerly commented 5 years ago

Hello, Are there any plans to support seeking to a specific frame?

I'm writing a small app that shows a song's Hz spectograph and, and allows play/pausing of the song along with the spectograph. Play/pause works great, but I'd like a way to reset what frame we're reading from. (That would allow to the user to "stop" and set the time to 0, or click on a spot and seek to that spot.)

I found that the OSX AudioToolbox backend has ExtAudioFileSeek: https://developer.apple.com/documentation/audiotoolbox/1486821-extaudiofileread?language=objc

And Python aifc has:

aifc.rewind()
aifc.setpos(pos)

https://docs.python.org/3.6/library/aifc.html

Backends to investigate:

sampsyo commented 5 years ago

Great idea! This might be hard to support in some backends, like the ffmpeg one, but that shouldn't stop us from adding it to backends where it's easy/possible.

One thing to remember is that we'll want a consistent story for what happens when you seek too far or backwards, if that's disallowed (silent no-op? immediate exception? exception after trying to read post-seek?).

pconerly commented 5 years ago

@sampsyo I think I'd vote for an immediate exception, so that users can take their own action. But also, I investigated the backends and I think it's possible to do with all of them.

I'm gonna try adding it to one of the backends and then submit a PR that we can chat about.