How to turn an USB camera with Raspberry Pi into an Onvif IP Camera?

Introduction

At this instructable, we will make a new interesting Camera solution, which have never seen before! I would like to show you how can you make connection your USB camera and Raspberry Pi with Camera SDK. The goal is to turn your webcamera to an Onvif IP Camera. Is it sounds interesting?

This solution will change your views of webcamera and add a higher Onvif IP Camera solution for you. During this project I would like to give information about the hardware and the software requirements. Beside that you can study and get more about Onvif technology. More of them you will know that how to use an normal ordinary webcam as a higher level IP Camera. If you are an Raspberry Pi user, or a developer you will find new solutions and technology solutions in this article for your device. Besides that you can learn how to install MJPEG Streamer package.

It could be a good solution for you if you are an USB camera or a Raspberry Pi user, becase you don’t have to buy an Onvif IP Camera, just turn your camera to IP camera with this great solution.

If you follow and join in this project and you can turn your cameras to Onvif IP Camera, with Camerea SDK and broadcast your cameras view with IP Camera Server solution. Besides that you will get to know how can you make Onvif service.

At the end of the project you will get solution, how can you reach and serve Onvif service with your usb webcam, Raspberry Pi over Cameras SDK. I really offer this solutions if you are an Raspberry Pi developer, Onvif developer, USB camera and Rasbsery Pi user, IP Camera user, Onvif Camera user, or just an user whom insterested in usefull solutions.

If you start read this article you will look forward to try this solution. So if you try and start and read this guide you can get a fantastic option, how can you make an Onvif IP server solution. You need only a few minutes to reach this state. Join this journey and I’m sware that you will read the most memorable article which have you ever read. I hope you will enjoy this solution.

What is Onvif?

Open Network Video Interface Forum (ONVIF) is a global and open industry forum which uses global open standards for the interface of physical IP-based security products. This technology has great flexibility, and it’s so popular nowadays. In this section I will present how it works, what kind of benefits has it and how you can use it. Let me instroduce what advantages has an Onvif IP Camera and why can be useful if you turn your USB camera to this higher level.

How Onvif Works?

If you turn your webcam to Onvif technology with Camera SDK you will get more information about your camera. Let me intruduce the onvif higher level technology. This is the standard for how IP products can communicate with each other within video surveillance and other physical security areas. Onvif technology requires broadband Internet connection. If you follow the guide you will get a solution how can you reach you webcam over internet, with Onvif IP Server solution.

Further requirements depend on the Onvif service you wish to use. The standard is providing great solutions and features of the security area such as Pan-Tilt-Zoom control, alarm handling, video analytics etc.

How to turn an USB camera with Raspberry Pi into an Onvif IP CameraWhat informations can you donwload if you use Onvif:

– IP configuration

– Device discovery

– Device management

– Media configuration

– Real time viewing

– Alarm handling

– PTZ control

– Video analytics

– Security

The alarm handling is a very important feature because if the IP camera detects motion the system reacts to this event. The sensitivity of motion detection is adjustable. When a detection has happened the system reacts with a predefined action: capturing image or video and uploading it to an FTP server or sending it as an e-mail. So you can set your webcam as an IP Camera if you jump the first step of the guide. I’m so excited, I’m looking forward to show you this solution! Let’s begin!

Step 1: STEP 1: Hardware requirements

In this chapter I would like to show you what kind of hardware items need to install this project. I’m ensure you that it takes just a few minutes. Let’s start to check what hardware requirements will need to collect to establish and make this project. These hardware items are so important, please check the following lists.

Requirement:

· USB Webcamera (Get an USB webcam)

· Raspberry Pi (Get a Rasberry PI)

· USB hub (Get USB hub)

· Extra USB cable (for power supply)

· Keyboard, mouse (Get keyboard, mouse)

· 5V DC power supply (Get 5V DC adapter)

· Onvif-compliant camera SDK (such as Ozeki Camera SDK)

· Ethernet cable (Get Ethernet Cable)

Let’s start the project to get information about hardware items and start to connect them to each other.

Figure 1 – USB Webcam

First of all you need an USB Webcamera can be an ordinary USB camera which you have bought at shop. It can be your own choice. I offer to use camera which has a good resolution too. e.g. 640×480. If you want to use and take good images and streaming I offer you to choose a high resolution camera. We are using an ordinary high resolution usb webcamera.

Figure 2 – Raspberry Pi

