TeamPyOgg / PyOgg

Simple OGG Vorbis, Opus and FLAC bindings for Python
The Unlicense
63 stars 27 forks source link

Allow opening OpusFile/OpusFileStream from memory. #91

Open ijc8 opened 3 years ago

ijc8 commented 3 years ago

Modifies OpusFile/OpusFileStream's __init__() to accept a path or buffer and call the appropriate libopusfile function (op_open_file or op_open_memory, respectively).

Resolves #90.

bernardohenz commented 2 years ago

Hi @ijc8 , I'm looking exactly for this, but for loading a VorbisFile. I'm trying to adapt your code to vorbis, but I couldn't find the equivalent of opus.op_open_memory for the vorbis. Do you have any idea how to open a VorbisFile from memory?

ijc8 commented 2 years ago

Hey @bernardohenz! I haven't tried it myself, but it should be possible using vorbis.ov_open_callbacks from libvorbisfile as mentioned here.

It looks like that's what opus.op_open_memory does under the hood. You could use opusfile's read-from-memory callbacks as a model, though this may be a little more painful to implement in Python with ctypes. (See here for how to use Python functions as C callbacks.)