简体   繁体   English

链接元素时,GStreamer错误“声明'GST_IS_ELEMENT(src)'失败”

[英]GStreamer error “assertion 'GST_IS_ELEMENT (src)' failed” when linking elements

I'm working on a GStreamer-based program using Python and the GObject introspection bindings. 我正在使用Python和GObject自省绑定开发基于GStreamer的程序。 I'm trying to build this pipeline: 我正在尝试建立此管道:

videomixer name=mix ! autovideosink \
uridecodebin uri=v4l2:///dev/video0 ! mix.

The pipeline works perfectly using gst-launch-1.0, but my Python program gives the errors: 使用gst-launch-1.0管道可以完美地工作,但是我的Python程序给出了以下错误:

(minimal.py:12168): GStreamer-CRITICAL **: gst_element_link_pads_full: assertion 'GST_IS_ELEMENT (src)' failed
on_error(): (GError('Internal data flow error.',), 'gstbasesrc.c(2865): gst_base_src_loop (): /GstPipeline:pipeline0/GstURIDecodeBin:uridecodebin0/GstV4l2Src:source:\nstreaming task paused, reason not-linked (-1)')

My code: 我的代码:

#!/usr/bin/python3
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, Gtk, GdkX11, GstVideo
GObject.threads_init()
Gst.init(None)

class Source:
    def __init__(self, uri, pipeline, mixer):
        self.uri = uri
        self.pipeline = pipeline
        self.mixer = mixer

        self.src = Gst.ElementFactory.make('uridecodebin', None)
        self.pipeline.add(self.src)
        self.src.set_property('uri', uri)
        self.src.connect('pad-added', self.on_pad_added, self.src, self.mixer)

    def on_pad_added(self, element, pad, src, dest):
        name = pad.query_caps(None).to_string()
        print('on_pad_added:', name)
        if name.startswith('video/'):
            src.link(dest)

class Main:
    def __init__(self):
        self.window = Gtk.Window()
        self.window.connect('destroy', self.quit)
        self.window.set_default_size(1280, 720)

        self.drawingarea = Gtk.DrawingArea()
        self.window.add(self.drawingarea)

        self.pipeline = Gst.Pipeline()

        self.bus = self.pipeline.get_bus()
        self.bus.add_signal_watch()
        self.bus.connect('message::error', self.on_error)
        self.bus.enable_sync_message_emission()
        self.bus.connect('sync-message::element', self.on_sync_message)

        self.mixer = Gst.ElementFactory.make('videomixer', None)
        self.sink = Gst.ElementFactory.make('autovideosink', None)

        self.pipeline.add(self.mixer)
        self.pipeline.add(self.sink)

        self.mixer.link(self.sink)
        video = Source('v4l2:///dev/video0', self.pipeline, self.mixer)

    def run(self):
        self.window.show_all()
        # You need to get the XID after window.show_all().  You shouldn't get it
        # in the on_sync_message() handler because threading issues will cause
        # segfaults there.
        self.xid = self.drawingarea.get_property('window').get_xid()
        self.pipeline.set_state(Gst.State.PLAYING)
        Gtk.main()
    def quit(self, window):
        self.pipeline.set_state(Gst.State.NULL)
        Gtk.main_quit()
    def on_sync_message(self, bus, msg):
        if msg.get_structure().get_name() == 'prepare-window-handle': msg.src.set_window_handle(self.xid)
    def on_error(self, bus, msg):
        print('on_error():', msg.parse_error())

main = Main()
main.run()

I figured out the problem, I was linking the dynamically-created pad incorrectly: 我发现了问题,我错误地链接了动态创建的垫:

src.link(dest)

Should have been: 本来应该:

pad.link(dest.get_compatible_pad(pad, None))

If the element is not added with the pipeline, then this error will occur. 如果未将元素与管道一起添加,则将发生此错误。 Ensure that the problematic element is added with the pipeline. 确保将有问题的元素添加到管道中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GStreamer-CRITICAL **:gst_element_make_from_uri:断言“ gst_uri_is_valid(uri)”失败 - GStreamer-CRITICAL **: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed OpenCV错误:(-215:断言失败)!_src.empty()在函数'cvtColor'中 - OpenCV error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' 错误:(-215:Assertion failed)._src:empty() in function 'cv::cvtColor' - error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' 错误:(-215:断言失败)_src.total() > 0 在 function 'cv::warpPerspective' - error: (-215:Assertion failed) _src.total() > 0 in function 'cv::warpPerspective' cv2.error: OpenCV(4.5.2).error: (-215:Assertion failed)._src:empty() in function 'cv::cvtColor' - cv2.error: OpenCV(4.5.2) .error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' OpenCV 错误: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' - OpenCV error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' "OpenCV VideoCapture 和错误:(-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'" - OpenCV VideoCapture and error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' OpenCV: 错误: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist' - OpenCV: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist' OpenCV VideoCapture 和 (-215:Assertion failed)._src.empty() in function 'cvtColor' - OpenCV VideoCapture and (-215:Assertion failed) !_src.empty() in function 'cvtColor' 为什么'gst.Element.get_request_pad(self.filter,'filter')'返回'None'(gstreamer | python) - why 'gst.Element.get_request_pad(self.filter, 'filter')' returns 'None' (gstreamer | python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM