22

We need to capture a live video stream from WebRTC (or any other capturing mechanism from the client webcam, even if it is not supported on all browsers, but as a PoC).

This live video needs to be handled by a server component (ASP.Net MVC / Web API), I imagine that the code on the server will look like:

[HttpPost]
public ActionResult HandleVideoStream(Stream videoStream)
{
      //Handle the live stream
}

Looking for any keyword or helpful link.

We have already implemented a way to send individual frames using base64 jpg, but this is not useful at all, because there is a huge overhead of the base64 encoding and because we could use any video encoding to send the video more efficiently (send the difference between the frames using VPx -vp8- for example), the required solution needs to capture a video from the webcam of the client and send it live (not recorded) to the server (asp.net) as a stream -or chunks of data representing the new video data-.

Saw
  • 6,199
  • 11
  • 53
  • 104
  • 6
    This is requesting for an offsite tool and resource, and is also extremely broad. – Benjamin Trent Aug 11 '15 at 18:48
  • how about trying out some media server, kurento for example, the important question here is what do you want to do with the live video on your server. – mido Aug 24 '15 at 02:22
  • The ultimate goal is to process it in the realtime (using a native C++ code, but to for now it is fine to save the webm chunks to the disk! Yesterday I have checked that media server, but it works only on Linux, is there a way to run it on Windows ? Is there another media server for Windows? – Saw Aug 24 '15 at 05:45
  • @MohamedSakherSawan Do you mean a WebRTC compatible media server or any media server? – aergistal Aug 24 '15 at 08:53
  • In the end, what do you want to do with your video stream? Do you want to have chat-like capabilities? – radu-matei Aug 24 '15 at 09:43
  • As I mentioned befor, the ultimate goal is to process the video in the realtime using native c++ code and return the feedback to the customer. – Saw Aug 24 '15 at 09:45
  • Is real-time an issue here? – radu-matei Aug 24 '15 at 09:50
  • To be honest it is the main issue, 1-2 seconds latency is fine, but not more! – Saw Aug 24 '15 at 10:05
  • If you need to process the video in real-time using C++ you must also be able to decode the frames to get the raw data. The OpenCV project can help you with that and they provide a C++ interface, no need to pass by ASP. – aergistal Aug 24 '15 at 13:01
  • I know that, my main issue is to get the stream to the server, after that I am done, I have endless ways to handle it! – Saw Aug 24 '15 at 13:02
  • Like I suggested in my answer one idea is to use another server. Eg; Flash browser capture via RTMP to the Nginx RTMP module which then `exec`s ffmpeg and pushes the stream to your application in whatever format you like (rawvideo?). This way you can also scale the solution and forward different streams to different processing servers if needed. – aergistal Aug 24 '15 at 13:14

3 Answers3

13

Your question is too broad and asking for off-site resources is considered off-topic on stackoverflow. In order to avoid opinion-prone statements I will restrict the answer to general concepts.

Flash/RTMP

WebRTC is not yet available on all browser so the most widely used way of capturing webcam input from a browser currently in use is via a plugin. The most common solution uses the Adobe Flash Player, whether people like it or not. This is due to the H.264 encoding support in recent versions, along with AAC, MP3 etc. for audio.

The streaming is accomplished using the RTMP protocol which was initially designed for Flash communication. The protocol works on TCP and has multiple flavors like RTMPS (RTMP over TLS/SSL for encryption), RTMPT(RTMP encapsulated in HTTP for firewall traversal).

The stream usually uses the FLV container format.

You can easily find open-source projects that use Flash to capture webcam input and stream it to an RTMP server.

On the server-side you have two options:

  • implement a basic RTMP server to talk directly to the sending library and read the stream
  • use one of the open-source RTMP servers and implement just a client in ASP (you can also transcode the incoming stream on the fly depending on what you're trying to do with your app).

WebRTC

With WebRTC you can either:

  • record small media chunks on a timer and upload them on the server where the stream is reconstructed (needs concatenating and re-stamping the chunks to avoid discontinuities). See this answer for links.
  • use the peer-to-peer communication features of WebRTC with the server being one of the peers.

A possible solution for the second scenario, which I haven't personally tested yet, is offered by Adam Roach:

  1. Browser retrieves a webpage with javascript in it.
  2. Browser executes javascript, which:
    1. Gets a handle to the camera using getUserMedia,
    2. Creates an RTCPeerConnection
    3. Calls createOffer and setLocalDescription on the RTCPeerConnection
    4. Sends an request to the server containing the offer (in SDP format)
  3. The server processes the offer SDP and generates its own answer SDP, which it returns to the browser in its response.
  4. The JavaScript calls setRemoteDescription on the RTCPeerConnection to start the media flowing.
  5. The server starts receiving DTLS/SRTP packets from the browser, which it then does whatever it wants to, up to and including storing in an easily readable format on a local hard drive.

Source

This will use VP8 and Vorbis inside WebM over SRTP (UDP, can also use TCP).

Unless you can implement RTCPeerConnection directly in ASP with a wrapper you'll need a way to forward the stream to your server app.

The PeerConnection API is a powerful feature of WebRTC. It is currently used by the WebRTC version of Google Hangouts. You can read: How does Hangouts use WebRTC.

Community
  • 1
  • 1
aergistal
  • 29,947
  • 5
  • 70
  • 92
  • Thank you for your great answer, do you have any thoghts about live video streaming from beowser in iOS – Saw Aug 29 '15 at 22:19
  • Thanks. For iOS you're out of luck, you can forget about `WebRTC` at the time of this post. You can however record a webcam clip with a `` in iOS 6+ but it's not live. For live-streaming you must build an app like Periscope which apparently uses `RTMP`. There's are third party libs for iOS. – aergistal Aug 30 '15 at 08:22
  • We already have our own app to do that, I think we can cover almost all modern browsers (mobile and desktop) apart from iOS and maybe Opera lite with those two options you have mentioned. – Saw Aug 30 '15 at 08:57
  • Great answer. Thanks for all of the info. Wowza now supports WebRTC - check out https://www.wowza.com/products/capabilities/webrtc-streaming-software – caveman Dec 21 '16 at 22:49
5

Agreed that this is an off-topic question, but I recently bumped into the same issue/requirement, and my solution was to use MultiStreamRecorder from WebRTCExperiments. This basically gives you a "blob" of the audio/video stream every X seconds, and you can upload this to your ASP.NET MVC or WebAPI controller as demonstrated here. You can either live-process the blobs on the server part by part, or concatenate them to a file and then process once the stream stops. Note that the APIs used in this library are not fully supported in all browsers, for example there is no iOS support as of yet.

My server side analysis required user to speak full sentences, so in addition I used PitchDetect.js to detect silences in the audio stream before sending the partial blob to server. With this type of setup, you can configure your client to send partial blobs to server after they finish talking, rather than every X seconds.

As for achieving 1-2 second delay, I would suggest looking into WebSockets for delivery, rather than HTTP POST - but you should play with these options and choose the best channel for your requirements.

Bora B.
  • 175
  • 2
  • 7
  • The thing I don't like about `MediaStreamRecorder` is that it can't capture the same format (eg. in Firefox A/V in WebM and Chrome A in WAV and V in WebM) – aergistal Aug 29 '15 at 12:38
0

Most IP cameras these days will use H264 encoding, or MJPEG. You aren't clear about what sort of cameras are being used.

I think the real question is, what components are out there for authoring/editing video and which video format does it require. Only once you know what format you need to be in, can you transcode/transform your video as necessary so you can handle it on the server side.

There are any number of media servers to transform/transcode, and something like FFMPEG or Unreal Media Server can transform, decode, etc on server side to get it to some format you can work with. Most of the IP cameras I have seen just use an H264 web based browser player.

EDIT: Your biggest enemy is going to be your delay. 1-2 seconds of delay is going to be difficult to achieve.

  • Low latency streaming is not difficult to achieve. The `x264` encoder for example has a `zerolatency` tuning option and you can also stream MJPEG with a delay in the order of miliseconds if the bandwidth supports it. – aergistal Aug 27 '15 at 07:50