停止流式传输,原因未协商(-4)错误

问题描述 投票:0回答:1

我有下面的代码,这些代码从视频捕获卡中读取帧并将这些帧作为gst缓冲区推送到appsrc元素,但是当我运行代码时,我越来越停止流式传输,原因是我未协商(-4)错误,我怀疑是那里我的上限分配有些问题。有人可以帮我指出我在代码中做错的地方吗

import sys
import gi
import os
import threading
import traceback
gi.require_version("Gst", "1.0")
from gi.repository import GObject, Gst  # pylint:disable=wrong-import-order

Gst.init([])


class LiveStreamingDUT(object):
    def __init__(self, display):
        self.end_of_stream = False
        self.vsrc = None

    def __stream_dut(self):
        try:
            pipeline_command = "appsrc name=videosrc is-live=true block=true caps=image/jpeg,framerate=(fraction)30/1 ! videoconvert ! x264enc tune=zerolatency ! " \
                               "mpegtsmux ! " \
                               "hlssink location=/var/www/segment-%05d.ts " \
                               "playlist-location=/var/www/index.m3u8 max-files=20 " \
                               "target-duration=15"

            print(pipeline_command)

            pipeline = Gst.parse_launch(pipeline_command)
            self.vsrc = pipeline.get_by_name('videosrc')

            r = PipelineRunner(pipeline)
            thread = threading.Thread(target=r.run)
            thread.daemon = True
            thread.start()

            writerThread = threading.Thread(target=self._appsrc_push_data, name='gstreamerpushdata')
            writerThread.start()

        except:
            print('error during streaming content')
            print("teardown: Exiting (GLib mainloop %s)" % (
                "is still alive!" if thread.isAlive() else "ok"))

    def _appsrc_push_data(self):
        try:
            while (self.end_of_stream == False):
                try:
                    ret, data = <read frame from hdmi capture card and return in numpy array>
                    buf = self.ndarray_to_gst_buffer(data)
                    self.vsrc.emit('push-buffer', buf)
                except:
                    traceback.print_exc()
                    print("Error reading HDMI data")
                    self.end_of_stream = True
                    break
        except:
            pass
        finally:
            pass

    def ndarray_to_gst_buffer(self, array):
        """Converts numpy array to Gst.Buffer"""
        return Gst.Buffer.new_wrapped(array.tobytes())

    def stream_dut(self):
        self.__stream_dut()

获取错误消息

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "./display/gst_live_stream.py", line 111, in run
    (self.err, self.dbg))
RuntimeError: Error running pipeline: gst-stream-error-quark: Internal data stream error. (1)

gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstAppSrc:videosrc:
streaming stopped, reason not-negotiated (-4)
python-3.x gstreamer http-live-streaming gstreamer-1.0
1个回答
0
投票
appsrc (...) caps=image/jpeg,framerate=(fraction)30/1 ! videoconvert

您的appsrc元素似乎正在输出运动JPEG流,并尝试将其馈送到videoconvert元素,该元素仅将原始视频流作为输入。可能可以通过在中间插入decodebin来解决,这将为您解码JPEG帧。

© www.soinside.com 2019 - 2024. All rights reserved.