Progress this week.
1) First of all great to see the new "The Picamera2 Library" manual (build-date: 2025-03-20) https://datasheets.raspberrypi.com/came ... manual.pdf including sections on the IMX500, PyavOutput & CircularOutput2.
2) I don't currently have a github account so haven't reported Picamera2 issues directly to https://github.com/raspberrypi/picamera2/issues one day I might set up an account & publish this work.
3) I got to the bottom of the CircularOutput2 anomaly I'd encountered. Turns out after the first time the buffer is flushed circular = CircularOutput2(buffer_duration_ms=5000) has to be defined a second time to permit flushing again.
Unchecked code, simplified for brevity:
4) Am using mp4 rather than h264 files now thanks to PyavOutput.
5) Have managed to concatenate the flushed video (pre) and the live captured video using ffmpeg to create a single video file.
6) Got to the bottom of an issue in (5) when concatenating the two video files as somewhere along the PyavOutput / CircularOutput2 chain the flushed video is not correctly formatted in that the 'start' value can be something other than zero. This causes the concatenated video file to hang on to the last frame of the flushed file for a long time. For example a 20 second video file can play for 11 minutes, although the file size is correct. ffprobe shows such a 'start' value:
The following example fixes this:
The above also corrects the low 'bitrate' value.
I now have a working proof of concept CCTV with pre, event and post capture.
Now just the small matter of tidying up the messy code & make it more respectable![Laughing :lol:]()
1) First of all great to see the new "The Picamera2 Library" manual (build-date: 2025-03-20) https://datasheets.raspberrypi.com/came ... manual.pdf including sections on the IMX500, PyavOutput & CircularOutput2.
2) I don't currently have a github account so haven't reported Picamera2 issues directly to https://github.com/raspberrypi/picamera2/issues one day I might set up an account & publish this work.
3) I got to the bottom of the CircularOutput2 anomaly I'd encountered. Turns out after the first time the buffer is flushed circular = CircularOutput2(buffer_duration_ms=5000) has to be defined a second time to permit flushing again.
Unchecked code, simplified for brevity:
Code:
picam2 = Picamera2()config = picam2.create_video_configuration()picam2.configure(config)encoder = H264Encoder(bitrate=10000000)circular = CircularOutput2(buffer_duration_ms=5000)picam2.start_recording(encoder, circular)time.sleep(5)# A. Because this is not closed when we circular buffer stops, the remaining 5 seconds will get flushed into here.circular.open_output(PyavOutput(f"flushed-file-a.mp4"))picam2.stop_encoder()circular = CircularOutput2(buffer_duration_ms=5000)picam2.start_recording(encoder, circular)time.sleep(5)# B. Because this is not closed when we circular buffer stops, the remaining 5 seconds will get flushed into here.circular.open_output(PyavOutput(f"flushed-file-b.mp4"))picam2.stop_encoder()4) Am using mp4 rather than h264 files now thanks to PyavOutput.
5) Have managed to concatenate the flushed video (pre) and the live captured video using ffmpeg to create a single video file.
6) Got to the bottom of an issue in (5) when concatenating the two video files as somewhere along the PyavOutput / CircularOutput2 chain the flushed video is not correctly formatted in that the 'start' value can be something other than zero. This causes the concatenated video file to hang on to the last frame of the flushed file for a long time. For example a 20 second video file can play for 11 minutes, although the file size is correct. ffprobe shows such a 'start' value:
Code:
compatible_brands: isomiso2avc1mp41 encoder : Lavf59.27.100 Duration: 00:11:17.29, start: 671.852018, bitrate: 14 kb/s Stream #0:0[0x1](und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 2016x1520, 1789 kb/s, 5.15 fps, 5 tbr, 15360 tbn (default)Code:
ffmpeg -i flush-with-start-problem.mp4 -metadata start="0.000000" -c copy flush-with-start-corrected.mp4I now have a working proof of concept CCTV with pre, event and post capture.
Now just the small matter of tidying up the messy code & make it more respectable
Statistics: Posted by Cobilia — Wed Mar 26, 2025 7:00 pm