@@ -448,6 +448,7 @@ def __exit__(self, exc_type, exc_value, traceback):
448448 cam .close ()
449449 del self ._picamera
450450
451+ @thing_action
451452 def start_streaming (self ) -> None :
452453 """
453454 Start the MJPEG stream
@@ -463,7 +464,7 @@ def start_streaming(self) -> None:
463464 picam .stop ()
464465 picam .stop_encoder () # make sure there are no other encoders going
465466 stream_config = picam .create_video_configuration (
466- main = {"size" : self . stream_resolution },
467+ main = {"size" : ( 832 , 624 ) },
467468 lores = {"size" : (320 , 240 ), "format" : "YUV420" },
468469 sensor = self .thing_settings .get ("sensor_mode" , None ),
469470 controls = self .persistent_controls ,
@@ -494,6 +495,55 @@ def start_streaming(self) -> None:
494495 "Started MJPEG stream at %s on port %s" , self .stream_resolution , 1
495496 )
496497
498+ @thing_action
499+ def start_highres_streaming (self ) -> None :
500+ """
501+ Start the MJPEG stream
502+
503+ Sets the camera resolution to the video/stream resolution, and starts recording
504+ if the stream should be active.
505+ """
506+ with self .picamera () as picam :
507+ # TODO: Filip: can we use the lores output to keep preview stream going
508+ # while recording? According to picamera2 docs 4.2.1.6 this should work
509+ try :
510+ if picam .started :
511+ picam .stop ()
512+ picam .stop_encoder () # make sure there are no other encoders going
513+ stream_config = picam .create_video_configuration (
514+ main = {"size" : (3280 , 2464 )},
515+ lores = {"size" : (320 , 240 ), "format" : "YUV420" },
516+ sensor = self .thing_settings .get ("sensor_mode" , None ),
517+ controls = self .persistent_controls ,
518+ )
519+ picam .configure (stream_config )
520+ logging .info ("Starting picamera MJPEG stream..." )
521+ picam .start_recording (
522+ MJPEGEncoder (self .mjpeg_bitrate ),
523+ PicameraStreamOutput (
524+ self .mjpeg_stream ,
525+ get_blocking_portal (self ),
526+ ),
527+ name = "lores" ,
528+ )
529+ picam .start_encoder (
530+ MJPEGEncoder (100000000 ),
531+ PicameraStreamOutput (
532+ self .lores_mjpeg_stream ,
533+ get_blocking_portal (self ),
534+ ),
535+ name = "lores" ,
536+ )
537+ except Exception as e :
538+ logging .exception ("Error while starting preview: {e}" )
539+ logging .exception (e )
540+ else :
541+ self .stream_active = True
542+ logging .debug (
543+ "Started MJPEG stream at %s on port %s" , self .stream_resolution , 1
544+ )
545+
546+ @thing_action
497547 def stop_streaming (self , stop_web_stream = True ) -> None :
498548 """
499549 Stop the MJPEG stream
0 commit comments