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 

### V4L2、FFmpeg和GStreamer的视频处理与媒体集成 #### FFmpeg简介及其配置调整 对于遇到`detect_ffmpeg.cmake`文件中的编译问题,可以通过修改OpenCV源码目录下的特定CMake脚本实现更详细的错误报告。具体操作是在`opencv-4.5.4/modules/videoio/cmake/detect_ffmpeg.cmake`找到`if(NOT __VALID_FFMPEG)`这一条件判断语句所在的代码块,并解除其后的首个注释标记,这一步骤能够使构建过程中显示完整的错误详情以便于排查问题[^2]。 #### GStreamer概述与其基本原理 作为一种模块化的多媒体框架,GStreamer允许开发者创建各种类型的媒体处理应用,从简单的音频播放器到复杂的多通道直播应用程序皆可胜任。尽管内置编码解码组件数量不及FFmpeg丰富[GStreamer的基本理念围绕着管道(pipe)的概念展开],即数据经一系列元件(element),这些元件各自执行特定的任务如解析、转换或渲染等[^1]。 #### V4L2接口说明 Video4Linux2 (V4L2) 是 Linux 下用于访问摄像头和其他视频设备的标准API集合。它提供了统一的方式去控制不同种类的捕获卡、电视调谐器以及数码相机等功能。利用该接口可以方便地获取来自物理传感器的数据帧并将其作为输入供给后续的图像分析算法或是直接送到网络上成为实时视讯服务的一部分。 #### 集成解决方案示例 当考虑将上述三种技术结合起来时,一种常见模式是从V4L2读取原始像素信息交给GStreamer进行初步过滤后再转交给FFmpeg完成最终封装打包过程准备传输给远端接收者。下面给出了一段Python伪代码来展示这种协作方式: ```python import cv2 # OpenCV库用来简化V4L2交互逻辑 from gi.repository import Gst, GObject # Python绑定版GStreamer SDK import subprocess as sp # 调用外部命令行工具比如ffmpeg def start_pipeline(): cap = cv2.VideoCapture(0) pipeline_str = 'appsrc ! videoconvert ! x264enc speed-preset=ultrafast tune=zerolatency ! rtph264pay config-interval=1 pt=96' pipeline = Gst.parse_launch(pipeline_str) appsrc = pipeline.get_by_name('source') def push_frame(*args): ret, frame = cap.read() if not ret: return False data = frame.tostring() buf = Gst.Buffer.new_allocate(None, len(data), None) buf.fill(0, data) appsrc.emit('push-buffer', buf) return True srcpad = appsrc.get_static_pad("src") srcpad.add_probe(Gst.PadProbeType.BUFFER, push_frame) pipeline.set_state(Gst.State.PLAYING) command = ['ffmpeg', '-i', '-', '-f', 'rtp_mpegts', '-c:v', 'libx264', '-preset', 'ultrafast', f'rtp://localhost:{port}'] process = sp.Popen(command, stdin=sp.PIPE) while True: try: buffer = ... process.stdin.write(buffer.raw_data()) except Exception as e: break start_pipeline() ``` 此代码片段展示了如何使用OpenCV通过V4L2抓取本地摄像机画面并通过GStreamer预处理之后再借助FFmpeg发送出去形成一个简易但功能完备的小型RTSP服务器架构。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值