【问题标题】:How to show rtmp live stream in web browser?如何在网络浏览器中显示 rtmp 直播流?
【发布时间】:2020-05-24 06:08:46
【问题描述】:

我已经为直播设置了一个 nginx 服务器,一切正常,我可以看到直播 VLC 播放器。

我正在尝试在网络浏览器而不是 VLC 播放器中实现直播,但没有得到任何适当的解决方案。

我看到了很多 jw 播放器的例子,但它不起作用。 任何人都请建议最好在网络浏览器中观看直播。

谢谢

【问题讨论】:

    标签: html rtmp


    【解决方案1】:

    这已经不可能了。以前可以使用 FASH,但不再支持 flash。您必须使用受支持的格式,例如 HLS 或 DASH

    【讨论】:

    • 我用过 HLS 但它只支持 safari 浏览器。我想要支持所有浏览器的东西
    【解决方案2】:

    因为我在尝试解决类似问题时来晚了,所以这里有一个我觉得有用的答案。

    一个选项可能正在使用这个项目:rtsp-simple-server

    您可以尝试使用从 rtmp 到 HLS 的代理。然后你需要为你的浏览器添加 HLS 支持(此时非 sarari 浏览器似乎需要像 hls.js 这样的 JS 后备)

    您可能希望在配置 yaml 中添加这样的部分来桥接单个流:

    paths:
      hls:
        source: rtmp://example.com:1935/stream
    

    【讨论】:

      【解决方案3】:
      import time
      import cv2 
      from flask import Flask, render_template, Response
      from werkzeug.wrappers import Request, Response
      
      app = Flask(__name__)
      
      @app.route('/')
      def index():
          return render_template('index.html')
      
      
      def gen():
          cap = cv2.VideoCapture("live streaming **strong text**url")
          width = 1200
          height = 700
          dim = (width, height)
          while(cap.isOpened()):
              ret, img = cap.read()
              if ret == True:
                  img = cv2.resize(img, dim, fx=0.5, fy=0.5) 
                  frame = cv2.imencode('.jpg', img)[1].tobytes()
                  yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
                  time.sleep(0.1)
              else: 
                  break
              
      
      @app.route('/video_feed')
      def video_feed():
          return Response(gen(),
                          mimetype='multipart/x-mixed-replace; boundary=frame')
      
          
      if __name__ ==('__main__'):
          from werkzeug.serving import run_simple
          run_simple('localhost', 7600, app)
      

      【讨论】:

      • 欢迎来到 StackOverflow。虽然这段代码可以解决问题,including an explanation 解决问题的方式和原因确实有助于提高帖子的质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提出问题的人。请edit您的回答添加解释并说明适用的限制和假设。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多