Streaming conversion from most popular audio formats to mp3

1,449 views
Skip to first unread message

Tom

unread,
Apr 15, 2011, 7:06:27 AM4/15/11
to nod...@googlegroups.com
I'm receiving streams of audio files which can be of any format.

These streams are then proxied to a receiving client. However, this client can only accept mp3 file formats.

Thus, I need to convert the incoming stream to mp3 as it comes in.

Has any work been done in this field for node.js?

Any feedback is appreciated. Thanks.

Best regards,
Tom

Jann Horn

unread,
Apr 15, 2011, 7:27:20 AM4/15/11
to nod...@googlegroups.com

I would just pipe it through ffmpeg.

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

Tom

unread,
Apr 15, 2011, 12:11:30 PM4/15/11
to nodejs
@Jann Horn, I have to remove the stream from memory as soon as
possible.

Thus, I cannot wait for the stream to finish to process it.

Can ffmpeg convert the file while streaming without having to wait for
the file to finish uploading?

Also, do you have any idea howmuch of a performance difference this
would make compared to doing it with v8 (if that is possible at all)?

- Tom

On Apr 15, 1:27 pm, Jann Horn <jannh...@googlemail.com> wrote:
> I would just pipe it through ffmpeg.
>

Jann Horn

unread,
Apr 15, 2011, 12:41:39 PM4/15/11
to nod...@googlegroups.com
Am Freitag, den 15.04.2011, 09:11 -0700 schrieb Tom:
> @Jann Horn, I have to remove the stream from memory as soon as
> possible.
>
> Thus, I cannot wait for the stream to finish to process it.
>
> Can ffmpeg convert the file while streaming without having to wait for
> the file to finish uploading?

Yes, I'm relatively sure. There's even a nodejs lib for it:
https://github.com/schaermu/node-fluent-ffmpeg


> Also, do you have any idea howmuch of a performance difference this
> would make compared to doing it with v8 (if that is possible at all)?

As the ffmpeg guys made many optimizations, I don't think that you'd get
better results with a simple implementation in javascript.

Jann

signature.asc

Dean Landolt

unread,
Apr 15, 2011, 12:45:53 PM4/15/11
to nod...@googlegroups.com
It's also likely to be processor-bound, which means you'd have to kick it into a worker node and pay the subprocess startup and ipc piper anyway. So there's no tangible benefit to doing it in js.

rektide

unread,
Apr 15, 2011, 8:46:23 PM4/15/11
to nodejs
pipe it through a gst (gstreamer) pipeline. that's the easy route i
took for my node-knockout entry, which i cant even find atm.

Tom

unread,
Apr 16, 2011, 5:59:24 AM4/16/11
to nodejs
@Jann Horn,

I do not see how to input binary chunks one by one to ffmpeg.

The library you linked expects this kind of input:
new ffmpeg('/path/to/your_movie.avi')

Thus, it expects the movie/audio to be stored on the server. While I
only have chunks on the server temporarily, thus I need to feed it
these chunks one by one.

Any idea if this is still possible with ffmpeg?
>  signature.asc
> < 1KViewDownload

Floby

unread,
Apr 16, 2011, 7:54:26 AM4/16/11
to nodejs
Pipe it through gstreamer is what I'd do too. You just have to start a
child process and send the output as it comes. The only tricky part is
the options you have to give to gstreamer.
fluent-ffmpeg looks great but I think it's a great flaw in the design
not to allow to use raw streams (since I'm almost certain that ffmpeg
allows for piping data to it). I'm not expert at gstreamer though.
you'll have to read a bit of doc I guess. Unless someone has already
done a node module of it.

biscarch

unread,
Apr 17, 2011, 12:11:20 AM4/17/11
to nodejs
In the ffmpeg documentation pipe is listed as a valid network
protocol.

Also go here and look at the pipe documentation:
http://www.ffmpeg.org/ffmpeg.html#SEC56

pipe:0 = stdin, 1 = stdout, 2 = stderr

It is definitely possible to stream to ffmpeg.

also look at the creation of the ffmpeg child process here.
https://github.com/ChristopherBiscardi/Node-Icecast-Streamer

Good luck and let us know how you do.

-Chris Biscardi

Tom

unread,
Apr 17, 2011, 8:34:34 AM4/17/11
to nodejs
I have now suggested this feature to the author of node-ffmpeg.

As I do not have the knowledge required to work with audio, I think I
will move this down in my priority list and see if the feature has
been implemented once the need arises.

Thanks a lot for the help.

- Tom

On Apr 17, 6:11 am, biscarch <bisca...@sketcht.com> wrote:
> In the ffmpeg documentation pipe is listed as a valid network
> protocol.
>
> Also go here and look at the pipe documentation:http://www.ffmpeg.org/ffmpeg.html#SEC56
>
> pipe:0 = stdin, 1 = stdout, 2 = stderr
>
> It is definitely possible to stream to ffmpeg.
>
> also look at the creation of the ffmpeg child process here.https://github.com/ChristopherBiscardi/Node-Icecast-Streamer

Felix Geisendörfer

unread,
Apr 18, 2011, 6:46:38 PM4/18/11
to nod...@googlegroups.com
Hi,

we've done something similar over at transloadit.com, where we convert video file uploads with ffmpeg while they are still uploading [1].

All you basically need is to tell ffmpeg to read from stdin (-i -), and then pipe your data stream into your ffmpeg child process using Stream#pipe.

The linked article below also contains some inspiration in case you need to throttle the process through a file system cache.

One warning so: While ffmpeg says it can accept pipes as input, that's not always true. Some media formats have the annoying habit of putting their meta information at the end of the file, in which case ffmpeg will try to fseek() on the fd, causing a broken pipe. I don't think you'll have these problems with audio files so.

--fg

Tom

unread,
Apr 19, 2011, 5:25:52 AM4/19/11
to nodejs
That's very helpful Felix,

Thanks a lot. I will just pipe it to a ffmpeg child process.

- Tom
Reply all
Reply to author
Forward
0 new messages