Android IOS WebRTC Audio Video Development Summary (85)--using WebRTC broadcast webcam video (bottom)

Source: Internet
Author: User

This article mainly introduces WEBRTC (we translate and collation, translator: Weizhenwei, check: Blacker), the earliest published in the " Weaving wind net "

Support original, reprint must indicate the source, welcome attention to my public number blacker (Id:blackerteam or WEBRTCORGCN).

Review: Android IOS WebRTC Audio Video Development Summary (83)--using WebRTC broadcast webcam video (top)

Connect webcam

As mentioned above, we use a simple D-link dcs-7010l webcam. The key reason is that it supports the RTSP protocol, so the server can get the video stream from the camera.

We use plug-in wiring to connect the camera to the router. After the camera is turned on, the router is identified by the DHCP protocol and the IP address is obtained, which is 192.168.1.34. If you turn on the router settings, you will find a connected device DCs 7010, which is our camera. Now start testing this webcam.

Open 192.168.1.34 in the browser, enter the Web management interface of the camera, the password default is empty.

As you can see, the video stream of the camera on the admin panel is playing smoothly. However, we can still see the phenomenon of jitter. That's the problem we're going to fix with WEBRTC.

Configuring the Webcam

First, we disable the authentication feature. For testing purposes, we allow anyone to watch the broadcast. Specifically, go to the setup-Network page and set authentication to Disable.

On the same Setup screen, we check that the RTSP protocol port is correct and the default is 554. The output video format is determined in the grade. You can set it to 3 grades, but we use the first LIVE1.SDP, which has been configured for audio and video separately for both H. x and G.711. Any settings you make here can be modified by Setup-audio and Video .

Now we can test the camera via RTSP. Open the VLC player (or any other player that supports the RTSP protocol, such as Quicktime,window Media player,realplayer, etc.), open the URL dialog box to set the camera's RTSP address: rtsp:// 192.168.1.34/LIVE1.SDP.

OK, it works as expected. The camera sends a video stream to the player via RTSP.

In addition, the video stream plays very smoothly without any flaws. We expect WEBRTC to behave the same way.

Installing the server

At this point, the camera has been installed and tested with a desktop player. We are ready to use the server for broadcasting. With the help of the Whatismyip.com website, you can determine that the camera's extranet IP address is 178.51.142.223. Now you need to configure the router to redirect all RTSP requests sent over 554 ports to the webcam.

To open the router's corresponding settings page:

and use Telnet to check the extranet IP address and the RTSP port:

Telnet 178.51.142.223 554

After determining that the port can respond to the request, we begin to install the WEBRTC server.

Hosting services we use the Amazon EC2 CentOS 64-bit server. To reduce performance issues, we chose to configure an M3.medium instance of Vcpus:

Of course, there are linode and Digitalocean to choose from, but this time we decided to use Amazon. For the example to work, we need to configure the ports on the AmazonEC2 Control Panel, which are required for both WEBRTC and RTSP/RTP. If you also want to test the sample, make sure that the Amazon receive traffic panel is configured as follows:

The configuration of the Digitalocean is simpler, you only need to close these ports at the firewall, or disable them completely. Based on our experience using Digitalocean, they provide static IPs that are not confused with Nat. As a result, Digitalocean does not need to configure ports like Amazon.

As a service-side software for broadcast RTSP/RTP to WEBRTC, we use WEBRTC media broadcast Server Software Flashphoner. The streaming media server is much like a wowza that can broadcast RTSP/RTP through Flash. The only difference is that Flashphoner transmits streaming media through WEBRTC instead of flash. Technically, this means that the browser and server communicate through DTLS, establish SRTP sessions, and transmit VP8 encoded video streams to the audience.

Next, install the SSH required by the server.

The complete Server Software Installation checklist is as follows:

1. Download the Server Software
$wget flashphoner.com/downloads/builds/wcs/3.0/x8664/wcs3_video_vp8/flashphonermediaserverwebrtc-3.0/ Flashphonermediaserverwebrtc-3.0.868.tar.gz

2. Extracting software
$tar-xzf flashphonermediaserverwebrtc-3.0.868.tar.gz

3. Installing the Software

$CD FlashphonerMediaServerWebRTC-3.0.868
$./install.sh

Configure the server's extranet IP address: 54.186.112.111, intranet IP address: 172.31.20.65.

4. Turn on the service

$service webcallserver Start

5. Check the log

$tail-f/usr/local/flashphonerwebcallserver/logs/server_logs/flashphoner.log

6. Confirm that the service is running

$ps aux | grep Flashphoner

7. Install and open Apache service

$yum Install httpd
$service httpd Start

8. Download the Web file and place it in the Apache default directory/var/www/html

Cd/var/www/html
$wget Github.com/flashphoner/flashphoner_client/archive/wcs_media_client.zip
$unzip Webrtc_media_client.zip

9. Configure the IP address of the server in configuration file Flashphoner.xml.

10. Turn off the firewall

$service iptables Stop

