Erkennen von SzenenÀnderungen und Speichern von h264-Videoclips auf Raspberry Pi ohne Dekodierung


Guten Tag. In diesem Artikel werde ich Ihnen alles andere als das erste Mal erklĂ€ren, wie Sie gleichzeitig Bewegung erkennen und Videos im H264-Format auf Raspberry Pi 3 und schwĂ€cheren Plattformen speichern / senden können. Ich werde mit denselben Neulingen in der Welt von Raspberry Pi wie ich ĂŒber das berichten, was ich in ein paar Tagen herausgefunden habe, wĂ€hrend ich herausgefunden habe, wie ich das Problem lösen kann. Ich werde ĂŒber die Arbeit mit der Raspberry Pi-Kamera in einer einfachen menschlichen Sprache sprechen.


" CSI- Raspberry Pi v.1.3 2.1 720p @ 25 FPS, 1 h264, , ".


, , .


, , , ( ) , , .

RPi, , OpenCV, , - , ffmpeg, - .


OpenCV, , : " RGB/MJPEG, - H264 MP4...".


Raspberry Pi , - , datasheets- ( ), — , .


, Raspberry Pi . , , , 2.8-3.2 . , , CS-mount , . - 3d-, — , Thingverse .


Raspberry 3 / — . FullHD OpenMAX.


: Raspberry Pi - H264 -.


FFmpeg :


#!/bin/bash

SS=$1
FPS=$2

WIDTH=1600
HEIGHT=1200

while :
do

ffmpeg -f video4linux2 -input_format h264 -video_size ${WIDTH}x${HEIGHT} \
    -framerate $FPS -i /dev/video0 -vcodec copy -map 0 \
    -segment_time $SS -f segment \
    -strftime 1 -reset_timestamps 1 \
    -segment_format mp4 /video/file_%s.mp4
done

$SS FPS $FPS , unix-timestamp. , MP4. CPU . , FTP.


v2.1 1080p — ( FOV). 1600x1200 — FPS. , , ffmpeg raspivid (. ) . .


, , , RAM GPU Raspberry Pi, - — .

H264, , . : Raspberry Pi 3 FullHD OpenCV , 1280x720 @ 30 FPS .


H264? — H264.


Raspberry Pi (motion vectors) H264. . , .


Raspberry Pi , MV :


typedef struct
{
   signed char x_vector;
   signed char y_vector;
   short sad;
} INLINE_MOTION_VECTOR; 

{x,y}_vector — , sad — . sad vectors . sad, motion vectors.


FFmpeg motion vectors , Raspivid:


#!/bin/bash

SS=$1
FPS=$2

W=1600
H=1200

while :
do
    raspivid -pts -stm -w $W -h $H -fps $FPS -t 0 \
                    -sn $(date +%s) -sg $(($SS*1000)) \
                    -o /video/video_%d.h264 -x /video/mv_%d.txt
done

, raspivid +1, , timestamp, stat .

FFmpeg CVLC, RTSP . , — motion vectors .


, "", , , . . FPS=25 ( 30) , , 50Hz , .


— , , MV, , . . , , .

, , RPi — H264 , MV.


, *.h264 — H264, MP4, VLC, , , . Raspberry Pi gpac:


sudo apt install -y gpac

h264 mp4 :


time MP4Box -add /video/video_1588645858.h264 /video/video_1588645858.mp4
AVC-H264 import - frame size 1280 x 720 at 25.000 FPS
AVC Import results: 1560 samples - Slices: 26 I 1534 P 0 B - 0 SEI - 26 IDR
Saving to /video/video_1588645858.mp4: 0.500 secs Interleaving

real    0m11.164s
user    0m0.548s
sys 0m0.469s

11 Raspberry Pi 3, .


MV :


import os
import sys
import struct
import numpy as np

resolution = [1280, 720]

framelength = int(((resolution[0] + 16) / 16) * (resolution[1] / 16) * 4)

framedata = []

cnt = 0

while True:
    data = sys.stdin.read(framelength)

    if data == '':
      break

    cnt += 1

    framedata = struct.unpack('>%db' % framelength, data)
    vectors = np.reshape(framedata[:(resolution[1]/16 * (resolution[0]/16 + 1) * 4)], (resolution[1]/16, resolution[0]/16 + 1, 4)).astype(np.float32)
    vectors = np.multiply(vectors[:, :, 0:1], vectors[:, :, 0:1])

    print int(np.sum(vectors))

C, .


time $(cat /video/mv_1588645871.txt| python proc.py > /dev/null)

real    0m26.288s
user    0m25.005s
sys 0m0.583s

, NumPy ( C), , , , 50% , . MV, , .


, :


, , — . — . .


:


cat /video/mv_1588645871.txt | python proc.py | awk '{ if ($1 > 0) print "motion" }' | grep motion > /dev/null
echo $?
0

, . , FTP, .


, " " , , Raspberry Pi .


, , , MV . Medium, MV Python.


Der Artikel mag fĂŒr Profis alltĂ€glich erscheinen, aber ich musste viel Zeit aufwenden, um mich mit diesen Dingen zu befassen. Ich hoffe, dass dies fĂŒr AnfĂ€nger, die anfangen, mit Videos auf der Raspberry Pi-Plattform zu arbeiten, nĂŒtzlich sein wird.


All Articles