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: Real-time streaming FLAC using Netcat? (Read 5827 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Real-time streaming FLAC using Netcat?

Hi,
I'm trying to use FLAC to stream audio to a client with low-latency using netcat. On the server I'm using:
Code: [Select]
 parec --device=sink.monitor --rate=16000 --format=s16le --channels=1 -r |   flac --fast --endian=little --channels=1 --bps=16 --sample-rate=16000 --sign=signed --force-raw-format --stdout -  | nc -l $port


Most of the time, it's low latency. However, if there's silence, then the flac encoder buffers until the silence ends and doesn't send any data (I believe this is due to flac's run length encoding).

Is there a way to turn off this behavior in the flac encoder, perhaps by telling it to never buffer more than 100ms (our max allowable latency) worth of data before encoding?

If there is another codec that might be a better fit for this task, please let me know! I've already tried MP2 (using twolame) and MP3 (using lame), but no luck with those.

Thanks!
Rohan

Real-time streaming FLAC using Netcat?

Reply #1
Perhaps adding "--disable-constant-subframes" to your FLAC encoder options will help.

Real-time streaming FLAC using Netcat?

Reply #2
Perhaps adding "--disable-constant-subframes" to your FLAC encoder options will help.


Thanks! This seems to have worked, though it still buffers for about 1.5 seconds before sending the data. Can you explain a little bit what this option does (it doesn't seem to be documented and I'm not sure what subframes are) and if there are additional parameters that I could possibly tweak?

Thanks,
Rohan

Real-time streaming FLAC using Netcat?

Reply #3
FLAC takes its input stream of audio and chops it into frames, each a fraction of a second long in most cases.  Those frames are then separated by channels into different subframes and compressed.  Constant subframes are FLAC's way of telling the decoder that all the audio samples in that subframe will be the same (typically silence).  But naturally it has to walk all the way to the end of the silence before it can know all the samples are the same, which sounded like the problem you were having.

FLAC always needs a little buffering time in order to do compression on its subframes, but it's hard to get it to spend less time than --fast.  Beyond tweaking the block size (the amount of samples in each subframe), I'm not sure what else to try.

Real-time streaming FLAC using Netcat?

Reply #4
FLAC takes its input stream of audio and chops it into frames, each a fraction of a second long in most cases.  Those frames are then separated by channels into different subframes and compressed.  Constant subframes are FLAC's way of telling the decoder that all the audio samples in that subframe will be the same (typically silence).  But naturally it has to walk all the way to the end of the silence before it can know all the samples are the same, which sounded like the problem you were having.

FLAC always needs a little buffering time in order to do compression on its subframes, but it's hard to get it to spend less time than --fast.  Beyond tweaking the block size (the amount of samples in each subframe), I'm not sure what else to try.


Thanks for the explanation