首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将mp4转换为rtsp

将mp4转换为rtsp
EN

Stack Overflow用户
提问于 2020-07-08 14:45:59
回答 1查看 105关注 0票数 1

我想帮你一点忙。如何在python中将mp4转换为rtsp?我试过这个代码,它不能工作--它似乎不知道gi是什么。

olso在cmd上得到了这个

我使用的是python 3.8。

代码语言:javascript
复制
#!/usr/bin/env python

import sys
import gi

gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GObject, 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=/path/to/dir/test.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()
        factory = TestRtspMediaFactory()
        factory.set_shared(True)
        mountPoints = self.rtspServer.get_mount_points()
        mountPoints.add_factory("/stream1", factory)
        self.rtspServer.attach(None)

if __name__ == '__main__':
    s = GstreamerRtspServer()
    loop.run()
EN

回答 1

Stack Overflow用户

发布于 2020-07-08 16:41:01

gi包由https://pygobject.readthedocs.io/en/latest/getting_started.html - install that提供。

不过,顺便说一句,您似乎使用的是Windows;您可能没有可用的Glib/Gstreamer生态系统的其余部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62789019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档