RaspberrIPCam – Full HD IP Camera based on Raspberry Pi

如果网络条件允许,建议看原文。转载自:http://www.sonsoftone.com/?page_id=287

[12-Nov-2014 RaspberrIPCam Updated ! Added Configuration web page with embedded player. Please read again the tutorial to be aware of modifications]

The RaspberrIPCam is an Open Source project that aims to provide a modern and reliable solution for anyone wants to secure it’s home or work and at a very low price compared to what you can find on the market.

I started this project because no other solutions based on Raspivid and vlc streamer convinced me in FPS and because I prefer to master all the chain.

Performances are just great, because it allow streaming a FULL HD (1080p) video stream at 30fps without latency (latency involved is mostly due to the player).

Currently it does the basic task of a CCTV IP Camera : stream over the network a live H.264 encoded video over RTSP protocol which is the standard protocol for video streaming in security applications. It will be improved by a Record Manager, and external trigger handler (PIR Sensor, door sensor, …) and a web sever for configuration.

This article show you how to encapsulate your own Raspberry in a camera housing and build the software to do this.

1- Building the camera

The Raspberry Pi + Camera Sensor Module are integrated into a standard fixed dome camera housing that can be found in eBay or Alibaba.

Image 1

I implemented a simplified version of PoE (Power over Ethernet) by using two twisted pairs to drive GND and +5V to the camera. 1-2 and 3-6 twisted pairs are used for the 100Mbps ethernet connection and the two other twisted pairs are used GND and +5V.

FakePoE

Power supply is provided by a simple 5V/1.5A AC/DC supply. +5V and GND are internaly soldered to C6 capacitor

Image 2

Currently the camera can not be used by night but I plan to make an other one with a NoIR (without InfraRed filter) version of the sensor and place a tiny infrared spot inside.You can find a workaround by placing a halogen spot controled by a PIR sensor.

When closed it looks like a real security cam:

Image 4

 2 – Building and Installing the software

The software is based on Raspivid software (which basically capture and encode to H264 the video) and Live555 RTSP library. Mixed together they provide the foundations of a security IP Camera.

First of all, if you haven’t activated it yet, activate SSH with raspi-config->advanced options->ssh->Enable to get remote access:

$ raspi-config

Then be sure to be up to date:

$ sudo apt-get update
$ sudo apt-get upgrade

Install CMake:

$ sudo apt-get install cmake

Download userland-master, build it and install it:

$ cd /home/pi/
$ git clone git://github.com/raspberrypi/userland.git
$ cd userland
$ ./buildme

Download and install libxml2-dev:

$ sudo apt-get install libxml2-dev

Download live555 RTSP library, modify it, build it:

$ sudo apt-get install lynx
$ cd /home/pi/
$ lynx -source http://www.live555.com/liveMedia/public/live555-latest.tar.gz > live555-latest.tar
$ tar -xvf live555-latest.tar
$ mv live live555
$ cd live555

Modify linux.config :

$ sudo nano config.linux

Add -DALLOW_RTSP_SERVER_PORT_REUSE=1 at the end of the COMPILE_OPTS line. This will allow you to reuse a socket that is in TIME_WAIT state. In other words, it is more convenient when you often start and stop the application and you do not want to wait for the socket to leave TIME_WAIT state (about two minutes)

When modified check modification:

$ cat config.linux

Bash should output this :

$ cat config.linux
COMPILE_OPTS = $(INCLUDES) -I. -O2 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DALLOW_RTSP_SERVER_PORT_REUSE=1
C = c
C_COMPILER = cc
C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS)
CPP = cpp
CPLUSPLUS_COMPILER = c++
CPLUSPLUS_FLAGS = $(COMPILE_OPTS) -Wall -DBSD=1 $(CPPFLAGS) $(CXXFLAGS)
OBJ = o
LINK = c++ -o
LINK_OPTS = -L. $(LDFLAGS)
CONSOLE_LINK_OPTS = $(LINK_OPTS)
LIBRARY_LINK = ar cr
LIBRARY_LINK_OPTS =
LIB_SUFFIX = a
LIBS_FOR_CONSOLE_APPLICATION =
LIBS_FOR_GUI_APPLICATION =
EXE =

Then build live555 library (you can take a cup of coffee, it takes a while):

$ sudo ./genMakefiles linux
$ sudo make

Then install Apache:

$ sudo apt-get install apache2 -y
$ sudo apt-get install php5 libapache2-mod-php5 -y

Now download RaspberrIP-Cam, build it and install it:

$ cd /home/pi/
$ git clone git://github.com/SonsOfTone/RaspberrIP-Camera
$ cd RaspberrIP-Camera
$ sudo make
$ sudo chmod 777 start.sh

Copy webpages and config.xml contains in RaspberrIPCam folder to Apache folder:

