代码:

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

GObject.threads_init()
Gst.init(None)
#pipeline_str="rtspsrc location=rtsp://100.78.210.126:8554/video latency=0 ! queue ! application/x-rtp ! rtph264depay ! avdec_h264 ! videoconvert ! video/x-raw,format=BGRA ! appsink name=outsink"
pipeline_str = "rtspsrc location=rtsp://100.78.210.126:8554/video latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink"

pipeline = Gst.parse_launch(pipeline_str)
pipeline.set_state(Gst.State.PLAYING)

bus = pipeline.get_bus()
while True:
    message = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS)
    if message:
        if message.type == Gst.MessageType.ERROR:
            err, debug = message.parse_error()
            print("Error received from element %s: %s" % (message.src.get_name(), err.message))
            print("Error received from element {}: {}".format(message.src.get_name(), err.message))

            #print(f"Error received from element {message.src.get_name()}: {err.message}")
            #print(f"Debugging information: {debug if debug else 'none'}")
            break
        elif message.type == Gst.MessageType.EOS:
            err, debug = message.parse_error()
            print("Error received from element " + message.src.get_name() + ": " + err.message)

            #print("End-Of-Stream reached.")
            break

pipeline.set_state(Gst.State.NULL)

import gi报错

下载PyGObject for Windows Files安装

链接:PyGObject for Windows - Browse Files at SourceForge.net

这个库最高只支持python3.4

安装时选择python3.4路径,选择与gstreamer有关的项目打钩

想用更高版本的python可以用此方法:How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

参考博客:gstreamer python bindings for Windows - Stack Overflow

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