gstream 推流 rtsp :no element “x264enc“

如果你安装bad 和 ugly 还不行

解决方案:重装gstreamer

wink wik

但安装方式和常规的不一样

安装gstreamer

sudo apt update

官网:Installing on Linux

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 

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值