Exemplo n.º 1
0
    def camera_image(self):
        """Return a still image response from the camera."""
        from haffmpeg import ImageSingle, IMAGE_JPEG
        ffmpeg = ImageSingle(get_binary())

        return ffmpeg.get_image(self._input, output_format=IMAGE_JPEG,
                                extra_cmd=self._extra_arguments)
Exemplo n.º 2
0
    def camera_image(self):
        """Return a still image response from the camera."""
        from haffmpeg import ImageSingle, IMAGE_JPEG
        ffmpeg = ImageSingle(self._ffmpeg_bin)

        return ffmpeg.get_image(self._input,
                                output_format=IMAGE_JPEG,
                                extra_cmd=self._extra_arguments)
Exemplo n.º 3
0
def cli(ffmpeg, source, format_img, output, extra):
    """FFMPEG capture frame as image."""

    stream = ImageSingle(ffmpeg_bin=ffmpeg)
    image = stream.get_image(
        input_source=source,
        output_format=format_img,
        extra_cmd=extra
    )

    if image is not None:
        with open(output, "wb") as fh_img:
            fh_img.write(image)
Exemplo n.º 4
0
    def __init__(self, name, interval, api, input_source, extra_arguments=None):
        """Init image processing."""
        from haffmpeg import ImageStream, ImageSingle

        super().__init__(name, interval, api)
        self._input_source = input_source
        self._extra_arguments = extra_arguments

        if self._interval > 0:
            self._ffmpeg = ImageStream(get_binary(), self._process_image)
        else:
            self._ffmpeg = ImageSingle(get_binary())

        self._start_ffmpeg()
Exemplo n.º 5
0
    def __init__(self, name, interval, api, input_source,
                 extra_arguments=None):
        """Init image processing."""
        from haffmpeg import ImageStream, ImageSingle

        super().__init__(name, interval, api)
        self._input_source = input_source
        self._extra_arguments = extra_arguments

        if self._interval > 0:
            self._ffmpeg = ImageStream(get_binary(), self._process_image)
        else:
            self._ffmpeg = ImageSingle(get_binary())

        self._start_ffmpeg()
Exemplo n.º 6
0
class OpenalprDeviceFFmpeg(OpenalprDevice):
    """Represent a openalpr device object for processing stream/images."""

    # pylint: disable=too-many-arguments
    def __init__(self, name, interval, api, input_source,
                 extra_arguments=None):
        """Init image processing."""
        from haffmpeg import ImageStream, ImageSingle

        super().__init__(name, interval, api)
        self._input_source = input_source
        self._extra_arguments = extra_arguments

        if self._interval > 0:
            self._ffmpeg = ImageStream(get_binary(), self._process_image)
        else:
            self._ffmpeg = ImageSingle(get_binary())

        self._start_ffmpeg()

    def shutdown(self, event):
        """Close ffmpeg stream."""
        if self._interval > 0:
            self._ffmpeg.close()

    def restart(self):
        """Restart ffmpeg stream."""
        if self._interval > 0:
            self._ffmpeg.close()
            self._start_ffmpeg()

    def scan(self):
        """Immediately scan a image."""
        from haffmpeg import IMAGE_PNG

        # process single image
        if self._interval == 0:
            image = self._ffmpeg.get_image(
                self._input_source,
                output_format=IMAGE_PNG,
                extra_cmd=self._extra_arguments
            )
            return self._process_image(image)

        # stream
        self._ffmpeg.push_image()

    def _start_ffmpeg(self):
        """Start a ffmpeg image stream."""
        from haffmpeg import IMAGE_PNG
        if self._interval == 0:
            return

        self._ffmpeg.open_stream(
            input_source=self._input_source,
            interval=self._interval,
            output_format=IMAGE_PNG,
            extra_cmd=self._extra_arguments,
        )

    @property
    def should_poll(self):
        """Return True if render is be 'image' or False if 'ffmpeg'."""
        return False

    @property
    def available(self):
        """Return True if entity is available."""
        return self._interval == 0 or self._ffmpeg.is_running
Exemplo n.º 7
0
class OpenalprDeviceFFmpeg(OpenalprDevice):
    """Represent a openalpr device object for processing stream/images."""

    # pylint: disable=too-many-arguments
    def __init__(self,
                 name,
                 interval,
                 api,
                 input_source,
                 extra_arguments=None):
        """Init image processing."""
        from haffmpeg import ImageStream, ImageSingle

        super().__init__(name, interval, api)
        self._input_source = input_source
        self._extra_arguments = extra_arguments

        if self._interval > 0:
            self._ffmpeg = ImageStream(get_binary(), self._process_image)
        else:
            self._ffmpeg = ImageSingle(get_binary())

        self._start_ffmpeg()

    def shutdown(self, event):
        """Close ffmpeg stream."""
        if self._interval > 0:
            self._ffmpeg.close()

    def restart(self):
        """Restart ffmpeg stream."""
        if self._interval > 0:
            self._ffmpeg.close()
            self._start_ffmpeg()

    def scan(self):
        """Immediately scan a image."""
        from haffmpeg import IMAGE_PNG

        # process single image
        if self._interval == 0:
            image = self._ffmpeg.get_image(self._input_source,
                                           output_format=IMAGE_PNG,
                                           extra_cmd=self._extra_arguments)
            return self._process_image(image)

        # stream
        self._ffmpeg.push_image()

    def _start_ffmpeg(self):
        """Start a ffmpeg image stream."""
        from haffmpeg import IMAGE_PNG
        if self._interval == 0:
            return

        self._ffmpeg.open_stream(
            input_source=self._input_source,
            interval=self._interval,
            output_format=IMAGE_PNG,
            extra_cmd=self._extra_arguments,
        )

    @property
    def should_poll(self):
        """Return True if render is be 'image' or False if 'ffmpeg'."""
        return False

    @property
    def available(self):
        """Return True if entity is available."""
        return self._interval == 0 or self._ffmpeg.is_running