Recently, I and my colleagues are often asked the question "How to realize the broadcasting of live video from the camera on the web site?". Many who ask this question are mistaken, believing that this can only be done with the help of IP cameras. No, this is done on the basis of inexpensive USB-cameras. Specialists who know “how” often have another misconception - why pay for an expensive IP camera when everything can be implemented on USB cameras for $ 20-30? And let's say the camera needs to be installed on the street, at the other end of the building, 70m long. Do you know a lot of USB cameras with an IP66 standard case and a working temperature of -20 ° C? How long can a USB cable be? According to the Wiki, the
maximum length of the USB cable (in the screen) should not exceed 5m . And how to connect the camera at a distance of 70m (and this is straight, without taking into account the conduit bends)? It is possible to install a usb-hub with power every 5m. And how much money will the cost of usb extenders and active usb-hubs with catering for them draw? You must admit that this will not even pay for one IP camera. Someone will say "I will put, in the immediate vicinity of the camera, a computer in ITX performance and there are no problems." Yes, this is an option, but in the end the cost of a “comp + USB camera” will, at best, be equal to the cost of an IP camera. And the service, and uninterrupted power? And if the cameras are separated by hundreds of meters, or even kilometers, such as the beaches of the Crimea? The IP camera definitely wins!
How better to "throw out" the image of the camera on the site? You can of course give the image to the user directly from the IP camera. But IP-cameras are not designed for a large number of simultaneous connections and most of them after the 5-6th connection will begin to "die", up to a complete freeze. And if you want to look at the beach and the sea dozens or even hundreds? The problem is solved with the help of an intermediary media server. There are a lot of articles describing such a solution, for example, “
Streaming video using ffserver & ffmpeg ”. True, this article describes a solution for a USB camera, but the principle of operation is also suitable for IP cameras. But such an approach requires good knowledge in Linux, and most importantly - a high-performance, respectively, quite expensive processor. A simple Intel Atom with the task of transcoding real-time video from M-JPEG to FLV, MPEG4 or H.264 is unlikely to cope. And giving an image to the site in the M-JPEG codec is a stream of
~ 3-4 Mbit / s with a 640x480 picture with 15 frames / s. What is the outgoing bandwidth required if you watch dozens of users? Yes, and "pump" these same
~ 3-4 Mbit / s, not every user is able to.
There is a simple add-on solution for Add-On for D-Link DNS-325 & DNS-345 network drives called Webcam. All the “tools” in it are available, it will suffice to perform the simplest actions, which I will describe below. I checked only on D-Link IP cameras, but in theory it should work with others.
Start by installing Add-On. Take here
http://dlink.ua/dns or here
http://dlink.vtverdohleb.org.ua/Add-On/ .
Go to the “Management / Application Management / Add Ons” section and install the Add-On corresponding to your drive model.

Messages "Third-party Add-On ..." do not worry, click Yes.
')

After the installation is complete, start the Add-On button with the Start button, go to the Applications section and open the Webcam web interface.


But first you need to configure the IP camera accordingly. For example, let me give you the setting of the D-Link DCS-2310L IP camera. Go to the “Setup / Audio and Video” section and add a new one or change an existing profile.

The main requirement is only MPEG4 codec, it will not work with others. The remaining settings are at your own discretion, but I would recommend the following:
1. "Frame size & View window area" no more than 800x600. It will work, but the speed of the video stream will be too big for the site.
2. "Maximum frame rate" not more than 15 frames / s, and preferably 4-7 frames / s. The reason is the same as in paragraph 1.
3. “Video quality”, for this model of camera, it is better to choose “Constant bit rate” 1M, or less. This indicator is better to pick up on the visual perception of the resulting image. But the smaller the better.
Next, go to the “Setup / Network Setup” section and remember the name “RTSP / Access name for stream” for the profile you have configured. In my case, profile 2 corresponds to "live2.sdp".

“Authentication & RTSP port” leave unchanged.
Let's go back to setting up webcam. In the "Cam IP" field, enter the IP address of your camera, in the "RTSP name" field, the corresponding "RTSP / Access name for stream". Enable the “Audio” checkbox if you want to transfer video with sound. But I would not recommend “Audio”, as it will put a significant load on the processor of the drive, and for the site the main picture, not the sound. Click “Submit”. If, for some reason, the upload fails, a message is displayed to the right of “Camera 1”, for example, “Error: Bad IP or RTSP URL”. If everything went well, you will see the following:

If you need to change the IP camera, RTSP name or image resolution, you will need to click "Delete" and enter the parameters again.
If everything is OK, start the broadcast with the "Start" button.

Broadcast went, now you need to add html-code access to the video on the page of your site. Click “Site code”.

It is assumed that your drive is inside the LAN and is not accessible from the outside. Therefore, the html-code substitutes the external IP-address of your router. Accordingly, in order to see the image from the Internet, you need to do a port forwarding (Virtual Server or Port Forwarding) on ​​the router. TCP protocol, port 8090. I will not tell you how to set up the forwarding, since there is no universal instruction, each manufacturer has its own configuration interface. For example, so
http://dlink.ru/ru/faq/246/1156.htmlAs a result, we get this picture

How it really works can be seen on the demo page.
http://dlink.vtverdohleb.org.ua/webcam.htmlThe truth does not guarantee that the page will always work, for whatever circumstances beyond my control, the camera may have to be turned off. But I will try not to turn it off within a month, after placing the article.
Possible problems:
1. Broadcasting works on the basis of the vlc-mozilla-plugin. Therefore, the picture will not be if the computer is not worth VLC Player. But searches in Google for some absolutely universal system yielded nothing. For example, on my tablet, after installing VLC Player, the video went off, but the sites with SWF did not show flash.
2. The outgoing bandwidth of your channel is lower than the total flow for everyone. Well, the options here are to increase the outgoing speed of the channel or “crush” the speed of the video stream by reducing frames / s and decreasing “Video quality / Constant bit rate” with a deterioration in picture quality.
See who is watching and what the flow rate can be on the status page:
http: // ip address of accumulator: 8090 /
In the next version of Webcam, the ability to work with 5 cameras will be added. If you have comments and suggestions for the current version, please write them in writing at
http://dlink.ua/dns or in the comments to the article.

Anticipating comment “But how can a weak NAS handle the distribution of 5 cameras for a couple of dozen users?” I give an example of top

As you can see, ffserver & ffmpeg broadcasting consumes only 3% of the process with the 1st camera and 4 users for viewing.
In general, D-Link DNS-325 & DNS-345 are very successful devices, able to do everything that competing devices offer and even more. Some of their functionality I have already described in previous articles:
Is IPTV over Wi-Fi a problem? Absolutely no problem!What we should build a PBX!Happy viewing!