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 routers CPU have DSP (digital signal processor), and so can be highly effective for video stream decoding (change the resolution, the frame rate, 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 described here, depending on used CPU and manufacturer's limitations of firmware reflashing. For example, it failed to upgrade the Mediatek MTK7621 (MIPS) based router. But had perfectly upgraded the router based on Qualcomm IPQ4018 (Cortex-A7).

All settings were made via Windows PC. In some cases will need to 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 the menu "Network.Diagnostics" was pressed "Ping" for the checking of Internet connection.

The FFmpeg package was used to collect the stream from the IP camera and store that in files by piecemeal (2 minutes length of each part). OpenWrt OS has FFmpeg built in, but this version does not 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). The fullweight FFmpeg package can be installed at Debian next and this version can work with H264/265 streams from IP cameras.

First step needs 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 archives if there is 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" needs to repeat till "No partition is defined yet!" message.

Then next commands were entered in terminal:

n+Enter

p+Enter

Enter

Enter

"Enter" needs 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 the 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) the nearby server was chosen that has code for architecture, suitable for the 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" rises, then the Debian target (armhf as here) was chosen wrong. Maybe 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 "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 the home network was achieved using ONVIF Device Manager, this was 192.168.1.10.

Mobirise

In the 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 means 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 than pointed size. This substring must be changed depending on the USB-HDD/SSD used.

Mobirise

The video archive was accessed via Windows PC Explorer.

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

The USB flash was used here only in experimental order. In 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 on the Internet too. To make this, it is necessary 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 the computer of this router is used only as a video recorder then it is a 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 of your data will be collected with a software you can load from this site.

Subscribe for updates.

Mobirise web creator - Find out