Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Webm live stream server: issues with <video> tag

I'm using Node.js as stream server to stream realtime Webm videos that is sent by FFMPEG (executed from another application, the stream is done via HTTP) and received by a webapp that uses the tag.

This is what I'm doing: FFMPEG streams the received frames using the following command:

ffmpeg -r 30 -f rawvideo  -pix_fmt bgra -s 640x480 
-i \\.\pipe\STREAM_PIPE -r 60 
-f segment  -s 240x160 -codec:v libvpx  -f webm 
http://my.domain.com/video_stream.webm

(the stream comes from an application that uses the Kinect as source and communicates with FFMPEG through a pipe, sending one frame after another)

When the webapp connects, it receives immediately this response from the server:

HTTP/1.1 200 OK
X-Powered-By: Express
content-type: video/webm
cache-control: private
connection: close
Date: Fri, 06 Dec 2013 14:36:31 GMT

and a Webm header (previously stored on the server, with the same resolution and frame rate of the source stream and tested as working on VLC) is immediately appended. Then the webapp starts to receive the data streamed by FFMPEG. Here is a screenshot of Mkvinfo GUI showing the fields of the header:

Header screenshot

However, even if the Network tab of the Chrome console shows that there is an actual stream of data (meaning that what is streamed is not completely garbage, otherwise the connection would be dropped), the player doesn't display anything. We tried to manually prepend our header to the dumped video received by the webapp and VLC plays it just fine, but this is not happening with the tag.

What can cause this problem? Are we missing something about the encoding on the FFMPEG side or we stored wrong values on the header (or they're not enough)?

PS: I cannot rely on an extern stream server.

PPS: We tried the following experiments:

  • substituting the video header with the one stored in the server makes the video playable on both vlc and video tag
  • if we dump the video that is already started (without an header) and we prepend the video header stored in the server or even its original header, the video is playable in VLC but not on the tag (we're carefully prepending the header just before the beggining of the cluster).
like image 317
breathe0 Avatar asked Dec 06 '13 15:12

breathe0


1 Answers

There so many variables added to this problem when considering you're using a technology outside of(and not integrated into) node to stream your video. This could cause issues with the loadbalancer or proxy you are using, or it could be that you're hosting 2 applications on the same port.

Could you do the streaming in just node? Or could you even just stream ffmpeg to the filesystem and stream that with node.fs.readStream()? This would reuse the same webserver instead of spawning an entirely new server on the same box. And if youre just streaming that content from point to point, then you need to buffer the data coming through and forward the buffer as a stream through node.

The reason why technologies get integrated, wrapped, and extended into other frameworks is for reasons of uniformity. Reading your question, though its well detailed, it still leaves a lot aloof. This could lead into question about how ffmpeg converts and serves http content, and how your loadbalancer/proxy handles that. Does node have anything to do with this? Is there a replacement for ffmpeg so you can standardize around node's framework? Is node right for this applications?

like image 147
tsturzl Avatar answered Oct 07 '22 04:10

tsturzl