Początkowo myślałem o : mjpg-streamer ale nie jest on już rozwijany i nie ma wsparcia developerów ...przynajmniej na dzień dzisiejszy. Instalujemy w/w jeśli jest w repozytorium lub kompilujemy najnowszą wersję z github-a (uwaga! najpierw instalując brakujące paczki jak podpowiedzi na github-ie!)
Kod: Zaznacz cały
apt install ustreamer
Kod: Zaznacz cały
ID 1bcf:2286 Sunplus Innovation Technology Inc. FHD Camera
Uwaga! po kompilacji najnowszy ustreamer uruchamiamy w/w komendą z kompilowanego folderu : ./ustreamer ... lub podmieniamy pliki w systemie w ścieżce:
Kod: Zaznacz cały
/usr/bin/ustreamer
/usr/bin/ustreamer-dump
Kod: Zaznacz cały
lsusb
v4l2-ctl --list-devices
Kod: Zaznacz cały
allwinner,sun50i-h6-vpu-g2-dec (platform:1c00000.video-codec-g2):
/dev/video0
/dev/media0
cedrus (platform:cedrus):
/dev/video1
/dev/media1
FHD Camera: FHD Camera (usb-5311000.usb-1):
/dev/video2
/dev/video3
/dev/media2
Kod: Zaznacz cały
v4l2-ctl -d /dev/video2 --list-formats-ex
Kod: Zaznacz cały
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture
[0]: 'MJPG' (Motion-JPEG, compressed)
Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Interval: Discrete 0.050s (20.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.100s (10.000 fps)
Interval: Discrete 0.200s (5.000 fps)
Interval: Discrete 1.000s (1.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
[1]: 'YUYV' (YUYV 4:2:2)
Size: Discrete 1920x1080
Interval: Discrete 0.200s (5.000 fps)
Interval: Discrete 0.333s (3.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.200s (5.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.050s (20.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
do uruchomienia w/w wystarczy wpis w terminalu:
Kod: Zaznacz cały
ustreamer --host=192.168.X.X --port=XXXX --device=/dev/video2 --quality=100 --format=MJPEG --resolution=1920x1080
Jeśli mamy kłopot (jak ja) z ciągle zmieniającą się ścieżka do kamery USB ( /dev/video0 / 1 / 2 itd )pomimo używania tego samego złącza USB....możemy zidentyfikować nazwę naszej kamery jaką przypisuje system w ścieżce : /dev/v4l/by-id/ u mnie jest to : /dev/v4l/by-id/usb-Sunplus_IT_Co_FHD_Camera-video-index0 potem w całej konfiguracji możemy zastąpić : /dev/video1 / 2 / 3 itd wpisem: /dev/v4l/by-id/usb-Sunplus_IT_Co_FHD_Camera-video-index0
Dotyczy to nie tylko programu ustreamer ale także np. motion
Teraz możemy np . stworzyć skrypt uruchamiany przy starcie systemu żeby włączyć kamerę USB
Kod: Zaznacz cały
#!/bin/bash
ustreamer --host=192.168.1.XX --port=XXXX --device=/dev/v4l/by-id/usb-Sunplus_IT_Co_FHD_Camera-video-index0 --quality=100 --format=MJPEG --resolution=1920x1080 &
Przydatne informacje uzyskamy wpisując w terminalu : ustreamer -help
np. użycie loginu i hasła w konfiguracji : --user=login / --passwd=hasło
Detekcję ruchu (ewentualne wysyłanie powiadomień na maila / sms ) skonfigurowałem jednak w innym programie który jest bardziej do tego preferowany ale jednak dla mojej kamery i bezpośredniego monitoringu przez np. http zbyt obciążał CPU !...może wynika to z racji iż nie chciał prawidłowo działać z metodą przechwytywania: MJPEG a jedynie z: YUYV
Instalujemy program motion:
Kod: Zaznacz cały
apt install motion
Kod: Zaznacz cały
sudo systemctl enable motion.service
sudo systemctl start motion.service
sudo systemctl staus motion.service
Kod: Zaznacz cały
#!/bin/bash
SERVICE="motion"
if systemctl is-active --quiet ${SERVICE}.service; then
echo "${SERVICE} jest uruchomiony. Wyłączam..."
sudo systemctl stop ${SERVICE}.service
echo "${SERVICE} został wyłączony."
else
echo "${SERVICE} jest wyłączony. Uruchamiam..."
sudo systemctl start ${SERVICE}.service
echo "${SERVICE} został uruchomiony."
fi
Kod: Zaznacz cały
crontab -e
Kod: Zaznacz cały
15 08 * * 1,2,3,4,5 /bin/bash /root/motion.sh >/dev/null 2>&1
15 22 * * 1,2,3,4,5 /bin/bash /root/motion.sh >/dev/null 2>&1
mój konfig dla kamery usb :/dev/video2 ... lub : /dev/v4l/by-id/usb-Sunplus_IT_Co_FHD_Camera-video-index0
wpis:
Kod: Zaznacz cały
# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 4.5.1
# Documentation: /usr/share/doc/motion/motion_guide.html
#
# This file contains only the basic configuration options to get a
# system working. There are many more options available. Please
# consult the documentation for the complete list of all options.
#
############################################################
# System control configuration parameters
############################################################
# Start in daemon (background) mode and release terminal.
daemon off
# Start in Setup-Mode, daemon disabled.
setup_mode off
# File to store the process ID.
; pid_file value
# File to write logs messages into. If not defined stderr and syslog is used.
log_file /var/log/motion/motion.log
# Level of log messages [1..9] (EMG, ALR, CRT, ERR, WRN, NTC, INF, DBG, ALL).
log_level 6
# Target directory for pictures, snapshots and movies
target_dir /root/foto
# Video device (e.g. /dev/video0) to be used for capturing.
#video_device /dev/video0
#video_device /dev/v4l/by-id/usb-LX-240924-XH_GENERAL_WEBCAM-video-index0
video_device /dev/v4l/by-id/usb-Sunplus_IT_Co_FHD_Camera-video-index0
# Parameters to control video device. See motion_guide.html
; video_params value
# The full URL of the network camera stream.
; netcam_url value
# Name of mmal camera (e.g. vc.ril.camera for pi camera).
; mmalcam_name value
# Camera control parameters (see raspivid/raspistill tool documentation)
; mmalcam_params value
############################################################
# Image Processing configuration parameters
############################################################
# Image width in pixels.
width 1280
# Image height in pixels.
height 720
# Maximum number of frames to be captured per second.
framerate 30
# Text to be overlayed in the lower left corner of images
text_left CAMERA1
# Text to be overlayed in the lower right corner of images.
text_right %Y-%m-%d\n%T-%q
############################################################
# Motion detection configuration parameters
############################################################
# Always save pictures and movies even if there was no motion.
emulate_motion off
# Threshold for number of changed pixels that triggers motion.
threshold 1500
# Noise threshold for the motion detection.
; noise_level 32
# Despeckle the image using (E/e)rode or (D/d)ilate or (l)abel.
despeckle_filter EedDl
# Number of images that must contain motion to trigger an event.
minimum_motion_frames 5
# Gap in seconds of no motion detected that triggers the end of an event.
event_gap 30
# The number of pre-captured (buffered) pictures from before motion.
pre_capture 3
# Number of frames to capture after motion is no longer detected.
post_capture 0
############################################################
# Script execution configuration parameters
############################################################
# Command to be executed when an event starts.
; on_event_start value
# Command to be executed when an event ends.
; on_event_end value
# Command to be executed when a movie file is closed.
; on_movie_end value
############################################################
# Picture output configuration parameters
############################################################
# Output pictures when motion is detected
picture_output on
# File name(without extension) for pictures relative to target directory
#picture_filename %Y%m%d%H%M%S-%q
picture_filename /%Y%m%d%H%M%S
############################################################
# Movie output configuration parameters
############################################################
# Create movies of motion events.
movie_output off
# Maximum length of movie in seconds.
movie_max_time 60
# The encoding quality of the movie. (0=use bitrate. 1=worst quality, 100=best)
movie_quality 45
# Container/Codec to used for the movie. See motion_guide.html
movie_codec mkv
# File name(without extension) for movies relative to target directory
movie_filename %t-%v-%Y%m%d%H%M%S
############################################################
# Webcontrol configuration parameters
############################################################
# Port number used for the webcontrol.
webcontrol_port 8080
# Restrict webcontrol connections to the localhost.
webcontrol_localhost off
# Type of configuration options to allow via the webcontrol.
webcontrol_parms 0
############################################################
# Live stream configuration parameters
############################################################
# The port number for the live stream.
stream_port 8081
# Restrict stream connections to the localhost.
stream_localhost off
##############################################################
# Camera config files - One for each camera.
##############################################################
; camera /usr/etc/motion/camera1.conf
; camera /usr/etc/motion/camera2.conf
; camera /usr/etc/motion/camera3.conf
; camera /usr/etc/motion/camera4.conf
##############################################################
# Directory to read '.conf' files for cameras.
##############################################################
; camera_dir /usr/etc/motion/conf.d
#input_format mjpeg
#v4l2_palette 2
# Wysyłanie e-maila z tematem i załącznikiem po wykryciu ruchu
#on_event_start /usr/bin/echo "Motion Detected!" | /usr/bin/mutt -s "Motion Alert" -a /root/foto/%Y%m%d%H%M%S.jpg -- xxxxxx@gmail.com
#video_params palette=6
#v4l2_palette 8
# Wysyłanie e-maila po zakończeniu detekcji ruchu
#on_event_end /usr/bin/echo "Motion ended" | /usr/bin/mutt -s "Motion Ended" -- xxxxxx@gmail.com
#on_event_start echo "Motion Detected!" | mutt -s "Motion Alert" -- xxxxxx@gmail.com
on_event_start /root/send_motion_mail.sh
#on_picture_save echo "Motion Detected! Załączam zdjęcie." | mutt -s "Motion Alert" -a /root/foto/%Y%m%d%H%M%S.jpg -- xxxxx@gmail.com
identyfikacja naszej kamery:
video_device /dev/v4l/by-id/usb-Sunplus_IT_Co_FHD_Camera-video-index0
parametry wideo:
width 1280
height 720
framerate 30
zapisywanie plików jpeg (zdjęć):
picture_output on
skrypt do konfiguracji wysyłania emaili/sms:
on_event_start /root/send_motion_mail.sh
Folder domyślny/domowy do zapisu zdjęć i wideo:
target_dir /root/foto
Muszę tu wspomnieć że mimo wielu prób i wpisów w prog. motion do wysyłki zdjęć i sms podczas detekcji ruchu nie udało mi się uzyskać zadowalających efektów tzn niestety program wykrywa ruch i wysyła powiadomienia bardzo często i są to setki !!! zdjęć itd dla samego zapisu to pożądane i jest OK ale już wysyłka na maila może być traktowana jako spam i zablokować nam adres email

wpis w send_motion_mail.sh:
Kod: Zaznacz cały
#!/bin/bash
LOCKFILE="/tmp/motion_mail.lock"
WAITSECS=20 # lub dłużej, np. 300 dla 5 minut
{
flock -n 9 || exit 1
NOW=$(date +%s)
LAST=0
[ -f "$LOCKFILE" ] && LAST=$(cat "$LOCKFILE")
DELTA=$((NOW - LAST))
if [ "$DELTA" -lt "$WAITSECS" ]; then
exit 0
fi
echo "$NOW" > "$LOCKFILE"
# najnowsze zdjęcie:
IMG=$(ls -t /root/foto/*.jpg 2>/dev/null | head -1)
if [ -n "$IMG" ]; then
echo "Wykryto ruch!" | mutt -s "Uwaga !!! Motion " -a "$IMG" -- xxxxxx@gmail.com
fi
} 9>/tmp/motion_mail_flock.lock
echo "$(date '+%F %T') $USER $IMG" >> /tmp/motion_mail_debug.log
curl -S -d "user=login&pass=hasło&type=sms&number=48xxxxxxxxx&text=Wykryto ruch !!!&from=user" https://api.mobitex.pl/sms.php > /dev/null
W systemie musimy także doinstalować parę programów:
Kod: Zaznacz cały
sudo apt install mutt
sudo apt install msmtp msmtp-mta mailutils
Program msmtp konfigurujemy dla swojego maila w pliku : ~/.msmtprc
Kod: Zaznacz cały
nano ~/.msmtprc
Kod: Zaznacz cały
# Konto Gmail
account gmail
host smtp.gmail.com
port 587
from xxxxxx@gmail.com
auth on
user xxxxxx@gmail.com
password 16-sto_znakowe_hasło_aplikacji_gmail_bez_spacji
tls on
# Domyślne konto
account default : gmail
Niestety usługa wysyłki sms jest płatna ( ale nie wiem czy uda się znaleźć usługę za FREE ) Uwaga po rejestracji i logowaniu w menu musimy utworzyć drugie hasło dla tzw. API i to hasło wykorzystujemy w konfiguracji do wysyłki sms + dodatkowo musi być ono zaszyfrowane w MD5 w necie jest sporo usług : md5 decrypt encrypt

login jest standardowy jak do konta + własny nr tel. / informację itd
skrypt w terminalu do wysyłki sms-a za pomocą prog. curl można wcześniej potestować:
Kod: Zaznacz cały
curl -S -d "user=login&pass=hasło&type=sms&number=48xxxxxxxxx&text=Wykryto ruch !!!&from=user" https://api.mobitex.pl/sms.php > /dev/null

Najlepiej stworzyć skrypt który sprawdza w cron co np 5sek. czy jest zapełniony w 100% ( czyli u mnie zadeklarowanego 1GB ) i wyczyścił / usuną zawartość... taka metoda "loop" znana z różnych gadżetów do ciągłego odnawiania zapisu na karcie CD itd.
w skrypcie np: /root/clear_if_full.sh
wpis:
Kod: Zaznacz cały
#!/bin/bash
FOLDER="/root/foto"
LIMIT=1073741824 # 1 GB w bajtach
# Oblicz aktualny rozmiar katalogu (w bajtach)
USAGE=$(du -sb "$FOLDER" | awk '{print $1}')
if [ "$USAGE" -ge "$LIMIT" ]; then
echo "[$(date)] Przekroczono limit! Czyszczenie katalogu $FOLDER"
rm -rf "$FOLDER"/*
fi
crontab -e
wpis:
Kod: Zaznacz cały
*/5 * * * * /root/clear_if_full.sh >/dev/null 2>&1
Oczywiście można korzystać z przeglądarki internetowej jak i np programu VLC do monitoringu podglądu na żywo ale raczej w dzisiejszych czasach tylko z sieci lokalnej LAN ...bo niestety ale nie mamy szyfrowania i może to być niebezpieczne

Żeby moc korzystać z podglądu z dowolnego miejsca w świecie trzeba uzyskać darmowy certyfikat od np. Let's Encrypt w systemie linux / przekierować pewne porty na routerze / i skorzystać z programów : certbot , apache2 lub enginx...ale to już raczej temat na nowy tuto-rial ...