simple web templates

Video recorder and streamer with USB camera

view/record what is viewed inside and/or around the camper at parking lot or while driving

Mobirise

Main components:
- USB camera,
- any single-board computer, one of the Cubietruck clones in this case,
- the camper's NAS,
- the camper’s router.

Since the USB cameras do not have an RTSP streamer and they use a resource-intensive USB port, this is the worst use case for the camera. Wired IP camera is better, wireless IP camera is worse, but USB camera is the worst in between.

But it still works and this case is described here.

Streaming from the USB-camera will be available on the local network of the camper through the IP-address of a single-board computer. Video recording (archive) will be stored in camper's NAS storage and will be available in the camper’s network.

Theoretically, it is possible to control more than one USB cameras on one single-board computer, but not each processor of this computers can do this normal.

In this case, one Cubietruck clone was used with Armbian OS (Ubuntu version), flashed to a 4GB SD card with Etcher.
The Cubietruck processor was with a good cooling solution.

The USB camera was not connected to Cubietruck at the beginning of setup. All settings were made via Windows PC. In some cases will need switch off the PC firewall while settings.

When Armbian started, the password for root user was changed and another normal user was made. Once Armbian is configured to use a Wi-Fi of the camper’s router, it will be available in the PC terminal via PuTTY over IP via 22 port. The IP address can be found in the web interface of the camper’s router.

Then was changed the hostname of Cubietruck:

nano /etc/hostname

In the opened file "cubieboard" was changed to "CA-Host1". Then:

Ctrl+O, Enter, Ctrl+X

nano /etc/hosts

In the opened file "cubieboard" also was changed to "CA-Host1". Then:

Ctrl+O, Enter, Ctrl+X

reboot

Cubietruck has been rebooted. There was a root login after a while.

This commands were entered from PC via PuTTY terminal for a long life of the SD card:

swapoff -a

Then cmake was installed:

wget http://www.cmake.org/files/v3.13/cmake-3.13.3.tar.gz

tar xzf cmake-3.13.3.tar.gz

cd cmake-3.13.3

./configure --prefix=/opt/cmake

make

make install

rm cmake-3.13.3.tar.gz

cd

nano  /etc/environment

In open file string:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

was changed to string:

PATH="/opt/cmake/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

that is, the substring "/opt/cmake/bin:" was added for the PATH environment variable. Then the commands were entered:

Ctrl+O, Enter, Ctrl+X

reboot

After rebooting and logging in to root, the MJPG-Streamer and FFmpeg packages were installed:

apt-get install libjpeg8-dev

apt-get install v4l-utils

cd /tmp

git clone https://github.com/jacksonliam/mjpg-streamer.git

cd mjpg-streamer/mjpg-streamer-experimental

make

make install

cd

apt-get update

apt-get install ffmpeg

It was then authorized as the root user for the camper's NAS via PuTTY over the NAS IP at 22 port. And the commands were entered:

nano /etc/exports

In the open file, the full path of access to the camper's NAS shared folder (in this case, CA-NAS-shfld) from any NFS client within camper’s network found. In this case, it was /export/CA-NAS-shfld.

In the camper's NAS shared folder, it was necessary to make a folder to archive video from the USB camera. Here the camera/folder name was inner_cam_01:

Ctrl+X

mkdir /export/CA-NAS-shfld/inner_cam_01

Then the size of the folder for video archive from the USB-camera to 10000 MB was limited. To do this, the crontab file was opened and added to its end:

crontab -e

# in this case, "Joe's Own Editor" was opened 

# the following line gives the command every 6 minutes to delete the oldest files in the folder when the folder size exceeds 10000 MB

*/6 * * * * while [ $(du -sm /export/CA-NAS-shfld/inner_cam_01| cut -f1) -gt 10000 ]; do rm -f /export/CA-NAS-shfld/inner_cam_01/"$(ls -1c /export/CA-NAS-shfld/inner_cam_01/ | tail -n1)";done > /dev/null 2>&1

# and at least one empty line should be at the end of the file!

Ctrl+K, Ctrl+X

Then in the Cubietruck using PuTTY was prepared by mounting the NAS folder for archive video from a USB camera:

apt-get install nfs-common

mkdir /mnt/nvr

echo "192.168.1.75:/export/CA-NAS-shfld/inner_cam_01 /mnt/nvr nfs rw,async,soft,timeo=10,intr,nolock 0 0" >> /etc/fstab

Where:

192.168.1.75 is the IP address of the camper's NAS,

/export/CA-NAS-shfld/inner_cam_01 is the camper's NAS shared folder for USB camera video archive, which is described here above.

Then all connected USB cameras were listed:

ls /dev/video*

The USB camera was then connected to Cubietruck. Once again, all connected USB devices were listed:

ls /dev/video*

One new line that appeared in the second list was the alias of the wired USB camera. In this case it was /dev/video0.

Then the parameters of the USB camera were determined:

v4l2-ctl -d /dev/video0 --all

These camera parameters should be noted:

Width/Height : 1280/720

Pixel Format : 'MJPG'

Frames per second: 25.000 (25/1)

These settings are best used and do not make any other changes to minimize CPU usage.

Then the follows commands were made. Since crontab was first launched in Cubietruck, the issue of editor selection was raised. Nano was selected:

chmod ugo+rwx /dev/video*

crontab -e

1, Enter

Then there was added to the end of the open file:

@reboot sleep 110 && /usr/local/bin/mjpg_streamer -i "input_uvc.so -r 1280x720 -d /dev/video0 -f 25 -q 80" -o "output_http.so -p 8080 -w /usr/local/share/mjpg-streamer/www" > /dev/null 2>&1

@reboot sleep 110 && mount /mnt/nvr > /dev/null 2>&1

*/2 * * * * ffmpeg -f mjpeg -r 5 -i "http://localhost:8080/?action=stream" -t 120 -c:v copy /mnt/nvr/`date +\%Y\%m\%d_\%H\%M\%S`.avi > /dev/null 2>&1

@hourly killall mjpg_streamer > /dev/null 2>&1

@hourly sleep 60 && /usr/local/bin/mjpg_streamer -i "input_uvc.so -r 1280x720 -d /dev/video0 -f 25 -q 80" -o "output_http.so -p 8080 -w /usr/local/share/mjpg-streamer/www" > /dev/null 2>&1

# and at least one empty line should be at the end of the file!

Ctrl+O, Enter, Ctrl+X

reboot

Approximately 2 minutes after the download, streaming from the USB camera was available at http://192.168.1.72:8080/stream_simple.html via browser or at http://192.168.1.72:8080/?action=stream via VLC.

Where 192.168.1.72 is the IP Cubietruck (CA-Host1) in the camper’s network.

The streaming archive from the USB camera will be stored on the camper's NAS in the CA-NAS-shfld/inner_cam_01 shared folder, fragmented into files lasting 2 min each.

The other variant for archive a video from the USB camera is listen http of Cubietruck on the camper's NAS side by ffmpeg like ordinary IP-camera (but with http protocol). But a static IP is need for this for Cubietruck (CA-Host1). What the method is best - is philosophy.

 

A software you can load from this site is free for a non-commercial use except for components for which their owners declared their own rights. Can be limited by local laws.

No your data will be collected with a software you can load from this site.

 

Get updates