Python Gstreamer播放rtsp视频(含音频)(海康IPCAM)

Python Gstreamer播放rtsp视频(海康IPCAM)

播放思路详见博客:Python Gstreamer播放rtsp视频流(海康IPCAM)
元件连接图解:
在这里插入图片描述
  这里开始想使用tee分流,但是不成功,后来使用两个源来分别对视频音频输出,目前还不是特别清楚出现网络延迟后视音频的时间能否统一,等查阅资料有结果之后会更新此博客。

Python Gstreamer代码

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject, GLib

Gst.init(None)
a = 0

def on_pad_added( src, pad, des):
    vpad = des.get_static_pad("sink")
    pad.link(vpad)
def cb_decodebin_newpad(src, pad, dst):
    caps = Gst.Pad.get_current_caps(pad)
    structure_name = caps.to_string()

    if structure_name.startswith("audio"):
        volume_pad = dst.get_static_pad("sink")
        pad.link(volume_pad)

pipe = Gst.Pipeline.new("test")

src = Gst.ElementFactory.make("rtspsrc", "src")
src1 = Gst.ElementFactory.make("rtspsrc", "src1")
depayv = Gst.ElementFactory.make("rtph264depay", "depayv")
depaya = Gst.ElementFactory.make("rtppcmadepay", "depaya")
#tee = Gst.ElementFactory.make("tee", "tee")
queuev = Gst.ElementFactory.make("queue2", "queuev")
queuea = Gst.ElementFactory.make("queue2", "queuea")
src.connect("pad-added", on_pad_added, queuev)
src1.connect("pad-added", on_pad_added, queuea)
conv = Gst.ElementFactory.make("videoconvert", "conv")
sink = Gst.ElementFactory.make("xvimagesink", "sink")
conva = Gst.ElementFactory.make("audioconvert", "conva")
sinka = Gst.ElementFactory.make("autoaudiosink", "sinka")

decodebin = Gst.ElementFactory.make("avdec_h264", "decode")
decodebina = Gst.ElementFactory.make("decodebin", "decodea")
decodebina.connect("pad-added", cb_decodebin_newpad, conva)
rstp = 'rtsp://admin:*********@*********/Streaming/channels/802'
src.set_property("location", rstp)
src1.set_property("location", rstp)
pipe.add(src)
pipe.add(src1)
pipe.add(depayv)
pipe.add(depaya)
pipe.add(queuev)
pipe.add(queuea)
#pipe.add(vfilter)
pipe.add(conv)
pipe.add(sink)
pipe.add(conva)
pipe.add(sinka)
pipe.add(decodebin)
pipe.add(decodebina)

queuev.link(depayv)
depayv.link(decodebin)
decodebin.link(conv)
conv.link(sink)
queuea.link(depaya)
depaya.link(decodebina)
conva.link(sinka)

pipe.set_state(Gst.State.PLAYING)

mainloop = GLib.MainLoop()
mainloop.run()
发布了30 篇原创文章 · 获赞 37 · 访问量 4084

猜你喜欢

转载自blog.csdn.net/qq_32188669/article/details/95226386