-
-
Save ghunti/58372b01650916f539d133a96a35efe8 to your computer and use it in GitHub Desktop.
picamera Copy_to test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import picamera | |
import sys | |
from picamera.frames import PiVideoFrameType | |
def find_seconds(stream, seconds, first_frame=PiVideoFrameType.sps_header): | |
pos = None | |
last = None | |
seconds = int(seconds * 1000000) | |
for frame in reversed(stream.frames): | |
print('Frame position: {}'.format(frame.position)) | |
if first_frame in (None, frame.frame_type): | |
print('First frame found: {}'.format(frame.position)) | |
pos = frame.position | |
if frame.timestamp is not None: | |
print('Frame timestamp: {}'.format(frame.timestamp)) | |
if last is None: | |
last = frame.timestamp | |
elif last - frame.timestamp >= seconds: | |
print('Elapsed: {}'.format(last - frame.timestamp)) | |
break | |
return pos | |
camera = picamera.PiCamera(resolution="1080p", framerate=30) | |
stream = picamera.PiCameraCircularIO(camera, seconds=20) | |
camera.start_recording(stream, format='h264') | |
try: | |
while True: | |
camera.wait_recording(10) | |
pos = find_seconds(stream, seconds=5) | |
print('Pos: {}'.format(pos)) | |
stream.copy_to('motion.h264', seconds=5) | |
sys.exit(0) | |
finally: | |
camera.stop_recording() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment