如果你安装bad 和 ugly 还不行
解决方案:重装gstreamer
wink wik
但安装方式和常规的不一样
安装gstreamer
sudo apt update
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
安装基础包之外的rtsp服务器
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstrtspserver-1.0-dev libgirepository1.0-dev
pkg-config --modversion gstreamer-rtsp-server-1.0
python的gstreamer包(接口)
pip install --index-url https://pypi.org/simple pygobject
# 如果你默认是镜像源,加个官网地址哦,要不然下载不了
如果报错,缺啥补啥
我是pycairo
sudo apt install libcairo2-dev pkg-config
pip install --index-url https://pypi.org/simple pycairo
测试
在pycharm里看到
from gi.repository import Gst 报错,不要怕,大胆运行
# test_gstreamer.py
from gi.repository import Gst
Gst.init(None)
print("GStreamer initialized successfully!")
# test_rtsp_server.py
from gi.repository import Gst, GstRtspServer
Gst.init(None)
print("GStreamer RTSP Server module is available!")
发出rtsp
import sys
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GLib
loop = GLib.MainLoop()
Gst.init(None)
class TestRtspMediaFactory(GstRtspServer.RTSPMediaFactory):
def __init__(self):
GstRtspServer.RTSPMediaFactory.__init__(self)
def do_create_element(self, url):
# Set mp4 file path to filesrc's location property
src_demux = "filesrc location=/home/oem/workspace/rtsp/test_videos/SampleVideo_1920_1080_10min.mp4 ! qtdemux name=demux"
h264_transcode = "demux.video_0"
# Uncomment following line if video transcoding is necessary
# h264_transcode = "demux.video_0 ! decodebin ! queue ! x264enc"
pipeline = "{0} {1} ! queue ! rtph264pay name=pay0 config-interval=1 pt=96".format(src_demux, h264_transcode)
print("Element created: " + pipeline)
return Gst.parse_launch(pipeline)
class GstreamerRtspServer():
def __init__(self):
self.rtspServer = GstRtspServer.RTSPServer()
self.rtspServer.set_service("8080") # 设置端口
factory = TestRtspMediaFactory()
factory.set_shared(True)
mountPoints = self.rtspServer.get_mount_points()
mountPoints.add_factory("/stream1", factory) # # 另一个终端:vlc -v rtsp://127.0.0.1:8080/stream1 拉流
self.rtspServer.attach(None)
if __name__ == '__main__':
s = GstreamerRtspServer()
print("Starting RTSP server on rtsp://127.0.0.1:8080/stream1...")
loop.run()
print("RTSP server stopped.")
拉流
# bash
vlc -v rtsp://127.0.0.1:8080/stream1