예제 #1
0
    def startup(self):
        self._pipeline = gst.GstVideoSource(self._gst_launch,
                                            max_buffers_size=8)
        self._pipeline.startup()

        self._num_loops += 1
        print(f"Starting {self._num_loops} loop")
예제 #2
0
def test_video_source():
    num_buffers = NUM_BUFFERS
    width, height = WIDTH, HEIGHT

    formats = [GstVideo.VideoFormat.to_string(f.buffer_format) for f in FRAMES]

    for fmt in formats:
        caps_filter = 'capsfilter caps=video/x-raw,format={},width={},height={}'.format(
            fmt, width, height)
        command = 'videotestsrc num-buffers={} ! {} ! appsink emit-signals=True sync=false'.format(
            num_buffers, caps_filter)
        with gst.GstContext(), gst.GstVideoSource(command) as pipeline:

            num_read = 0
            while num_read < num_buffers:
                buffer = pipeline.pop()
                if buffer:
                    num_read += 1
                    h, w = buffer.data.shape[:2]
                    assert h == height and w == width

            assert pipeline.total_buffers_count == num_buffers
예제 #3
0
def test_video_src_to_source():

    num_buffers = NUM_BUFFERS

    for frame in FRAMES:
        buffer = frame.buffer
        h, w = buffer.shape[:2]

        sink_cmd = "appsrc emit-signals=True is-live=True ! videoconvert ! fakesink sync=false"

        fmt = GstVideo.VideoFormat.to_string(frame.buffer_format)
        caps_filter = f'capsfilter caps=video/x-raw,format={fmt},width={w},height={h}'
        src_cmd = f'videotestsrc num-buffers={num_buffers} ! {caps_filter} ! appsink emit-signals=True sync=false'

        with gst.GstContext(), gst.GstVideoSink(sink_cmd, width=w, height=h, video_frmt=frame.buffer_format) as sink, \
                gst.GstVideoSource(src_cmd) as src:
            assert sink.total_buffers_count == 0

            # wait pipeline to initialize
            max_num_tries, num_tries = 5, 0
            while not sink.is_active and num_tries <= max_num_tries:
                time.sleep(.1)
                num_tries += 1

            assert sink.is_active

            num_read = 0
            while num_read < num_buffers:
                buffer = src.pop()
                if buffer:
                    num_read += 1
                    sink.push(buffer.data,
                              pts=buffer.pts,
                              dts=buffer.dts,
                              offset=buffer.offset)

            assert src.total_buffers_count == num_buffers
            assert sink.total_buffers_count == num_buffers