Beispiel #1
0
 def _create_resizer(self, width, height):
     self.resizer = ct.POINTER(mmal.MMAL_COMPONENT_T)()
     mmal_check(mmal.mmal_component_create(
         mmal.MMAL_COMPONENT_DEFAULT_RESIZER, self.resizer),
                prefix="Failed to create resizer component")
     if not self.resizer[0].input_num:
         raise PiCameraError("No input ports on resizer component")
     if not self.resizer[0].output_num:
         raise PiCameraError("No output ports on resizer component")
     # Copy the original input port's format to the resizer's input,
     # then the resizer's input format to the output, and configure it
     mmal.mmal_format_copy(self.resizer[0].input[0][0].format,
                           self.input_port[0].format)
     mmal_check(mmal.mmal_port_format_commit(self.resizer[0].input[0]),
                prefix="Failed to set resizer input port format")
     mmal.mmal_format_copy(self.resizer[0].output[0][0].format,
                           self.resizer[0].input[0][0].format)
     fmt = self.resizer[0].output[0][0].format
     fmt[0].es[0].video.width = width
     fmt[0].es[0].video.height = height
     fmt[0].es[0].video.crop.x = 0
     fmt[0].es[0].video.crop.y = 0
     fmt[0].es[0].video.crop.width = width
     fmt[0].es[0].video.crop.height = height
     mmal_check(mmal.mmal_port_format_commit(self.resizer[0].output[0]),
                prefix="Failed to set resizer output port format")
Beispiel #2
0
 def _create_resizer(self, width, height):
     self.resizer = ct.POINTER(mmal.MMAL_COMPONENT_T)()
     mmal_check(
         mmal.mmal_component_create(mmal.MMAL_COMPONENT_DEFAULT_RESIZER, self.resizer),
         prefix="Failed to create resizer component",
     )
     if not self.resizer[0].input_num:
         raise PiCameraError("No input ports on resizer component")
     if not self.resizer[0].output_num:
         raise PiCameraError("No output ports on resizer component")
     # Copy the original input port's format to the resizer's input,
     # then the resizer's input format to the output, and configure it
     mmal.mmal_format_copy(self.resizer[0].input[0][0].format, self.input_port[0].format)
     mmal_check(
         mmal.mmal_port_format_commit(self.resizer[0].input[0]), prefix="Failed to set resizer input port format"
     )
     mmal.mmal_format_copy(self.resizer[0].output[0][0].format, self.resizer[0].input[0][0].format)
     fmt = self.resizer[0].output[0][0].format
     fmt[0].es[0].video.width = width
     fmt[0].es[0].video.height = height
     fmt[0].es[0].video.crop.x = 0
     fmt[0].es[0].video.crop.y = 0
     fmt[0].es[0].video.crop.width = width
     fmt[0].es[0].video.crop.height = height
     mmal_check(
         mmal.mmal_port_format_commit(self.resizer[0].output[0]), prefix="Failed to set resizer output port format"
     )
Beispiel #3
0
 def _create_encoder(self, **options):
     """
     Creates and configures the encoder itself
     """
     assert not self.encoder
     self.encoder = ct.POINTER(mmal.MMAL_COMPONENT_T)()
     mmal_check(
         mmal.mmal_component_create(self.encoder_type, self.encoder),
         prefix="Failed to create encoder component")
     if not self.encoder[0].input_num:
         raise PiCameraError("No input ports on encoder component")
     if not self.encoder[0].output_num:
         raise PiCameraError("No output ports on encoder component")
     # Ensure output format is the same as the input
     self.output_port = self.encoder[0].output[0]
     if self.resizer:
         mmal.mmal_format_copy(
             self.encoder[0].input[0][0].format, self.resizer[0].output[0][0].format)
     mmal.mmal_format_copy(
         self.output_port[0].format, self.encoder[0].input[0][0].format)
     # Set buffer size and number to appropriate values
     self.output_port[0].buffer_size = max(
         self.output_port[0].buffer_size_recommended,
         self.output_port[0].buffer_size_min)
     self.output_port[0].buffer_num = max(
         self.output_port[0].buffer_num_recommended,
         self.output_port[0].buffer_num_min)
