Example #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")
Example #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"
     )
Example #3
0
 def _create_encoder(self):
     """
     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)
     else:
         mmal.mmal_format_copy(self.encoder[0].input[0][0].format,
                               self.input_port[0].format)
     mmal_check(mmal.mmal_port_format_commit(self.encoder[0].input[0]),
                prefix="Failed to set encoder input port 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)
Example #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)
     else:
         mmal.mmal_format_copy(self.encoder[0].input[0][0].format, self.input_port[0].format)
     mmal_check(
         mmal.mmal_port_format_commit(self.encoder[0].input[0]), prefix="Failed to set encoder input port 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
     )
Example #5
0
    def __init__(
            self, parent, layer=0, alpha=255, fullscreen=True, window=None,
            crop=None, rotation=0, vflip=False, hflip=False):
        # Create and enable the renderer component
        self._rotation = 0
        self._vflip = False
        self._hflip = False
        self.parent = parent
        self.renderer = ct.POINTER(mmal.MMAL_COMPONENT_T)()
        mmal_check(
            mmal.mmal_component_create(
                mmal.MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, self.renderer),
            prefix="Failed to create renderer component")
        try:
            if not self.renderer[0].input_num:
                raise PiCameraError("No input ports on renderer component")

            self.layer = layer
            self.alpha = alpha
            self.fullscreen = fullscreen
            if window is not None:
                self.window = window
            if crop is not None:
                self.crop = crop
            self.rotation = rotation
            self.vflip = vflip
            self.hflip = hflip

            mmal_check(
                mmal.mmal_component_enable(self.renderer),
                prefix="Renderer component couldn't be enabled")
        except:
            mmal.mmal_component_destroy(self.renderer)
            raise
Example #6
0
 def __init__(self, parent, source):
     self.parent = parent
     self.renderer = ct.POINTER(mmal.MMAL_COMPONENT_T)()
     mmal_check(
         mmal.mmal_component_create(mmal.MMAL_COMPONENT_DEFAULT_NULL_SINK, self.renderer),
         prefix="Failed to create null sink component",
     )
     try:
         if not self.renderer[0].input_num:
             raise PiCameraError("No input ports on null sink component")
         mmal_check(mmal.mmal_component_enable(self.renderer), prefix="Null sink component couldn't be enabled")
     except:
         mmal.mmal_component_destroy(self.renderer)
         raise
     self.connection = self.parent._connect_ports(source, self.renderer[0].input[0])
Example #7
0
 def __init__(self, parent, source):
     self.parent = parent
     self.renderer = ct.POINTER(mmal.MMAL_COMPONENT_T)()
     mmal_check(mmal.mmal_component_create(
         mmal.MMAL_COMPONENT_DEFAULT_NULL_SINK, self.renderer),
                prefix="Failed to create null sink component")
     try:
         if not self.renderer[0].input_num:
             raise PiCameraError("No input ports on null sink component")
         mmal_check(mmal.mmal_component_enable(self.renderer),
                    prefix="Null sink component couldn't be enabled")
     except:
         mmal.mmal_component_destroy(self.renderer)
         raise
     self.connection = self.parent._connect_ports(source,
                                                  self.renderer[0].input[0])
Example #8
0
    def __init__(self,
                 parent,
                 layer=0,
                 alpha=255,
                 fullscreen=True,
                 window=None,
                 crop=None,
                 rotation=0,
                 vflip=False,
                 hflip=False):
        # Create and enable the renderer component
        self._rotation = 0
        self._vflip = False
        self._hflip = False
        self.parent = parent
        self.renderer = ct.POINTER(mmal.MMAL_COMPONENT_T)()
        mmal_check(mmal.mmal_component_create(
            mmal.MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, self.renderer),
                   prefix="Failed to create renderer component")
        try:
            if not self.renderer[0].input_num:
                raise PiCameraError("No input ports on renderer component")

            self.layer = layer
            self.alpha = alpha
            self.fullscreen = fullscreen
            if window is not None:
                self.window = window
            if crop is not None:
                self.crop = crop
            self.rotation = rotation
            self.vflip = vflip
            self.hflip = hflip

            mmal_check(mmal.mmal_component_enable(self.renderer),
                       prefix="Renderer component couldn't be enabled")
        except:
            mmal.mmal_component_destroy(self.renderer)
            raise