andrewrk / node-waveform

simultaneously transcode audio and generate visuals - Node.js module
MIT License
101 stars 19 forks source link

using a stream instead of audio file? #5

Open hems opened 8 years ago

hems commented 8 years ago

I'm wondering if would be possible to generate the waveform from a file stream, so we could use big files and keep the memory down?

Does that make any sense?

andrewrk commented 8 years ago

It must scan the audio file to determine the correct duration, then it must seek to 0 and scan again to produce the waveform. It does not load the entire file into memory when doing this; each time it scans it streams from disk.

Are you observing a memory increase proportional to the size of the file you are scanning?

hems commented 8 years ago

@andrewrk my main interest would be to get a real time stream, for instance an online radio and feed it into node-waveform so then when the stream is finished, for instance a 10 hours stream it will take hopefully just a couple of seconds to generate the png ?

sorry i just have specified this use case on my initial description of the issue.

andrewrk commented 8 years ago

If you wanted to do that, you would have to know the duration of the stream before the stream starts.

It is however possible to generate a waveform whose size is proportional to the stream length without knowing the duration ahead of time. So then you'd end up with a png whose width was PixelsPerSecond * DurationInSeconds and PixelsPerSecond is up to you.

hems commented 8 years ago

good point!

on my use case i wouldn't know the size of the jpg since i don't know the length of the stream.

so perhaps i would need to keep appending to that json file representing the wav and just generate the image at the very end when i actually know the length of the stream...

do you think node-waveform would be a good place to house or a good tool in this case ?

andrewrk commented 8 years ago

node-waveform is a tiny wrapper around a command line program written in C: waveform. You could start by forking this project and deleting the PNG code, deleting the transcoding code, and modifying the JSON outputting code to output JSON relative to the duration of the input file instead of needing to know the duration.

Next you can work on making it work on a stream instead of an audio file. waveform depends on libgroove for audio input. libgroove 5.0.0 isn't released yet (coming soon!) but it supports opening audio based on a stream rather than a file. So this could be used to, for example have the CLI application process stdin and stream the JSON representation of the waveform to stdout.

So, a bit of work to be done to get what you want, but it's all possible.

There's also a waveform sink in libgroove 5.0.0 that generates waveform json. I'll consider adding a parameter that would put it in "streaming" mode, which would pretty much do exactly what you want. In this case, node-groove would be the module you would want.

hems commented 8 years ago

@andrewrk okie! i'll have a go / keep an eye open for node-groove ! thanks!