开发者

Streaming without Content-Length in response

I'm using Node.js, Express (and connect), and fluent-ffmpeg.

We want to stream audio files that are stored on Amazon S3 through http.

We have all working, except that we would like to add a feature, the on-the-fly conversion of the stream through ffmpeg.

This is working well, the problem is that some browsers checks in advance before actually getting the file.

Incoming requests containing the Range header, for which we reply wi开发者_C百科th a 206 with all the info from S3, have a fundamental problem: we need to know in advance the content-length of the file.

We don't know that since it is going through ffmpeg.

One solution might be to write out the resulting content-length directly on S3 when storing the file (in a special header), but this means we have to go through the pain of having queues to encode after upload just to know the size for future requests. It also means that if we change compressor or preset we have to go through all this over again, so it is not a viable solution.

We also noticed big differencies in the way Chrome and Safari request the audio tag src, but this may be discussion for another topic.

Fact is that without a proper content-length header in response everything seems to break or browsers goes in an infinite loop or restart the stream at pleasure.

Ideas?


This seems to be working for me.

It would be great if you could confirm whether it gives the expect results in your browsers too.

res.writeHead(200, {
                       'Transfer-Encoding': 'chunked'
                     , 'Content-Type': 'audio/mpeg'
                     , 'Accept-Ranges': 'bytes' //just to please some players, we do not actually allow seeking
});

Basically, you tell the browser that you are going to stream using chunked encoding. An issue may be that some browsers do not like streaming without know how much bytes they should expect in total.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