0
votes

I want node.js to convert an extremly long audio file to mp3, and the second data is available on stdout, node.js should send it to the client for them to play.

I've written the following, and while it works, the html5 audio/video tag waits until ffmpeg is 100% done transcoding, where-as I want to start playing the video while ffmpeg is doing its thing.

var ffmpeg = childProcess.spawn('ffmpeg', [
   '-i', params.location, //location of the specified media file
   '-f', 'mp3',
   'pipe:1'
 ]);
 res.writeHead(200, {
   'Content-Type': 'audio/mp3'
 });
 ffmpeg.stdout.pipe(res);

EDIT 1: Not sure why, but if params.location points to a movie everything seems to work. But if its an audio file, ffmpeg doesn't seem to be outputting to stdout until its 100% converted.

EDIT 2: Turns out that you can't dump an mp4 file to stdout due to the fact that mp4 files are non Causal (http://en.wikipedia.org/wiki/Causal_system). THerefore if you use webm it works. Just make sure to compile ffmpeg with webm support (for homebrew users: brew install ffmpeg --with-vpx --with-vorbis ).

I've uploaded a github gist showing two functions to send live mp3/webm transcodes: https://gist.github.com/cobookman/c1a9856a4588496b021a

1
Turns out it was due to prams.location pointing to an mp3 file. Still not sure how to get ffmpeg to pipe an mp3 file being re-transcoded with a lower bitrate.blasteye
So couldn't ever figure out how to get ffmpeg to play nice, so I'm now using lame for * audio->mp3, and ffmpeg for * video -> webm/h.264. Not sure whats wrong with ffmpeg.blasteye

1 Answers

0
votes

I don't know why this isn't working for you, as I have almost the exact same code in my applications. The difference is that I am using - instead of pipe:1 for the output. Try that.

The other thing I suggest is reading from FFmpeg's stderr so that you can see if there is any odd output from FFmpeg that may give you clues as to what is going on.