Hikvision Raspberry PI as Viewer

Kumar Pratik
3 min readFeb 17, 2017

--

We love exploring new things at GeekyAnts & an innovation always leads a solution. One of the experiments which actually solved our problem with Raspberry PI & a bit of scripting.

We just got our security cameras installed in our office (GeekyAnts) and we wanted an additional viewer on our reception desk with limited number of camera display. The solution from the vendor was quite complex and required wiring from the Hikvision DVR to Reception desk. And we wanted some quick solution for it

Unfortunately, I wasn’t able to find anything quick to do the things. So we built our custom solution with Raspberry pi 3.

Here is my solution for creating extended Hikvision Viewer over IP network. You will need the following things:

  • Raspberry PI 3 running OS raspbian
pi@pi-resp:~ $ cat /etc/os-releasePRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"NAME="Raspbian GNU/Linux"VERSION_ID="8"VERSION="8 (jessie)"ID=raspbianID_LIKE=debianHOME_URL="http://www.raspbian.org/"SUPPORT_URL="http://www.raspbian.org/RaspbianForums"BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
  • Monitor Full HD with HDMI
  • You will need your IP Address of your Hikvision DVR and the username & password.
  • Do make sure that your Hikvision and Raspberry PI are on the same network and you know the IP :D

You will need to install the following softwares (make sure your OS is updated to latest)

  • omxplayer — which you can install by running sudo apt-get install omxplayer
  • omxplayer is the video player which uses GPU

Next, lets start configuring the raspberry pi system

  • sudo raspi-config

As omxplayer is going to use lots of GPU, lets increase the GPU Ram to 256Mb

Advance Option -> Memory Split -> Change the Value to 256 -> Save and Reboot

Optionally, you can keep the system running in CLI Mode. So you don’t burn your CPU and RAM is other unwanted things.To do so, again open the raspi-config
-> Boot Options -> Desktop / CLI -> Console (Text Console, requiring user to login)

Next, lets make the display always active. by default the display turns off after 10 mins incase of no interaction on the console.

edit the file /etc/kbd/config by using sudo nano /etc/kbd/config

# screen blanking timeout.  monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
BLANK_TIME=0

change the value of BLANK_TIME to 0, as shown in the above example.

To start the video you can just write

omxplayer --live --refresh --video_queue 4 --fps 30 --win “0 0 1920 1080” rtsp://<username>:<password>@<ip-hikvision>/h264/ch1/main/av_stream

with the above command you should be able to start your live video from channel 1 camera.

#ref: http://www.cctvforum.com/viewtopic.php?t=37239

Main stream:
rtsp://admin:12345@192.0.0.64/h264/ch1/main/av_stream
rtsp://admin:12345@192.0.0.64/MPEG-4/ch1/main/av_stream

Sub stream:
rtsp://admin:12345@192.0.0.64/mpeg4/ch1/sub/av_stream
rtsp://admin:12345@192.0.0.64/h264/ch1/sub/av_stream

Next, I wanted to display my 3 cameras on the screen

  • Main Passage Camera (that is on channel 4)
  • Another Floor Passage View (that is on channel 3)
  • Parking Area (that is on channel 1)

here is my script which does the job for me! It runs every min via cronjob to make sure all the streams are running and incase if its close / crashed by any reason it auto restarts.

#Script for checking and starting the camera display, setup to runs via cronjob everymin.setterm -cursor off#stream1
st1=`ps -ef | grep omxplayer | grep stream1 | cut -d'-' -f2 | cut -d' ' -f2`
echo "Checking & Starting Screen 1";
if [ "$st1" = "stream1" ];
then
echo "Running Stream1..";
else
echo "Starting Stream1..";
screen -dmS stream1 sh -c 'omxplayer --live --refresh --video_queue 4 --fps 30 --win "0 0 1280 1080" rtsp://<username>:<password>@<ip-hikvision>/h264/ch4/main/av_stream';
fi
#stream2
st2=`ps -ef | grep omxplayer | grep stream2 | cut -d'-' -f2 | cut -d' ' -f2`
echo "Checking & Starting Screen 2";
if [ "$st2" = "stream2" ];
then
echo "Running Stream2..";
else
echo "Starting Stream2..";
screen -dmS stream2 sh -c 'omxplayer --live --refresh --video_queue 4 --fps 30 --win "1280 0 1920 720" rtsp://<username>:<password>@<ip-hikvision>/h264/ch3/main/av_stream';
fi;
#stream3
st3=`ps -ef | grep omxplayer | grep stream3 | cut -d'-' -f2 | cut -d' ' -f2`
echo "Checking & Starting Screen 3";
if [ "$st3" = "stream3" ];
then
echo "Running Stream3..";
else
echo "Starting Stream3..";
screen -dmS stream3 sh -c 'omxplayer --live --refresh --video_queue 4 --fps 30 --win "1280 720 1920 1080" rtsp://<username>:<password>@<ip-hikvision>/h264/ch1/main/av_stream';
fi;

Save it as start-stream.sh and All done :-)

Below is the screenshot of the output from our viewer!

--

--