/ Mask_Efficacy / take_video.py
take_video.py
1 # SPDX-FileCopyrightText: 2020 Carter Nelson for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 import math 7 import os 8 import RPi.GPIO as GPIO 9 import simpleaudio as sa 10 import picamera 11 12 camera = picamera.PiCamera() 13 camera.resolution = (1920, 1080) 14 VIDEO_LENGTH = 10 15 16 BUTTON = 4 17 GPIO.setmode(GPIO.BCM) 18 GPIO.setup(BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP) 19 20 SIN_LENGTH = 500 21 SIN_AMPLITUDE = 127 22 SIN_OFFSET = 128 23 DELTA_PI = 2 * math.pi / SIN_LENGTH 24 sine_wave = bytes([ 25 int(SIN_OFFSET + SIN_AMPLITUDE * math.sin(DELTA_PI * i)) for i in range(SIN_LENGTH) 26 ]) 27 28 def play_tone(length): 29 play_back = sa.play_buffer(sine_wave*length, 2, 2, 44100) 30 play_back.wait_done() 31 32 run_number = int(input("Enter run number:")) 33 34 print("Press button when ready.") 35 while GPIO.input(BUTTON): 36 pass 37 38 play_tone(100) 39 camera.start_recording("run_{:03d}.h264".format(run_number)) 40 camera.wait_recording(VIDEO_LENGTH) 41 camera.stop_recording() 42 play_tone(100) 43 44 err = os.system("MP4Box -add run_{0:03d}.h264 run_{0:03d}.mp4".format(run_number))