At this project we will show you how can you use your Raspberry Pi and your USB camera connnect with Cameras SDK and provide Onvif solution. You can buy i tor order on the Internet. This device has a memory card and we stored linux operation system for Raspberry Pi . Figure 2.

Figure 3 – Canyon USB Hub

It also can be your choice. I’m sure that you choose an usb hub which has more ports for connections. If you want to connect keybord, mouse, webcamera and other devices, then it can be useful if you buy a hub which has more than 3 ports. In this example we use CANYON 4 port USB HUB as you seen at Figure 3.

Figure 4– USB Keyboard and Mouse

If you connect USB keyboard and mouse you can easily install drivers for the connection. If you have other solution you can use it. At this time we use USB Keybord and Mouse devices.

Figure 5 – DC adapter

You need an 5V DC Adapter. It will give power supply for Raspberry Pi and USB devices. It can be an ordinary device, you can buy it an electrical shop or on ebay. Figure 5.

Figure 6 – Ethernet cable

You will need an Ethernet cable to connect your Raspberry Pi to you local Area Network. It can be a Cat5 straight cable, (Figure 6) when you connect Raspberry Pi to your home router. I offer to choose a cable which has long enough from your router till to your Raspberry Pi device. If you bought a longer one you can create a shorter one with a crymper and a pin connector.

Now we if checked the hardware, let’s start to connect them to each other. It can be easy for you, just connect usb devices to the usb hub. You will need an extra usb cable to give power supply for Raspberry Pi . The next pictre below will show how you need to connect. You can check the connnection on Figure 7.

Figure 7 – Connect devices

If you have HDMI to VGA converter you can connect your device with a VGA monitor you can reach your Raspberry Pi view. So you connect your USB devices with USB hub and the DC Apater to the USB hub. Finally connect the hub with Raspberry Pi . You can check the final state at Figure 8.

Figure 8 – Raspberry Pi hardwarde connections

We have an other step is to connect your Raspberry Pi to your local network. You will need this step to install MJPEG stream package.

Connect your Raspberry Pi to Localhost

Before then we jump to STEP 3, you need to connect your Raspberry Pi to local network. You can do this with an Ethernet cable and a router. Just plug the Ethernet cable to Ethernet shield and your router. You can also see how can you connect Ethernet cable to shield at Figure 9.

Figure 9 – Connect Ethernet cable to Raspberry Pi

Let’s connect the Raspberry Pi with your router. In this sample we used a Linksys WRT54g router. It’s not an important member of the hardware requirements. You can use your own one. Just check that you have connect to the Internet. We need to connect Raspberry Pi to Ethernet 1 port. Figure 10.

Figure 10 – Connect Raspberry Pi to Lan network

After we have connected Raspberry Pi to router, check that your router connected to internet WAN connection and the power supply. It’s more important because at STEP 3 you will install the package from the internet which will need for establishing the connection. Please check your WAN cable has connected to WAN port of the router. Figure 11.

Figure 11 – Connect the router to WAN network

The next step will help to you how can you connect your Raspberry Pi with Ozeki Camera SDK and how can you use it with Onvif technology. Let’s continue the next step of this guide.

Step 2: STEP 2: Connect Raspberry Pi MJEG streamer package install

At this step we will show you how can you install MJPEG streamer package at your Raspberry Pi . After you have started your Raspberry Pi , and connected to the local network please start a terminal. If you don’t have graphical interface you can easily install, just use apt-get install package_name. Besides that you need to establish Ethernet connection. You need to set up internet connection at /etc/network/interfaces file. If your router use DHCP service you need to install dinamic ip address. Not we set dinamic ip address to reach the Internet. Modify the interfaces file with nano or other text editor. Please add another row to the file.

$ iface eth0 inet dhcp

After the network settings, check the connect with ping command. E.g. ping google.com. If the connection is established you will receive packets. Now let’s start to install the MJEPG streamer package. Follow the steps and be carefull do not miss one of them.

First of all you have to log in to root mode. After you sign as root you can start to install MJPEG streamer. The following command installs the three libraries that MJPG-Streamer uses:

$ sudo apt-get install libjpeg8-dev imagemagick libv4l-dev

The videodev.h header file that MJPG-Streamer needs you have to replace with a videodev2.h. You need to create a symbolic link to make MJPG-Streamer:

$ sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h

The source code for MJPG-Streamer is available at sourceforge.net, please user wget command to find and to direct download the link:

$ wget http://sourceforge.net/code-snapshots/svn/m/mj/mj…

