From 2080b0a6fc793d01e544e07588926a098b61c8f1 Mon Sep 17 00:00:00 2001 From: Zen Date: Tue, 8 Dec 2020 23:33:04 +0300 Subject: [PATCH] first commit --- cam1.sh | 16 ++++++++++++++ cam2.sh | 11 ++++++++++ camera.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ read_sensor.py | 18 ++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100755 cam1.sh create mode 100755 cam2.sh create mode 100755 camera.py create mode 100755 read_sensor.py diff --git a/cam1.sh b/cam1.sh new file mode 100755 index 0000000..a662d6a --- /dev/null +++ b/cam1.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +time_UNIX=$(date +%s) +time_HUMAN=$(date '+video_%d.%m.%y_%H:%M:%S') +PID_1=$(ffmpeg -nostdin -f v4l2 -framerate 20 -video_size 320x240 -i /dev/video0 -filter_complex "drawtext=fontfile=/usr/share/fonts/truetype/arial.ttf: text='%{pts\:localtime\:$time_UNIX\:%d.%m.%Y %T}': x=180 : y=5 : box=1" -c:a copy $(echo $time_HUMAN)_1.mp4 &> /dev/null) & + +sleep 1 + +ffmpeg_str=$(ps auxw | grep "copy $(echo $time_HUMAN)_1.mp4" | head -n1) +array=( $ffmpeg_str ) +echo ${array[1]} > /tmp/pid_1 + +#sleep 10 + +#kill -SIGINT $(cat /tmp/pid_1) +#echo Finish record!!! \ No newline at end of file diff --git a/cam2.sh b/cam2.sh new file mode 100755 index 0000000..4d768b5 --- /dev/null +++ b/cam2.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +time_UNIX=$(date +%s) +time_HUMAN=$(date '+video_%d.%m.%y_%H:%M:%S') +PID_1=$(ffmpeg -nostdin -f v4l2 -framerate 20 -video_size 320x240 -i /dev/video1 -filter_complex "drawtext=fontfile=/usr/share/fonts/truetype/arial.ttf: text='%{pts\:localtime\:$time_UNIX\:%d.%m.%Y %T}': x=180 : y=5 : box=1" -c:a copy $(echo $time_HUMAN)_2.mp4 &> /dev/null) & + +sleep 1 + +ffmpeg_str=$(ps auxw | grep "copy $(echo $time_HUMAN)_2.mp4" | head -n1) +array=( $ffmpeg_str ) +echo ${array[1]} > /tmp/pid_2 diff --git a/camera.py b/camera.py new file mode 100755 index 0000000..97af0f4 --- /dev/null +++ b/camera.py @@ -0,0 +1,57 @@ +#!/usr/bin/python3 + +import sys +import time +import os +import signal + + +def stop_cams(): + f = open("/tmp/pid_1", "r") + pid1 = int(f.read()) + f.close() + f = open("/tmp/pid_2", "r") + pid2 = int(f.read()) + f.close() + + os.kill(pid1, signal.SIGINT) + os.kill(pid2, signal.SIGINT) + +def read_old_time(): + f = open("/tmp/sensor", "r") + sensor_time = int(f.read()) + f.close() + return sensor_time + + +def main(): + record_time = 60 + + os.system("echo 0 > /tmp/sensor") + #os.system("./read_sensor.py &") + + while (True): + time.sleep(1) + print (int(time.time()) - read_old_time()) + + if ((int(time.time()) - read_old_time()) <= record_time): + print("Wait to start camera script.") + os.system("./cam1.sh") + os.system("./cam2.sh") + time.sleep(10) + + print("Start min write.") + time.sleep(record_time) + + while ((int(time.time()) - read_old_time()) < record_time): + t = read_old_time() - (int(time.time()) - record_time) + print("Continue record video on camera -> " + str(t) + ".") + time.sleep(t) + + print("Wait to stop camera script.") + stop_cams() + time.sleep(10) + print("Stop camera script.") + +if __name__ == '__main__': + main() diff --git a/read_sensor.py b/read_sensor.py new file mode 100755 index 0000000..d539c4f --- /dev/null +++ b/read_sensor.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 + +import time +import Adafruit_BBIO.GPIO as GPIO +# Set up gpio 60 as input +GPIO.setup("P9_12", GPIO.IN) +# Sets an event when pin 60 changes to 1 +GPIO.add_event_detect("P9_12", GPIO.RISING) +i = 0 + +while True: + time.sleep(1) + if GPIO.event_detected("P9_12"): + f = open('/tmp/sensor', 'w') + f.write(str(int(time.time())) + '\n') + f.close() + i = i + 1 + print(str(i) + " Event!!!") \ No newline at end of file