first commit

master
Zen 4 years ago
parent 63f153a04c
commit 2080b0a6fc
  1. 16
      cam1.sh
  2. 11
      cam2.sh
  3. 57
      camera.py
  4. 18
      read_sensor.py

@ -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!!!

@ -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

@ -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()

@ -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!!!")
Loading…
Cancel
Save