Open njsmith opened 11 years ago
libsndfile has some facility to read from a PIPE (http://www.mega-nerd.com/libsndfile/FAQ.html#Q017), but I have never tried it. There may be a way to make this more friendly in python.
Right, the libsndfile part is fine, the problem is that the python wrapper api has no way to say " please give me N frames... or if the file ends before you've read N frames, then just give me what you got". The wrapper considers it a hard error if the file ends before all N frames are read.
(Compare the length argument to file.read, which is just an upper bound and you may get fewer bytes than requested.) On 16 Jan 2013 07:55, "David Cournapeau" notifications@github.com wrote:
libsndfile has some facility to read from a PIPE ( http://www.mega-nerd.com/libsndfile/FAQ.html#Q017), but I have never tried it. There may be a way to make this more friendly in python.
— Reply to this email directly or view it on GitHubhttps://github.com/cournape/audiolab/issues/14#issuecomment-12324696.
I want to read the audio out of a
.mov
file, so I'm doingThis calls avconv (from ffmpeg) to feed the data directly into my process (no need for temporary files), and that's great. But:
my_sndfile.nframes
contains nonsense: Okay, so I don't know how many frames to read, not a surprise given it's coming from a pipe. (It would be nice ifnframes
in this situation wereNone
or-1
or something; instead I'm getting2305843009213693945L
.)read_frames
with a large value, hoping to get all the frames, I get:Sort of frustrating... it's telling me it managed to read the frames, but... then it threw them away and raised an exception. So the frames are there, but it's impossible for me to get at them. I expected this to allow for a shorter return value, like POSIX
read
or Pythonfile.read
.The only solution I can see is to call
read_frames(1)
in a loop, which is silly, but there you go.