$ cp -rf www/* /var/www/
$ sudo cp -rf config.xml /var/www/
$ sudo rm /var/www/index.html
$ sudo chmod 777 /var/www/config.xml

Start the RaspberrIPCam application:

$ sh start.sh

When starting, the application inform you on what URL you will be able to access the stream, for me: rtsp://192.168.1.33:8554/

Play this stream using the URL "rtsp://192.168.1.33:8554/"
Beginning streaming...
Start Streaming from RaspberrIP Camera...

This URL will change according to your raspberry pi IP adress. In my case, the DHCP server gave me the 192.168.1.33 address. Port is always 8554

Now you checked that all works fine, you may want to launch the application at startup:

$ sudo nano /etc/init.d/Startscript

Add these lines in the file to allow RaspberrIPCam to be launched by Apache:

chmod 777 /dev/vchiq
su www-data -c "/home/pi/RaspberrIP-Camera/start.sh &"

Verify the modification :

$ cat /etc/init.d/Startscript

Bash should output this :

$ cat /etc/init.d/Startscript
chmod 777 /dev/vchiq
su www-data -c "/home/pi/RaspberrIP-Camera/start.sh &"

Add Startscript to start sequence :

$ sudo chmod 755 /etc/init.d/Startscript
$ sudo update-rc.d Startscript defaults

Restart the raspberry, RaspberrIP-Camera application will start automatically

The start.sh script is configured to launch RaspberrIPCam with no parameters.

/home/pi/RaspberrIP-Camera/RaspberrIPCam -o - >/dev/null

By default, RaspberrIPCam open config.xml and parse it to grab parameters. You can still add parameters to start command line in start.sh as you did with raspivid (see raspivid documentation) if they are not supported by the config.xml file. If you do not specify anything, parameters found in config.xml are initialized and the others are set to default.

<?xml version="1.0"?>
<raspberripcamconfig>
 <video>
 <hres>1280</hres>
 <vres>720</vres>
 <bitrate>20000000</bitrate>
 <gopsize>15</gopsize>
 <shutter>30000</shutter>
 <fps>30</fps>
 </video>
 <network>
 <rtspport>8554</rtspport>
 </network>
</raspberripcamconfig>

3- Configuration Web Page : 

You can only do this after doing the entire previous procedure and restarting the camera.

Start your web browser and type you raspberry pi address in URL bar, you will access to the configuration page :

WebPageVLCPlugin

 

The player only works on Firefox at this time.

A click on Save button will store parameters and restart RaspberrIPCam with new parameters.

This list of parameters will be improved soon

4- View the stream in VLC or Mplayer:

Open VLC, click on Media->Open Network Stream, then enter the URL

VLC

Pay attention to set these settings as this in Tools->Preférences->Show Stettings(all)->Input Codecs. This will ensure the lowest latency with VLC.

VLC2Config

View the stream in mplayer (works but have more latency than VLC):

mplayer rtsp://192.168.1.33:8554/

mplayer

5- Synology Surveillance Station Integration

If you have a Synology NAS, you can configure it to view and record your RaspberrIPCam video stream.

To this this first stop Surveillance Station in Main Menu -> Packet Center

Launch a terminal and log as root on your NAS.

Then navigate to this folder, create a custom .conf file and edit it :

$ cd /volume1/@appstore/SurveillanceStation/device_pack/camera_support
$ touch RaspberrIPCam.conf
$ vi RaspberrIPCam.conf

Then copy paste the following text (you have to press « i » key to insert text before) :

RaspberrIPCam*RaspberrIPCam]
api = custom
channel_list = 1
default_channel = 1
resolutions_h264 = 1280x720
default_resolution_h264 = 1280x720
fps_h264_1280_720 = 30
default_fps_h264_1280_720 = 30
default_image_quality = 5
h264 = rtsp
rtsp_protocol = udp
mjpeg = rtsp

Restart Surveillance Station in Main Menu -> Packet Center

Then Open Surveillance Station and in management menu click « Add->Add Camera » button. Click « Next » button and choose « Complete Setup » option and click « Next » button.

Enter your IP Address, 8554 as port, and select in Brand « RaspberrIPCam ». Leave blank Username and Password.  Click « Next » button :

SynoSSConfig2

Choose H.264 Codec. Click « Next » button :

SynoSSConfig4

Choose your recording schedule. Click « Next » button :

SynoSSConfig5

Choose Live view from camera and UDP transport protocol. Click « Finish » button :

SynoSSConfig6

Done !

(Thanks to  RMorrison for comment (see below) and steaminghacker for tutorial)

6- What comes next ?

Currently, the software is really basic. I’ll first add a recording manager to store short videos on trigger (PIR, switch, …) it will make pre and post recording.

The camera will also be updated with a NoIR sensor and an IR spot.

Configuration web pages will handle more parameters and I will add a login page to restrict access.

7- Troubleshooting

– If you see cuts, abnormal latency and low FPS in the viewer, you might have to tweak the shutter parameter (-ss in the start.sh command line) when the light is very low.

– I tested the application with a Netgear WNA1000M and it didn’t  work. I have to investigate why, because the connection seems to be OK. Maybe it’s linked to my router. It’s not mandatory for me as far as camera is power over the ethernet cable.

– Currently the latency that you can feel is due to VLC. I have to test other players to see if they do better

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值