Table of Contents
Video stream proxy
Intro
Nowadays, IP camera's manufacturers do not provide unauthorized access to video stream due to security reasons. To use videostream in WebHMI it should be without login/password to access. Also, using a server in between PC and IP Camera will allow access from many users, what is a true broadcast, unlike direct IP camera connection, which is usually limited to 10 users.
The solution, is the shim web server in LAN, which will transcode H.264 to MJPEG. (e.g. Raspberry Pi). Also, this could be a Linux or Windows powered machine.
Devices prerequisites
IP Webcam testing app
If there is no IP camera at moment, you can use IP Webcam to test WebHMI videostream (as it is not ecrypted be default) or VLC transcoding if you want to substitute phone with IP camera later after testing.
Any IP camera, that can show stream using rtsp: or http: protocol.
You can see the links at IP Webcam app screen. When the IP Webcam server started, it has default cgi access via link
http://phone-ip:8080/video
IP camera CGI setting
By default, cgi should be enabled manually in settings.
Hikvision: Configuration, Network, Advanced Settings, Enable Hikvision-CGI. Then create a cgi user.
Dahua: Configuration, Integration Protocol, Enable CGI. Use web login user.
Tested devices list:
For example, there was a two different manufacturers devices tested. Dahua DH-IPC-K22
- cgi-link
http://login:password@ip-camera:80/cgi-bin/mjpg/video.cgi?channel=1&subtype=1
Hikvision DS-2CD2423G0-IW
- cgi-link
http://login:password@ip-camera:80/Streaming/channels/102/httpPreview
VLC transcode
- WebHMI with IP 192.168.1.1
- IP Camera with IP 192.168.1.2
- Broadcast server with IP 192.168.1.3
Broadcast server can be Windows or Linux machine, e.g. Rapsbian on Raspberry Pi . Let's consider using Rapsberry Pi 3B+ powered Raspbian 10.
To do this, VLC player is preinstalled with Rapsbian. If it is not present in the system, you can install it with
sudo apt-get install vlc
To start with, login to IP-camera and check the settings, if cgi enabled and test access via link using browser. Alternatively, if you want to test to possibility, use IP Webcam app. There is default config which allows both vlc or WebHMI videostream testing.
Command to output and argument explanations
Access to IP cameras stream usually can be provided via RTSP or HTTP protocols. Put the link in the following example and try to watch and then to transcode stream.
- example_stream
cvlc -vvv http://login:password@ip-address:port/link_to_stream
That should look like this:
- test_stream
cvlc -vvv rtsp://student:Hikvision@192.168.1.58:554/Streaming/Channels/102
If you can see the image, so the IP camera settings done and now you can start configure transcoding.
- example_transcode_stream
cvlc -vvv -Idummy http://login:password@ip-address:port/link_to_stream --sout "#transcode{vcodec=MJPG}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8888/}"
For example let's use login and password with IP camera' IP, using RTSP protocol (through 554 port) and transcode the full resolution stream to 192.168.1.3:8888 which is Raspberry Pi server and custom port 8888.
- test_transcode_stream
cvlc -vvv -Idummy rtsp://student:Hikvision@192.168.1.2:554/Streaming/Channels/102 --sout "#transcode{vcodec=MJPG}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=192.168.1.3:8888/}"
Let's take a closer look at the command. The source stream is:
rtsp://student:Hikvision@192.168.1.2:554
Destination can be also set port only, and the IP will be IP of Raspberry Pi to get access to stream
dst=:8888/
The output broadcast URL is
http://192.168.1.3:8888
To test if it works, copy following link to terminal and run with -vvv
argument to show the maximum verbosity.
The output should not have warning and unresolved errors such as no codecs finded.
Perfomance optimisation
Do not forget to get rid of -vvv
argument due to huge additional processor load.
There are some variants to try to optimize performance
- Decrease IP camera stream resolution
- Lower transcode output resolution
Lower picture resolution
#full resolution cvlc -Idummy http://login:password@ip-address:80/link_to_stream --sout "#transcode{vcodec=MJPG}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8888/}" cvlc -Idummy rtsp://http://login:password@ip-address:554/link_to_stream --sout "#transcode{vcodec=MJPG}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8888/}" #transcode to lower resolution cvlc -Idummy http://login:password@ip-address:80/link_to_stream --sout "#transcode{vcodec=MJPG,vfilter=canvas{width=640,height=480}}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8888/}" cvlc -Idummy rtsp://http://login:password@ip-address:554/link_to_stream --sout "#transcode{vcodec=MJPG,vfilter=canvas{width=640,height=480}}:standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8888/}"