Theoretically, you should configure firewall ports and rules in step 10th instead of shutting it down. But for testing purposes, we shut down the firewall directly.

Configure the server

Our WEBRTC Broadcast service architecture is as follows:

We have configured the nodes in the diagram, and now we need to configure the arrow connections between the nodes.

Web client is responsible for the interconnection between browser and WEBRTC, can download source code from GitHub. Js,css and HTML files are uploaded to the/var/www/html directory during installation (Nineth step).

Browser-server communication is configured in Flashphoner.xml, where we write to the server's extranet IP address, so that the Web client can webrtc the server through the HTML5 websocket connection.

OK, we've configured the server, now let's test it:

Open the Web Client index page in the browser index.html:

HTTP://54.186.112.111/WCS_MEDIA_CLIENT/?ID=RTSP://WEBRTC-IPCAM.DDNS.NET/LIVE1.SDP webrtc-ipcam.ddns.net is a free domain name from the noip.com dynamic Domain name server that connects to our extranet IP address. Also, we have configured the router to redirect RTSP requests sent to 192.168.1.34 according to NAT rules.

Parameter ID=RTSP://WEBRTC-IPCAM.DDNS.NET/LIVE1.SDP sets the URL of the video stream. The WEBRTC server obtains the video stream from the webcam, processes it and broadcasts it to the browser using WEBRTC. Your router may support DDNS, and if not, you can use the camera option:

The following is the setup of DDNS in the router:

Finally, let's test the system to see the results.

Test

The link opens from the browser and connects to the WEBRTC server. The server sends a request to the webcam to get the video stream. This process takes a few seconds.

The browser connects to the server via WebSocket, and the server sends a request via RTSP to the camera, with the RTP encapsulated stream of H. XML, which is then transcoded to the VP8/SRTP format, which is eventually played on the WEBRTC compatible browser.

After a short delay, we can see the familiar picture:

The video bottom shows the URL address of the video stream, which you can copy and open in another browser.

Confirm WEBRTC at Work

What if we cheat? That is, the video from the webcam is still being transmitted over HTTP. We should not only believe the video stream we see, but should also check the type of incoming traffic. Run the Wireshark and Chrome debugging Tools again, and you'll see the following in the Chrome console:

This time there are no data packets in and out, and there are no pictures transmitted through the HTTP protocol. Now we're looking at WebSocket data frames, mostly ping/pong frames that maintain websocket session connectivity. The more interesting frames are the connect,preparertspsession and onreadytoplay---connection servers are going through these stages: first establish WebSocket connection and session, then play the request content.

Here's what chrome://webrtc-internals shows:

As shown, the video bitrate from the webcam is 1Mbps. There are also send traffic, mainly RTCP and ice packets. The RTT between the browser and the Amazon server is around 300ms.

Now let's look at Wireshark, which clearly shows UDP traffic from the server. The picture packet size is 1468 bytes, which is the WEBRTC traffic. In particular, we can see the SRTP packet that transmits the VP8 video frame from the browser. In addition, we can also see some stun requests, which are WEBRTC checking the connection status carefully.

It is worth mentioning that the video playback latency is very low. WEBRTC works on SRTP/UDP, which is the fastest way to send packets compared to HTTP, rtmp, and other TCP-based protocols. Therefore, the visible delay is the sum of RTT, buffer delay, decoding delay, and playing time delay.

Visually, the naked eye does not feel any delay, which indicates a delay of less than 500ms.

The next test is to connect the other viewers. We've opened 10 chrome windows, each of which plays video, which makes Chrome dull. A 11th window opens on another computer, and the video playback is still smooth.

WEBRTC of mobile devices

As you know, Chrome and Firefox on the Android platform also support WEBRTC. Let's check whether the WEBRTC broadcast works here:

As shown, an HTC Smart machine plays video from a webcam on Firefox. Video playback on mobile devices is also smooth and smoother compared to desktop systems.

Conclusion

As a result, we were able to broadcast webcam video with WEBRTC to the browser at minimal cost. This does not require dancing or witchcraft in the rain or rocket science, only basic Linux and SSH knowledge.

Broadcast quality is fully acceptable and the naked eye feels no delay.

We can conclude that browser-based WEBRTC broadcasts are entirely worth considering, as in our scenario, WEBRTC is not an attachment or a plugin, but rather a real platform for playing video in a browser.

Why WEBRTC is not widely used

The main hurdle may be the lack of a video codec. The WEBRTC community and vendors should strive to integrate H. A into the WEBRTC. We can't say VP8 is bad, but why should we ignore the millions of compatible devices and software that already use H. Goddamn Patent!

The second reason is that only a subset of browsers support WEBRTC. IE and Safari are still not supported, so we have to use other methods such as using the Webrtc4all plugin.

In the future we want to see a lot of solutions that don't need transcoding, and a lot of browsers that can play video streams from different devices.

Translator: Weizhenwei, detailed see: " weaving wind net "

Android IOS WebRTC Audio Video Development Summary (85)--using WebRTC broadcast webcam video (bottom)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.