0

At this moment I have the VideoImageTrack class I show bellow (adapted from here) that returns an av VideoFrame. The script I show works fine. My problem is that the frame encoding step:

VideoFrame.from_ndarray(image, format="bgr24")

is quite slow.

Is there a gstreamer pipeline that outputs the already encoded frame and iterable with python-opencv read()?

class VideoImageTrack(VideoStreamTrack):
    """
    A video stream track that returns a rotating image.
    """

    def __init__(self):
        super().__init__()  # don't forget this!

        self.video = cv2.VideoCapture("v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=15/1,bitrate=250000  ! appsink")


    async def recv(self):
        pts, time_base = await self.next_timestamp()

        retval, image = self.video.read()
        frame = VideoFrame.from_ndarray(image, format="bgr24")
        frame.pts = pts
        frame.time_base = time_base

        return frame
Miguel
  • 2,738
  • 3
  • 35
  • 51

1 Answers1

0

Although I don't know if processing will be faster but you can try to use GStreamer's videoconvert that transcodes video frames between many formats.

Example pipeline:

v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,format=BGR,width=640,height=480,framerate=15/1 ! appsink
Dusan Kovacevic
  • 1,377
  • 1
  • 13
  • 19