Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Reduce FLAC decoder buffer size (Read 1607 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Reduce FLAC decoder buffer size

I am trying to do a (realtime) streaming decode of a FLAC stream, however I noticed that the decoder will output chunks of audio. When I redirect the decoded audio to a file, I am seeing it being written to disk in approximately 2 second chunks (around 30000 bytes) Presumably there is some kind of buffering being done, either when reading the data or writing it. Is there a way to reduce this buffer size?

Re: Reduce FLAC decoder buffer size

Reply #1
Please explain in more detail what you're doing. What decoder are you using? How are you using it? On what operating system?
Music: sounds arranged such that they construct feelings.

Re: Reduce FLAC decoder buffer size

Reply #2
I am currently on macOS, and have tried to accomplish this with both `ffmpeg` and the `flac` CLI utility, which use libFLAC. I am sending data in realtime to the respective process set up to receive raw flac data from stdin and output raw decoded pcm audio to stdout. When reading data from stdout, I can only read it in large chunks of decoded audio and not frame by frame. I thought that perhaps there was an internal buffer used by libFLAC to store the decoded pcm data before it actually writes to stdout, however have not found anything yet in the source.

Re: Reduce FLAC decoder buffer size

Reply #3
How are you sending data in realtime? What process is 'spoon-feeding' the data the flac/ffmpeg and how does it know when to send data? From the problem statement it seems to me you are not throttling the readout.
Music: sounds arranged such that they construct feelings.

Re: Reduce FLAC decoder buffer size

Reply #4
I am sending data to the process' stdin with python, at a rate which approximately resembles realtime (send 128 bytes of data, sleep a bit, repeat).

> not throttling the readout.

Could you elaborate? I have a separate process continuously reading from the stdout and writes that to disk, whenever there is data available. And at the moment, whenever it reads, it does not receive only one frame but approximately 2 seconds worth of audio each time.

Re: Reduce FLAC decoder buffer size

Reply #5
I am sending data to the process' stdin with python, at a rate which approximately resembles realtime (send 128 bytes of data, sleep a bit, repeat).
That doesn't really work that way. The bitrate of FLAC is highly variable.

Anyway, I don't know where the problem is. Can you try using ffmpeg's -re option? That throttles decoding down to realtime. You'll have to use that option before your input. Presumably that means your command will be
ffmpeg -re -i - -f wav -

Could you elaborate? I have a separate process continuously reading from the stdout and writes that to disk, whenever there is data available. And at the moment, whenever it reads, it does not receive only one frame but approximately 2 seconds worth of audio each time.
It seems better to limit the output of flac or ffmpeg than it's input, because the input has a variable bitrate and the output a constant bitrate. But ffmpeg's -re option takes care of that anyway.
Music: sounds arranged such that they construct feelings.