Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将gstreamer管道转换为python代码_Python_Gstreamer_Nvidia_Gobject - Fatal编程技术网

将gstreamer管道转换为python代码

将gstreamer管道转换为python代码,python,gstreamer,nvidia,gobject,Python,Gstreamer,Nvidia,Gobject,我正在尝试使用gi库将gstreamer管道转换为python代码 这是在终端中成功运行的管道: gst-launch-1.0 rtspsrc location="rtsp://admin:123456@192.168.0.150:554/H264?ch=1&subtype=0&proto=Onvif" latency=300 ! rtph264depay ! h264parse ! nvv4l2decoder drop-frame-interval=1 ! nvvideocon

我正在尝试使用gi库将gstreamer管道转换为python代码

这是在终端中成功运行的管道:

gst-launch-1.0 rtspsrc location="rtsp://admin:123456@192.168.0.150:554/H264?ch=1&subtype=0&proto=Onvif" latency=300 ! rtph264depay ! h264parse ! nvv4l2decoder drop-frame-interval=1 ! nvvideoconvert ! video/x-raw,width=1920,height=1080,formate=I420 ! queue !  nveglglessink window-x=0 window-y=0 window-width=1080 window-height=720
但是,当使用python代码运行相同的管道时,没有显示rtsp流的输出窗口,终端上也没有错误。在我按下ctrl+c之前,终端一直卡住

这是我用来运行gstreamer命令的代码:

import gi

gi.require_version("Gst", "1.0")

from gi.repository import Gst, GObject


def main(device):
    GObject.threads_init()
    Gst.init(None)

    pipeline = Gst.Pipeline()

    source = Gst.ElementFactory.make("rtspsrc", "video-source")
    source.set_property("location", device)
    source.set_property("latency", 300)
    pipeline.add(source)

    depay = Gst.ElementFactory.make("rtph264depay", "depay")
    pipeline.add(depay)
    source.link(depay)

    parse = Gst.ElementFactory.make("h264parse", "parse")
    pipeline.add(parse)
    depay.link(parse)

    decoder = Gst.ElementFactory.make("nvv4l2decoder", "decoder")
    decoder.set_property("drop-frame-interval", 2)
    pipeline.add(decoder)
    parse.link(decoder)

    convert = Gst.ElementFactory.make("nvvideoconvert", "convert")
    pipeline.add(convert)
    decoder.link(convert)

    caps = Gst.Caps.from_string("video/x-raw,width=1920,height=1080,formate=I420")
    filter = Gst.ElementFactory.make("capsfilter", "filter")
    filter.set_property("caps", caps)
    pipeline.add(filter)
    convert.link(filter)

    queue = Gst.ElementFactory.make("queue", "queue")
    pipeline.add(queue)
    filter.link(queue)

    sink = Gst.ElementFactory.make("nveglglessink", "video-sink")
    sink.set_property("window-x", 0)
    sink.set_property("window-y", 0)
    sink.set_property("window-width", 1280)
    sink.set_property("window-height", 720)

    pipeline.add(sink)

    queue.link(sink)

    loop = GObject.MainLoop()

    pipeline.set_state(Gst.State.PLAYING)

    try:
        loop.run()
    except:
        pass

    pipeline.set_state(Gst.State.NULL)

if __name__ == "__main__":
    main("rtsp://admin:123456@192.168.0.150:554/H264?ch=1&subtype=0&proto=Onvif")

有人知道是什么错误吗?谢谢大家!

它不工作的原因是因为
rtspsrc
的源代码填充是一个所谓的。这里的链接对此进行了很好的解释,但基本上您无法预先知道
rtspsrc
上会有多少焊盘可用,因为这取决于RTSP服务器提供的SDP

因此,您应该收听
rtspsrc
“pad added”
信号,您可以将管道的其余部分链接到回调中刚刚出现的源pad

总结如下:

def main(device):
    GObject.threads_init()
    Gst.init(None)

    pipeline = Gst.Pipeline()
    source = Gst.ElementFactory.make("rtspsrc", "video-source")
    source.set_property("location", device)
    source.set_property("latency", 300)
    source.connect("pad-added", on_rtspsrc_pad_added)
    pipeline.add(source)

    # We will add/link the rest of the pipeline later
    loop = GObject.MainLoop()

    pipeline.set_state(Gst.State.PLAYING)

    try:
        loop.run()
    except:
        pass

    pipeline.set_state(Gst.State.NULL)

def on_rtspsrc_pad_added(rtspsrc, pad, *user_data):
    # Create the rest of your pipeline here and link it 
    depay = Gst.ElementFactory.make("rtph264depay", "depay")
    pipeline.add(depay)
    rtspsrc.link(depay)

    # and so on ....

我在上面的代码中添加了总线调用定义来捕获错误。我得到的错误是“错误:gst流错误quark:内部数据流错误。(1):gstbasesrc.c(3055):gst_base_src_loop():/GstPipeline:pipeline0/GstRTSPSrc:video source/GstUDPSrc:udpsrc2:流停止,原因未链接(-1)”