kkroening/ffmpeg-python

Read from an audio file while it is being written to.

sagalpreet opened this issue · 0 comments

I have a use case where contents to an audio file are being written by a different process. I want to simultaneously read the file. I am trying to do so as follows:

print('Opening stream ...')
process = ffmpeg.input(
    'path/to/audio/file'
).output(
    'pipe:',
    format='f32le',
    acodec='pcm_f32le',
    ac=channels,
    ar=samplerate,
    loglevel='quiet',
).run_async(pipe_stdout=True)

Then, I read the content as follows:

while True:
    data = process.stdout.read(read_size)
    # process data

The problem in reading this way is that even when more data has been written to the file, ffmpeg is not able to read it.
Is there a way to accomplish what I am trying to do using ffmpeg ?

Thanks.