Beispiel #4
0
 def _create_encoder(self, **options):
     """
     Creates and configures the encoder itself
     """
     assert not self.encoder
     self.encoder = ct.POINTER(mmal.MMAL_COMPONENT_T)()
     mmal_check(mmal.mmal_component_create(self.encoder_type, self.encoder),
                prefix="Failed to create encoder component")
     if not self.encoder[0].input_num:
         raise PiCameraError("No input ports on encoder component")
     if not self.encoder[0].output_num:
         raise PiCameraError("No output ports on encoder component")
     # Ensure output format is the same as the input
     self.output_port = self.encoder[0].output[0]
     if self.resizer:
         mmal.mmal_format_copy(self.encoder[0].input[0][0].format,
                               self.resizer[0].output[0][0].format)
     mmal.mmal_format_copy(self.output_port[0].format,
                           self.encoder[0].input[0][0].format)
     # Set buffer size and number to appropriate values
     self.output_port[0].buffer_size = max(
         self.output_port[0].buffer_size_recommended,
         self.output_port[0].buffer_size_min)
     self.output_port[0].buffer_num = max(
         self.output_port[0].buffer_num_recommended,
         self.output_port[0].buffer_num_min)
Beispiel #5
0
    def __init__(self,
                 parent,
                 source,
                 size=None,
                 layer=0,
                 alpha=255,
                 fullscreen=True,
                 window=None,
                 crop=None,
                 rotation=0,
                 vflip=False,
                 hflip=False):
        super(PiOverlayRenderer,
              self).__init__(parent, layer, alpha, fullscreen, window, crop,
                             rotation, vflip, hflip)

        # Copy format from camera's preview port, then adjust the encoding to
        # RGB888 and optionally adjust the resolution and size
        port = self.renderer[0].input[0]
        fmt = port[0].format
        mmal.mmal_format_copy(
            fmt,
            parent._camera[0].output[parent.CAMERA_PREVIEW_PORT][0].format)
        fmt[0].encoding = mmal.MMAL_ENCODING_RGB24
        fmt[0].encoding_variant = mmal.MMAL_ENCODING_RGB24
        if size is not None:
            w, h = size
            fmt[0].es[0].video.width = mmal.VCOS_ALIGN_UP(w, 32)
            fmt[0].es[0].video.height = mmal.VCOS_ALIGN_UP(h, 16)
            fmt[0].es[0].video.crop.width = w
            fmt[0].es[0].video.crop.height = h
        mmal_check(mmal.mmal_port_format_commit(port),
                   prefix="Overlay format couldn't be set")
        port[0].buffer_num = port[0].buffer_num_min
        port[0].buffer_size = port[0].buffer_size_recommended

        mmal_check(mmal.mmal_component_enable(self.renderer),
                   prefix="Overlay couldn't be enabled")

        mmal_check(mmal.mmal_port_enable(port, _overlay_callback),
                   prefix="Overlay input port couldn't be enabled")

        self.pool = mmal.mmal_port_pool_create(port, port[0].buffer_num,
                                               port[0].buffer_size)
        if not self.pool:
            raise PiCameraRuntimeError("Couldn't create pool for overlay")

        self.update(source)
Beispiel #6
0
    def __init__(
            self, parent, source, size=None, layer=0, alpha=255,
            fullscreen=True, window=None, crop=None, rotation=0, vflip=False,
            hflip=False):
        super(PiOverlayRenderer, self).__init__(
            parent, layer, alpha, fullscreen, window, crop,
            rotation, vflip, hflip)

        # Copy format from camera's preview port, then adjust the encoding to
        # RGB888 and optionally adjust the resolution and size
        port = self.renderer[0].input[0]
        fmt = port[0].format
        mmal.mmal_format_copy(
            fmt, parent._camera[0].output[parent.CAMERA_PREVIEW_PORT][0].format)
        fmt[0].encoding = mmal.MMAL_ENCODING_RGB24
        fmt[0].encoding_variant = mmal.MMAL_ENCODING_RGB24
        if size is not None:
            w, h = size
            fmt[0].es[0].video.width = mmal.VCOS_ALIGN_UP(w, 32)
            fmt[0].es[0].video.height = mmal.VCOS_ALIGN_UP(h, 16)
            fmt[0].es[0].video.crop.width = w
            fmt[0].es[0].video.crop.height = h
        mmal_check(
            mmal.mmal_port_format_commit(port),
            prefix="Overlay format couldn't be set")
        port[0].buffer_num = port[0].buffer_num_min
        port[0].buffer_size = port[0].buffer_size_recommended

        mmal_check(
            mmal.mmal_component_enable(self.renderer),
            prefix="Overlay couldn't be enabled")

        mmal_check(
            mmal.mmal_port_enable(port, _overlay_callback),
            prefix="Overlay input port couldn't be enabled")

        self.pool = mmal.mmal_port_pool_create(
            port, port[0].buffer_num, port[0].buffer_size)
        if not self.pool:
            raise PiCameraRuntimeError("Couldn't create pool for overlay")

        self.update(source)