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: Streaming FLAC over the Internet (Read 23826 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Streaming FLAC over the Internet

IMHO flac has one technical weakness that will prevent it taking off as THE standard -- namely it only has Variable Bit Rate compression algorithms. Which means that one cannot predict in advance the length of ouput file that will be generated for any input stream.

This is a problem when you want to transcode another format of audio file to flac and stream it over Http. The Http protocol requires sending a Content Length (number of bytes) header at the start of the streaming process. With flac you cannot know the number of bytes until after the full file has been transcoded. So this means that Http must either wait until the full transcoding has been completed, or alternatively if it wants to start streaming the data immediately, then it must provide some guessed value in its Content Length header (and this is not conformant to the Http specifications, and may cause problems in some music players...)

By contrast, if you are (say) transcoding to mp3 and streaming that via Http, then the transcoder can select a Constant Bit Rate compression algorithm. And in such a case, the Http Content Length is easily calculated in advance as being the input audio file's duration (in seconds) multiplied by the CBR rate (in bytes per second).

So if the flac standard were extended to allow both the existing Variable Bit Rate compression algorithm plus a new Constant Bit Rate option, then it would become much better suited for online streaming.

Streaming FLAC over the Internet

Reply #1
IMHO flac has one technical weakness that will prevent it taking off as THE standard -- namely it only has Variable Bit Rate compression algorithms. Which means that one cannot predict in advance the length of ouput file that will be generated for any input stream.

Name a single compressed lossless format that isn't VBR in nature.

Don't bother trying; one doesn't exist. Designing one would be futile since some signals must grow in size after being processed by a lossless compression algorithm in order for other signals to be compressible and satisfy the necessary requirement that they remain unique after being decompressed.


Streaming FLAC over the Internet

Reply #3
By definition, lossless compressed formats can't be CBR.

You could "abuse" the lossyWAV algorithm to make a near-lossless CBR-ish (maybe ABR, or at least capped bitrate) encoder fairly easily.

Cheers,
David.

Streaming FLAC over the Internet

Reply #4
The Http protocol requires sending a Content Length (number of bytes) header

Since when? I can’t speak for streaming media over HTTP, but regular data doesn’t require it. Also some radio stations provide flac streams.

Streaming FLAC over the Internet

Reply #5
It is true: all current compressed lossless formats suck, as far as Http streaming is concerned.


Definitely, this thread has gone offtopic, but your comments require an answer.

First:
Stream: a continuous (once received) set of data. Generally speaking, a set of data that is being transmitted from a source to a destination.

When the set of data has a determined size, then, it rarely is called stream, but a download or upload.
In other words, streams in internet tend to be of data for which the size is not determined. One such example is, obviously, a Live radio stream.

Second:
The HTTP ContentLength header can have the value of 0, which tells the browser that the size of the stream is not known beforehand.

In our job, we generate PDF files in realtime, and in some cases, start sending them before the file is fully generated (Like for files that can have several megabytes). In such cases, the file size is undetermined and, as such, the ContentLength that we send is zero.

Streaming FLAC over the Internet

Reply #6
If this is still relevant after [JAZ]'s clarification:

So if the flac standard were extended to allow both the existing Variable Bit Rate compression algorithm plus a new Constant Bit Rate option, then it would become much better suited for online streaming.


FLAC can deliver CBR. (Signal won't be compressed, though.)



Streaming FLAC over the Internet

Reply #9

First:
Stream: a continuous (once received) set of data. Generally speaking, a set of data that is being transmitted from a source to a destination.

When the set of data has a determined size, then, it rarely is called stream, but a download or upload.
In other words, streams in internet tend to be of data for which the size is not determined. One such example is, obviously, a Live radio stream.


One other example is UPnP / DLNA "streaming". In general that technology delivers pre-existing tracks. But they call it streaming. Don't argue with me. Argue with them...


Second:
The HTTP ContentLength header can have the value of 0, which tells the browser that the size of the stream is not known beforehand.

In our job, we generate PDF files in realtime, and in some cases, start sending them before the file is fully generated (Like for files that can have several megabytes). In such cases, the file size is undetermined and, as such, the ContentLength that we send is zero.


Yes. And I am sure you do...


Streaming FLAC over the Internet

Reply #11
By definition, lossless compressed formats can't be CBR.


I don't agree. What is it about the "definition" of lossless that says it can't be CBR. Please be specific.


It's not the “lossless” part, it's the “compression” part. (Edit: and then, I see, you write that you know.)

Streaming FLAC over the Internet

Reply #12
By definition, lossless compressed formats can't be CBR.


I don't agree. What is it about the "definition" of lossless that says it can't be CBR. Please be specific.


You were answered earlier on this very point.

Name a single compressed lossless format that isn't VBR in nature.

Don't bother trying; one doesn't exist. Designing one would be futile since some signals must grow in size after being processed by a lossless compression algorithm in order for other signals to be compressible and satisfy the necessary requirement that they remain unique after being decompressed.


You can choose not to "agree" all you want, but information theory is solid math.
Creature of habit.

Streaming FLAC over the Internet

Reply #13
By definition, lossless compressed formats can't be CBR.

You could "abuse" the lossyWAV algorithm to make a near-lossless CBR-ish (maybe ABR, or at least capped bitrate) encoder fairly easily.

Cheers,
David.


What about a ZIP format? IE All FLAC would be is a container for the WAV file. Is this possible without VBR?

Streaming FLAC over the Internet

Reply #14
What about a ZIP format? IE All FLAC would be is a container for the WAV file. Is this possible without VBR?


You mean, like when you store in a .zip without compressing? FLAC can do that. dBpoweramp also even supports conversion to uncompressed FLAC, likely to satisfy placebophiles who think it makes a difference.

WAV is a container, by the way.

Streaming FLAC over the Internet

Reply #15
What about a ZIP format? IE All FLAC would be is a container for the WAV file. Is this possible without VBR?


You mean, like when you store in a .zip without compressing? FLAC can do that. dBpoweramp also even supports conversion to uncompressed FLAC, likely to satisfy placebophiles who think it makes a difference.

WAV is a container, by the way.


Cool. I always forget WAV is a container. Just no error checking.

Personally VBR is fine. Just make sure HTTP can steam the max value.

Streaming FLAC over the Internet

Reply #16
I am speaking of UPnP / DLNA audio renderers. If you don't provide a Content Length, then the player cannot support Seek.


We mostly agree, but now think about this. If the DLNA renderer allows the user to seek your realtime-generated stream, what will you do if the user seeks backwards?
Also, depending on the DLNA server/renderer, the content might be fully "downloaded" before it starts to play.


Streaming FLAC over the Internet

Reply #18
You can choose not to "agree" all you want, but information theory is solid math.


I don't dispute information theory. Indeed I am prepared to bet that I know more about the math of information theory than you do...

Nevertheless information theory has nothing to say about algorithms that can losslessly compress a data stream at a predetermined number of bytes per second. For example let us try the following algorithm: The flac encoder has nine levels of aggressivity in its compression. So let us start compressing a file at (say) grade 5. After (say) one second let us see if the compressed output is smaller or larger than our target CBR BPS. If smaller then let us back off on the compression aggressivity grade by one grade, and if larger then let us tighten the compression aggressivity by one grade. Repeat every second. So long as you are not over aggressive on choosing your target CBR BPS, then statistically speaking, you will end up with an output file that is dead on the target CBR BPS. Of course there will be Gaussian curve outliers. But, statistically this algorithm will center its statistical Gaussian peak on the selected target CBR BPS. And the longer the file, the closer it will get to the target CBR BPS...

If you want to submit some math to prove me wrong, please feel free to do so.

Streaming FLAC over the Internet

Reply #19

... now think about this. If the DLNA renderer allows the user to seek your realtime-generated stream, what will you do if the user seeks backwards?


That is absolutely no problem. The server can always seek backwards to an earlier time offset in its cache of what has already been transcoded. It is actually a bit more difficult to seek forwards: In such a case, the server obviously cannot seek forward into a not yet transcoded cache. Instead the server needs to abandon the current running transcoder process and start another transcoder process starting at a forward time offset into the original source file.

This can only work if the server has given a reasonably accurate Content Length value: If the user seeks to (say) half way through the file, then the renderer makes a Byte-Range seek to Content Length x 0.5. Obviously if Content Length is not existing then this cannot work. And if the provided Content Length is wildly inaccurate then the seek may not end up in the expected place. And if the provided Content Length is way too long, then the seek may end up trying to go beyond the end of the final transcoded actual file...


Also, depending on the DLNA server/renderer, the content might be fully "downloaded" before it starts to play.


If the renderer has fully downloaded the track, then indeed it has full knowledge about the actual track length, so it can process seek requests accurately. However most users are not willing to wait until a track has fully downloaded before starting to play it. This therefore requires a predictive approach towards the seek algorithm. And this is why I think that flac needs to provide a predictive method of estimating a Content Length before the full file has actually been transcoded...

Streaming FLAC over the Internet

Reply #20
What about a ZIP format? IE All FLAC would be is a container for the WAV file. Is this possible without VBR?


You mean, like when you store in a .zip without compressing? FLAC can do that. dBpoweramp also even supports conversion to uncompressed FLAC, likely to satisfy placebophiles who think it makes a difference.

WAV is a container, by the way.


There are some VERY SPECIAL people in this world

For curiosity sake, what are the commands for uncompressed FLAC files in dBpoweramp?

Streaming FLAC over the Internet

Reply #21
For curiosity sake, what are the commands for uncompressed FLAC files in dBpoweramp?


I also would be interested to know if there are any commands for uncompressed flac output in either flac.exe or sox.exe? (As far as I can tell, this is not possible in flac.exe or sox.exe and the only way to do it is to either use libflac.dll or to compile your own wrapper around the flac source code libraries. But I would be delighted if anyone can explain otherwise...)




Streaming FLAC over the Internet

Reply #23
I also would be interested to know if there are any commands for uncompressed flac output in either flac.exe or sox.exe? (As far as I can tell, this is not possible in flac.exe or sox.exe and the only way to do it is to either use libflac.dll or to compile your own wrapper around the flac source code libraries. But I would be delighted if anyone can explain otherwise...)

We had this here:
http://www.hydrogenaudio.org/forums/index....964&hl=4608
Is troll-adiposity coming from feederism?
With 24bit music you can listen to silence much louder!

Streaming FLAC over the Internet

Reply #24
If you want to submit some math to prove me wrong, please feel free to do so.

That's a use of the flying spaghetti monster defense we don't typically see with some argument from authority sprinkled in which we do typically see.

Despite your insistence that you're smarter than the rest of us, I think I'll wait until I see your idea put into action and take note of what those CBR bitrates actually are, thanks.  I won't be holding my breath on the bitrates being interesting, let alone the idea being implemented; in other words, I think we'll chalk this up as a fail on your part after it is all said and done.

In the meantime, does anyone know of a program that displays a histogram of bitrates from flac and hopefully some of the other more popular lossless formats?

There we go a CBR Lossless format

Sure, but we already covered that.