bootstrap theme

Router becomes
video recorder
for IP cameras

Some routers have powerful CPU and USB-port on a board and can be used as a video recorder in addition to routing functions, in order for collect and distribute video and sound from IP-cameras that streams only H264/265 RTSP (as most modern cheap high resolution IP cameras). Moreover, some of routers CPU has DSP (digital signal processor), and so can be highly effective for a video stream decoding (change the resolution, the framerate, etc). As a storage can be used USB flash, USB-HDD, USB-SSD. A NAS in home network can be used too.

Mobirise

Not any router can be upgraded as here described, depend on used CPU and manufacturer's limitations of firmware reflashing. For example, was failed to upgrade the Mediatek MTK7621 (MIPS) based router. But was perfectly upgrade the router based on Qualcomm IPQ4018 (Cortex-A7).

All settings were made via Windows PC. In some cases will need switch off the PC firewall while settings.

On the router was installed OpenWrt OS in order to have Linux on a board. OpenWRT OS and the home network was deployed as described on the appropriate page of OpenWrt project for this router model. Then OpenWRT was logged in from PC on IP 192.168.1.1.

Mobirise

In menu "Network.Diagnostics" was pressed "Ping" for the checking of Internet connection.

The FFmpeg package was used for collect the stream from the IP camera and store that in files by piecemeal (2 minutes length of each part). OpenWrt OS haves FFmpeg build in, but this version not work with H264/265 stream at this moment, despite this stream type is most used in cheap high resolution IP-cameras.

But up on OpenWrt OS (lightweight Linux) can be installed Debian OS (fullweight Linux). Then fullweight FFmpeg package can be installed at Debian and this version can works with H264/265 stream from IP cameras.

First step need to dramatically increase the memory of the router with a USB flash or USB-HDD or USB-SSD. Same time, this storage can be used for video archive if no NAS in the home network.

Mobirise

The router was achieved from PC via PuTTY on IP 192.168.1.1, port 22.

With 8Gb (any other volume can be) USB flash had plugged in the router's USB port, next commands were entered one by one to the router via PuTTY terminal:

opkg update

opkg install kmod-usb-core kmod-usb-storage kmod-fs-ext4 

opkg install kmod-scsi-core block-mount e2fsprogs fdisk

opkg install kmod-usb-uhci kmod-usb-ohci kmod-usb2

insmod usbcore

insmod uhci

insmod usb-ohci

insmod ehci-hcd

fdisk -l

The /dev/sda (name of USB flash, can be other) from the last command output was noted.

Then next commands were entered in terminal:

fdisk /dev/sda

d+Enter

d+Enter

"d+Enter" need to repeat till "No partition is defined yet!" message.

Then next commands were entered in terminal:

n+Enter

p+Enter

Enter

Enter

"Enter" need to repeat till "Partition 1 of type Linux and of size..." message.

Then next commands were entered in terminal:

w+Enter

mkfs.ext4 /dev/sda1

mkdir -p /mnt/usb

mount -t ext4 /dev/sda1 /mnt/usb -o rw,sync

tar -C /overlay -cvf - . | tar -C /mnt/usb -xvf -

vi /etc/config/fstab

In opened file, next lines were added after "i" key once pressed:

config 'mount'

    option target /overlay

    option device /dev/sda1

    option fstype ext4

    option options rw,sync

    option enabled 1

    option enabled_fsck 0

Then next keys were pressed for save changes and exit from file:

Esc

:wq

Enter

Then the router was rebooted:

reboot

Mobirise

Once rebooted, the router was with USB flash memory integrated.

One more time the router was achieved from PC via PuTTY on IP 192.168.1.1, port 22. Next commands were entered one by one to the router via PuTTY terminal:

opkg update

opkg install samba36-server luci-app-samba

opkg install debootstrap

cat /proc/cpuinfo

Mobirise

The output from last command showed the router's CPU architecture (here was ARMv7), this data was noted.

Mobirise

Next step within a list of Debian sites (mirrors) was chosen nearby server haves code for architecture, suitable for router's CPU. For router's ARMv7 was noted above, most suitable Debian target was armhf, as a result the mirror ftp.ch.debian.org/debian/ was noted.

