def present(self, frame: QVideoFrame) -> bool:
        if not frame.isValid():
            return False

        image_format = QVideoFrame.imageFormatFromPixelFormat(frame.pixelFormat())
        if image_format == QVideoFrame.Format_Invalid:
            _logger.info(_('QR code scanner for video frame with invalid pixel format'))
            return False

        if not frame.map(QAbstractVideoBuffer.ReadOnly):
            _logger.info(_('QR code scanner failed to map video frame'))
            return False

        try:
            img = QImage(frame.bits(), frame.width(), frame.height(), image_format)

            # Check whether we need to flip the image on any axis
            surface_format = self.surfaceFormat()
            flip_x = surface_format.isMirrored()
            flip_y = surface_format.scanLineDirection() == QVideoSurfaceFormat.BottomToTop

            # Mirror the image if needed
            if flip_x or flip_y:
                img = img.mirrored(flip_x, flip_y)

            # Create a copy of the image so the original frame data can be freed
            img = img.copy()
        finally:
            frame.unmap()

        self.frame_available.emit(img)

        return True
    def present(self, frame: QVideoFrame):
        print("present called")

        if frame.isValid():

            clone_frame = QVideoFrame(frame)

            clone_frame.map(QAbstractVideoBuffer.ReadOnly)
            image = QImage(clone_frame.bits(), frame.width(), frame.height(), frame.bytesPerLine(), \
                QVideoFrame.imageFormatFromPixelFormat(frame.pixelFormat()))
            clone_frame.unmap()

            self.frame_available.emit(image)

        if self.surfaceFormat().pixelFormat() != frame.pixelFormat() or \
            self.surfaceFormat().frameSize() != frame.size():
            self.setError(QAbstractVideoSurface.IncorrectFormatError)
            self.stop()

            print("present finished: Return False")
            return False
        else:
            self.current_frame = frame

            print("present finished: Return True")
            return True
Beispiel #3
0
    def present(self, frame: QVideoFrame):
        """
        Called by the video player
        :param frame: frame to present
        """
        if frame.isValid():
            clone_frame = QVideoFrame(frame)
            clone_frame.map(QAbstractVideoBuffer.ReadOnly)
            image = QImage(
                clone_frame.bits(), clone_frame.width(), clone_frame.height(),
                QVideoFrame.imageFormatFromPixelFormat(
                    clone_frame.pixelFormat()))

            self.frameAvailable.emit(image)
            clone_frame.unmap()

        if self.surfaceFormat().pixelFormat() != frame.pixelFormat(
        ) or self.surfaceFormat().frameSize() != frame.size():
            self.setError(self.IncorrectFormatError)
            self.stop()
            return False
        else:
            self.currentFrame = frame
            self.widget.repaint()
            return True
Beispiel #4
0
 def present(self, frame: QVideoFrame):
     if frame.isValid():
         self.conversion_thread.process_frame(frame)
         return True
     return False