Skip to main content

Notice

Please be aware that much of the software linked to or mentioned on this forum is niche and therefore infrequently downloaded. Lots of anti-virus scanners and so-called malware detectors like to flag infrequently downloaded software as bad until it is either downloaded enough times, or its developer actually bothers with getting each individual release allow listed by every single AV vendor. You can do many people a great favor when encountering such a "problem" example by submitting them to your AV vendor for examination. For almost everything on this forum, it is a false positive.
Topic: Real-time streaming FLAC using Netcat? (Read 4597 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

 
SimplePortal 1.0.0 RC1 © 2008-2021