Skip to content

VIDEO Camera

wifiBlocker EUROPE edited this page Dec 25, 2024 · 7 revisions

Install motion on iBlocker

Uncomment below line from /etc/apk/repositories

http://dl-cdn.alpinelinux.org/alpine/v3.20/community

Launch apk update

Launch below commands (as root):

apk add build-base v4l-utils autoconf automake bash gettext-dev v4l-utils-dev linux-headers libjpeg-turbo-dev ffmpeg-dev libmicrohttpd-dev libwebp-dev

mkdir /opt/IB/MOTION    - the Motion video records location

Download and unzip motion-release-4.6.0.tar.gz in /home/iblocker/

cd /home/iblocker/motion-release-4.6.0
autoreconf -fiv
./configure
make
make install

-> conf file located in /usr/local/etc/motion

 cp motion-dist.conf motion.conf and adjust the settings with iblocker motion.conf

/usr/local/bin/motion start or stop

As root edit crontab (crontab -e) and add below lines:

# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
#*/15    *       *       *       *       /etc/periodic/15min/empty_motion
0       *       *       *       *       /etc/periodic/hourly/empty_motion
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly
@reboot /var/www/localhost/cgi-bin/modem/AT/ushubctl-reset-hub.cgi
@reboot /var/www/localhost/cgi-bin/piwall/camera.cgi &
@reboot /var/www/localhost/cgi-bin/piwall/check_ssh_tunnel.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Read_SMS_Daemon.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Usb0-Reboot-Daemon.cgi &

Save and exit.

or add below command in crontab (instead of check_ssh_tunnel script):

@reboot autossh -M 0 -q -i /home/iblocker/.ssh/id_ed25519 iblocker@8x.ab4.17z.22x -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 80xy:localhost:8081 &

iBlocker is configured for an USB camera: a daemon will automatically detect it and use it via motion. Used port for video is 8081.

motion.conf settings below:

daemon on
process_id_file /var/run/motion/motion.pid
setup_mode off
logfile /var/log/motion/motion.log
log_level 6
log_type all
videodevice /dev/video0
; tunerdevice /dev/tuner0
input -1
power_line_frequency -1
rotate 0
flip_axis none
width 1280
height 720
framerate 30
minimum_frame_time 0
; netcam_url value
; netcam_userpass value
netcam_keepalive off
; netcam_proxy value
netcam_tolerant_check off
rtsp_uses_tcp on
; mmalcam_name vc.ril.camera
; mmalcam_control_params -hf
auto_brightness off
brightness 0
contrast 0
saturation 0
hue 0
roundrobin_frames 1
roundrobin_skip 1
switchfilter off
threshold 100
threshold_tune off
noise_level 32
noise_tune on
despeckle_filter EedDl
; area_detect value
; mask_file value
smart_mask_speed 0
lightswitch 0
minimum_motion_frames 1
pre_capture 5
post_capture 900
event_gap 0
max_movie_time 0
emulate_motion off
output_pictures off
output_debug_pictures off
quality 75
picture_type jpeg
ffmpeg_output_movies on
ffmpeg_output_debug_movies off
ffmpeg_bps 400000
ffmpeg_variable_bitrate 0
ffmpeg_video_codec mkv
ffmpeg_duplicate_frames true
timelapse_interval 0
timelapse_mode daily
timelapse_fps 30
timelapse_codec mpg
use_extpipe off
;extpipe mencoder -demuxer rawvideo -rawvideo w=%w:h=%h:i420 -ovc x264 -x264encopts bframes=4:frameref=1:subq=1:scenecut=-1:nob_adapt:threads=1:keyint=1000:8x8dct:vbv_bufsize=4000:crf=24:partitions=i8x8,i4x4:vbv_maxrate=800:no-chroma-me -vf denoise3d=16:12:48:4,pp=lb -of   avi -o %f.avi - -fps %fps
;extpipe x264 - --input-res %wx%h --fps %fps --bitrate 2000 --preset ultrafast --quiet -o %f.mp4
;extpipe mencoder -demuxer rawvideo -rawvideo w=%w:h=%h:fps=%fps -ovc x264 -x264encopts preset=ultrafast -of lavf -o %f.mp4 - -fps %fps
;extpipe ffmpeg -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -vcodec libx264 -preset ultrafast -f mp4 %f.mp4
snapshot_interval 0
locate_motion_mode off
locate_motion_style box
text_right %Y-%m-%d\n%T-%q
; text_left CAMERA %t
text_changes off
text_event %Y%m%d%H%M%S
text_double off
;exif_text %i%J/%K%L
target_dir /opt/IB/MOTION
snapshot_filename %v-%Y%m%d%H%M%S-snapshot
picture_filename %v-%Y%m%d%H%M%S-%q
movie_filename %v-%Y%m%d%H%M%S
timelapse_filename %Y%m%d-timelapse
ipv6_enabled off
stream_port 8081
stream_quality 50
stream_motion off
stream_maxrate 100
stream_localhost off
stream_limit 0
stream_auth_method 0
; stream_authentication iblocker:Test#1234
; stream_preview_scale 25
; stream_preview_newline no
webcontrol_port 8082
webcontrol_localhost on
webcontrol_html_output on
; webcontrol_authentication username:password
webcontrol_parms 0
track_type 0
track_auto off
;track_port /dev/ttyS0
;track_motorx 0
;track_motorx_reverse 0
;track_motory 1
;track_motory_reverse 0
;track_maxx 200
;track_minx 50
;track_maxy 200
;track_miny 50
;track_homex 128
;track_homey 128
track_iomojo_id 0
track_step_angle_x 10
track_step_angle_y 10
track_move_wait 10
track_speed 255
track_stepsize 40
quiet on
; on_event_start value
; on_event_end value
; on_picture_save value
; on_motion_detected value
; on_area_detected value
; on_movie_start value
; on_movie_end value
; on_camera_lost value
; on_camera_found value
; sql_log_picture on
; sql_log_snapshot on
; sql_log_movie off
; sql_log_timelapse off
; sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')
; database_type value
; database_dbname value
; database_host value
; database_user value
; database_password value
; database_port value
; database_busy_timeout 0
; video_pipe value
; motion_video_pipe value
; camera /etc/motion/camera1.conf
; camera /etc/motion/camera2.conf
; camera /etc/motion/camera3.conf
; camera /etc/motion/camera4.conf
; camera_dir /usr/etc/motion/conf.d

