I'm using code based on the Timelapse video example, but as I'm recording for long periods (12 hours or so) I'm trying to break the output up into smaller files of an hour each to process while the capture is running.
I got that working, but only the first timestamp file has a header.
There is probably an easy fix, like add the header whenever a new output is created, not just when the timestamp is 0. Perhaps put that bit in the init?
Here's a minimal exampleand the start and end of each timestamp fileI'm running on a Pi 2B with Camera 2 NoIR and fully updated Buster 32-bit.
This probably is something really simple, but I'm pretty much a beginner at Python and cameras too.
I got that working, but only the first timestamp file has a header.
There is probably an easy fix, like add the header whenever a new output is created, not just when the timestamp is 0. Perhaps put that bit in the init?
Here's a minimal example
Code:
#!/usr/bin/python3import timefrom picamera2 import Picamera2from picamera2.encoders import H264Encoder, Qualityfrom picamera2.outputs.fileoutput import FileOutput# Define an output which divides all the timestamps by a factorclass TimelapseOutput(FileOutput): def __init__(self, file=None, pts=None, speed=10): self.speed = int(speed) super().__init__(file, pts) def outputtimestamp(self, timestamp): if timestamp == 0: # Print timecode format for the first line print("# timestamp format v2", file=self.ptsoutput, flush=True) # Divide each timestamp by factor to speed up playback timestamp //= self.speed super().outputtimestamp(timestamp)# Set the parameters for the timelapsespeedup_factor = 2 # speed increaseframerate = 25.0 # fpsresolution = (640, 480)picam2 = Picamera2()config = picam2.create_video_configuration(main={"size": resolution})picam2.configure(config)encoder = H264Encoder()picam2.start()# Give time for Aec and Awb to settle, before disabling themtime.sleep(1)picam2.set_controls({"AeEnable": False, "AwbEnable": False, "FrameRate": framerate})# And wait for those settings to take effecttime.sleep(1)# Record a file - timestamp file has headeroutput = TimelapseOutput("test1.h264", "test1.txt", speedup_factor)encoder.output = outputpicam2.start_encoder(encoder, quality=Quality.VERY_HIGH)time.sleep(10) # 10 seconds for testingpicam2.stop_encoder()# Record a second file - timestamp file doesn't have headeroutput = TimelapseOutput("test2.h264", "test2.txt", speedup_factor)encoder.output = outputpicam2.start_encoder(encoder, quality=Quality.VERY_HIGH)time.sleep(10) # 10 seconds for testingpicam2.stop_encoder()picam2.stop()
Code:
rpdom@cam0:~ $ head -2 test1.txt# timestamp format v20.000rpdom@cam0:~ $ tail -2 test1.txt4959.9924979.993rpdom@cam0:~ $ head -2 test2.txt5599.9935619.993rpdom@cam0:~ $ tail -2 test2.txt10559.98710579.987
This probably is something really simple, but I'm pretty much a beginner at Python and cameras too.
Statistics: Posted by rpdom — Sat Feb 10, 2024 11:40 am