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()
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值