To restrict access to camera with user/password, add below lines to /usr/local/etc/motion/motion.conf and reboot.

stream_auth_method 1
stream_authentication user:password

Camera resolutions (width x height):

640 x 360
960 x 544
1280 x 720
1920 x 1080
3840 x 1080
4800 x 1200

Port 8081 SSH Tunneling from iblocker to a public server

Add user iblocker to group root:

~# adduser iblocker root

As user=iblocker generate public/private rsa key pair

~$ ssh-keygen -b 4096

Note: Leave password blank

You will need to copy id_*.pub file from iblocker /home/autossh/.ssh/ to the /home/iblocker/.ssh/authorized_keys file on the remote system you want to connect to for the tunnel - 8x.ab4.17z.22x.

or

ssh-copy-id -i /home/iblocker/.ssh/id_ed25519 iblocker@8x.ab4.17z.22x 

Make a test connection: ~$ ssh iblocker@8x.ab4.17z.22x
The authenticity of host '8x.ab4.17z.22x (8x.ab4.17z.22x)' can't be established. ED25519 key fingerprint is SHA256:fjuh8QWIkAXQblablablabla. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes ~$ exit

Create SSH tunnel:

ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 80xy:localhost:8081 iblocker@8x.ab4.17z.22x -i /home/iblocker/.ssh/id_ed25519   - creates a SSH tunnel

As iblocker edit crontab (crontab -e) and add below line:

@reboot ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 80xy:localhost:8081 iblocker@8x.ab4.17z.22x -i /home/iblocker/.ssh/id_ed25519 &

Save and exit.

pgrep -f 8081 - returns Process_ID for the SSH tunnel

The command - kill -9 pgrep -f 8081 - will stop the SSH tunnel created on port 8081

On server 8x.ab4.17z.22x, change below lines from /etc/sshd_config:

AllowTcpForwarding yes
GatewayPorts yes

then systemctl ssh.service restart

Then on server 8x.ab4.17z.22x, port 8081 is open and could be accessed as http://8x.ab4.17z.22x:8081

Explanation of ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 8081:localhost:8081 iblocker@8x.ab4.17z.22x:

  • -N - Do not execute a remote command; this is useful for just forwarding ports.

  • ServerAliveInterval - the number of seconds that the client will wait before sending a "server alive" message to the server to keep the connection alive.

  • ServerAliveCountMax - the number of "server alive" messages which may be sent without reply from the server. If this threshold is reached ssh will disconnect from the server, terminating the session.

  • ExitOnForwardFailure - if set to "yes", the connection shall be terminated if ssh cannot set up all requested dynamic, tunnel, local, and remote port forwardings, (e.g. if either end is unable to bind and listen on a specified port).

  • -R 8080:localhost:80 - Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side. In this case, it means forward port 80 of the remote server to port 8080 of the client.

e.g. Open SSH to iBlocker on port 2022:

ssh -f -N -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o ExitOnForwardFailure=yes -R 2022:localhost:22 iblocker@8x.ab4.17z.22x

Then ssh iblocker@8x.ab4.17z.22x


Delete Motion movies

Create a script (empty_motion.sh, chmod 755 empty_motion.sh) in /etc/periodic/hourly.

Script should contain one line (outside #!/bin/sh):

  1. Delete files older than 12 hours:
find /opt/IB/MOTION/ -name "*" -type f -mmin +720 -delete
  1. Delete files older than 1 day:
find  /opt/IB/MOTION/ -name "*" -type f -mtime +1 -delete
  1. As root use crontab -e and add below lines:
# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
#*/15    *       *       *       *       /etc/periodic/15min/empty_motion
0       *       *       *       *       /etc/periodic/hourly/empty_motion
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly
@reboot /var/www/localhost/cgi-bin/modem/AT/ushubctl-reset-hub.cgi
@reboot /var/www/localhost/cgi-bin/piwall/camera.cgi &
@reboot /var/www/localhost/cgi-bin/piwall/check_ssh_tunnel.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Read_SMS_Daemon.cgi &
@reboot /var/www/localhost/cgi-bin/modem/AT/Usb0-Reboot-Daemon.cgi &

Note: empty_motion.sh is added without extension in crontab.

--------//-------------

and restart cron:

 rc-service crond restart

Clone this wiki locally