Considering the data received above, the following commands were entered into the terminal:

mkdir debian

debootstrap --foreign --arch armhf buster ./debian http://ftp.ch.debian.org/debian/

And after very... very... long installation (need to rerun till no downloading's errors will, at this downloading time need to abstain from downloading other files within same home network), the following commands were entered into the terminal:

DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true

LC_ALL=C LANGUAGE=C LANG=C

chroot debian /debootstrap/debootstrap --second-stage

After one more very... very... long installation (at this downloading time need to abstain from downloading other files within same home network), the following commands were entered into the terminal:

DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true

LC_ALL=C LANGUAGE=C LANG=C

chroot debian dpkg --configure -a

mount -o bind /proc /root/debian/proc

mount -o bind /dev /root/debian/dev

mount -o bind /sys /root/debian/sys

chroot /root/debian /bin/bash

From this point, the fullweight Debian "Buster" started work on a router. In the terminal command input line is Debian but not OpenWrt now.

Note: if at this point the error "illegal function" rise, then the Debian target (armhf as here) was chosen wrong. May be need to try another target.

Then next commands were entered one by one to the router via PuTTY terminal (where cam01 is folder for the video archive):

apt-get update

apt-get install ffmpeg

exit

cd /root/debian/home

mkdir chroot chroot/cam01

Mobirise

Via OpenWRT webface, from PC on IP 192.168.1.1, in menu "Services.Network Shares.Edit Template" were added next strings for Samba server configuration. Then was clicked "Save and apply".

[archive]

    path = /root/debian/home/chroot

    force user = root

    read only = No

    guest ok = Yes

    hide dot files=yes

    hide files=/.*/lost+found/

    create mask = 0777

    directory mask = 0777

The IP camera was connected to the router (can be wired or Wi-Fi).

Mobirise

The camera's IP in home network was achieved using ONVIF Device Manager, this was 192.168.1.10.

Mobirise

In topic "Live video" of ONVIF Device Manager, under the window with the video, was found the link to the camera's RTSP stream.

With noted IP and RTSP link of the camera, next commands were entered in terminal:

crontab -e

i

@reboot sleep 10; DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C

@reboot sleep 20; chroot debian dpkg --configure -a

@reboot sleep 40; mount -o bind /proc /root/debian/proc; mount -o bind /dev /root/debian/dev; mount -o bind /sys /root/debian/sys

*/2 * * * * chroot /root/debian ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.10:554/user=admin_password=tlJwpbo6_channel=1_stream=0.sdp?real_stream -t 118 -vcodec copy -acodec copy /home/chroot/cam01/`date +\%Y\%m\%d\%H\%M\%S`.avi > /dev/null 2>&1

*/6 * * * * while [ $(du -sm /root/debian/home/chroot/cam01| cut -f1) -gt 4000 ]; do rm -f /root/debian/home/chroot/cam01/"$(ls -1c /root/debian/home/chroot/cam01/ | tail -n1)";done > /dev/null 2>&1


# Note: one empty string must be here at the end of file

Esc

:wq

Enter

reboot

Where -gt 4000 substring mean the maximum size (here is near 4 Gb) of the video archive for the camera. Every 6 minutes, older files in the video archive folder, will delete while the folder size will no more the pointed size. This substring must be changed depend of used USB-HDD/SSD.

Mobirise

The video archive was accessed via Windows PC Explorer.

That's all. Ever since this router is not only router, but video recorder too. Was no experiment with two ore more IP cameras, but test with one only IP camera do not show overload of the router's CPU.

The USB flash was used here only in experimental order. On practice, USB HDD/SSD must be used. In some cases, USB HDD/SSD must be powered external, via USB external powered HUB, for example.

The video archive can be shared not only in the home network, but with global access in Internet too. For make this, need to install FTP server in OpenWrt, and use router's port mapping with static IP, external IP, or temporary IP with alerts about them changes.

If this router's computer planned to use only as video recorder, then is good idea to switch off Wi-Fi radios on a board - will be less EM radiation and more power for USB.

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.