Awesome, thanks for your help! I had no idea that this option existed in Picamera2.
I was getting quite a few dropped frames in the high res stream stored to disk, so I added a simple downsampler to the network stream and that seemed to help a lot!
I was getting quite a few dropped frames in the high res stream stored to disk, so I added a simple downsampler to the network stream and that seemed to help a lot!
Code:
import timefrom picamera2 import Picamera2from picamera2.encoders import H264Encoderfrom picamera2.outputs import FfmpegOutputclass H264DownsampleEncoder(H264Encoder): def __init__(self, bitrate=None, repeat=True, iperiod=30, framerate=3, qp=None, profile=None): super().__init__(bitrate, repeat, iperiod, framerate, qp, profile) self._last = None self._span = 1 / framerate def _encode(self, stream, request): timestamp_us = self._timestamp(request) if self._last is None or (timestamp_us - self._last) / 100000 >= self._span: self._last = timestamp_us super()._encode(stream, request)def main(): ip_addr = "192.168.0.100" port = 5555 cam = Picamera2() config = cam.create_video_configuration( main={"size": (1280, 720)}, lores={"size": (640, 480)}, ) cam.configure(config) cam.set_controls({"FrameRate": 80}) file_encoder = H264Encoder() network_encoder = H264DownsampleEncoder(framerate=1) network_output = FfmpegOutput(f"-f mpegts udp://{ip_addr}:{port}") cam.start_recording(network_encoder, network_output, name="lores") time.sleep(15) cam.start_encoder(file_encoder, "foo.h264", "foo.pts", name="main") time.sleep(30) cam.stop_encoder(file_encoder) time.sleep(2) cam.stop_recording()if __name__ == "__main__": main()Statistics: Posted by oneleggedredcow — Wed Apr 24, 2024 8:36 pm