After that you need to unzip the MJPG-Streamer source code. The source code download is a compressed zip file. You can put the file in your home directory and run the following command to extract the files:

$ unzip mjpg-streamer-code-182.zip

MJPG-Streamer downloads with several plugins the next command below only builds what's needed:

$ cd mjpg-streamer-code-182/mjpg-streamer

$ make mjpg_streamer input_file.so output_http.so

The following commands copy all the needed files into system directories:

$ sudo cp mjpg_streamer /usr/local/bin

$ sudo cp output_http.so input_file.so /usr/local/lib/

$ sudo cp -R www /usr/local/www

Let’s start the camera. We are almost reach your webcam. Be patiant it takes just a few seconds. Now it is time to start the camera module:

$ mkdir /tmp/stream

$ raspistill –nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0

Start MJPG-Streamer. The camera is now writing images, so all that is left is to start MJPG-Streamer:

$ LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i “input_file.so -f /tmp/stream -n pic.jpg” -o “output_http.so -w /usr/local/www”

Finally let’s start the service:

$ ./mjpg_streamer -i “./input_uvc.so” -o “./output_http.so -w ./www”

Figure 12- The service has started

You established the connection with your camera! Watch the Stream! Now you can connect with your web browser and watch the stream live. If you want to watch from another computer in your network use http://192.168.0.1:8080. You have to modify the IP address to your Raspberry Pi ’s ip address.

When you install this package at your Raspberry Pi , the streaming has started and you can reach it. Let’s check the camera view. You can check that stream is working, if you press the ip and port number 8080 into your browser. This is what you will see after installing MJPEG streamer in the browser. Please check and compare to the Figure 13 with your details.

Figure 13 – Raspberry Pi MJPG streaming reach from http://rasberpi_ip:8080

If you click Stream you will check the live view of your camera. You can see your camera’s image at Stream tab. Please check the Figure 14 below.

Figure 14 – Check the MJPG streamer camera view

If you follow the guide you will get more insterting solution how to turn your camera to Onvif IP Camera. If you click VideoLAN you can find the stream url:

192.168.115.87:8080/ ?action=stream.

You will need this stream at the next part of this guide. You can reach streaming at:

http://192.168.115.87.8080.

The next chapter will give information, how can you install and start Onvif Service without Onvif IP Camera. Let’s start the most exciting chapter STEP 3 when you find out how can you turn your webcam to IP camera.How to turn an USB camera with Raspberry Pi into an Onvif IP Camera schematic

Step 3: STEP 3: Install Ozeki Camera SDK

You can download and use the free trial version of OZEKI Camera SDK using the following link: Download OZEKI Camera SDK free of charge.

After downloading OZEKI Camera SDK, you will need to install it to your computer. The installation wizard will lead you through this process. You can change some basic settings during the installation, like the target folder but you can also install the SDK without any modifications. First you need to extract the downloaded zip file. For extracting you will need WinRAR program. Select the zip file, then right click and choose the “Extract Here” option. Figure 15.

Figure 15 – Extract SDK

Run the extracted Ozeki_IP_Camera_SDK file. Either right click, then choose the “Run as administrator” option or double left click. At both a confirmation window can pop up, where you can allow the installation. The installation wizard will start with a welcoming page that informs you about that the OZEKI Camera SDK will be installed on your computer Click on the ‘Next' button. Figure 16.

Figure 16 – Installation of Ozeki Camera SDK

When you pressed the Next button on the Welcoming window, you get to another one that will allow you to select the installation folder for your SDK. The default folder for installation is the C:\Program Files\Ozeki\Ozeki SDK folder, but you can change this if you wish. Click on the ‘Install' button.

Figure 17 – Add path of installation

The installation process is showed by a progress bar. The installation can take some time according to your hardware configuration. Please wait while Ozeki IP Camera is being installed. When the installataion is completed, then the window will inform you about it and ask you whether to run the OZEKI Camera SDK Launcher. Click on the ‘Finish' button. Finally you succesfully installed the Ozeki Cameras SDK. After that you need more clicks to reach your USB camera with Camera SDK over Onvif technology.

The Camera SDK give you this option to stream and catch your Raspberry Pi cameras streaming. After the installation, start install Onvif solution and service with Ozeki Camera SDK. Please start the Ozeki Camera SDK Launcher. At your PC desktop you can find the Launcher .exe which will help you to establish Onvif service on your USB camera. You can find it at the end guide at STEP 4.

For more detail: How to turn an USB camera with Raspberry Pi into an Onvif IP Camera?


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top