如何使用videojs播放rtmp直播

如何使用videojs播放rtmp直播

本文介绍了如何使用videojs播放rtmp直播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用OBS将实时流推送到我的本地rtmp服务器(node-rtsp-rtmp-server),并且可以与VLC媒体播放器很好地配合使用.我只想把它放到网页中,然后我找到了videojs.它没有用,并返回不支持指定的类型"属性"rtmp/mp4".看来我的rtmp服务器没有显示该网页的任何请求.所以我错过了什么?这是我的代码:

I'm using OBS to push live stream to my local rtmp server(node-rtsp-rtmp-server),and it works well with VLC media player.I just want to put it into a webpage and i found videojs.It didnt work and returns Specified "type"-attribute "rtmp/mp4" is not supported.it seems my rtmp server didnt reveive any requests from this webpage.So what i missed?here is my code:

<head>
    <meta charset="utf-8">
    <link href="./video-js-6.0.0/video-js.css" rel="stylesheet">
    <script src="./video-js-6.0.0/video.js"></script>
    <script src="./video-js-6.0.0/videojs-flash.min.js"></script>
    <script>
        videojs.options.flash.swf = "./video-js-6.0.0/video-js.swf"
    </script>
</head>
<body>
   <video  id='vid' class='video-js' controls height=300 width=600>
      <source src="rtmp://127.0.0.1:1935/live/pokemon" type="rtmp/mp4"/>
    </video>
    <script>
        var player = videojs('vid');
    </script>
</body>

推荐答案

<html>
<head>
  <title> Stream Player </title>
  <link href="video-js.css" rel="stylesheet" type="text/css">
  <script src="video.js"></script>
  <script>videojs.options.flash.swf = "video-js.swf";</script>
</head>
<body>
 <center>
   <video
     id="livestream"
     class="video-js vjs-default-skin vjs-big-play-centered"
     controls
     autoplay
     preload="auto"
     data-setup='{"techorder" : ["flash","html5] }'>
     <source src="rtmp://127.0.0.1:1935/live/test" type="rtmp/mp4">
   </video>
 </center>
</body>
</html>

似乎要使videojs使用Flash,必须设置data-setup techorder参数.

The data-setup techorder parameter seems to be necessary for videojs to use flash.

如果这不起作用,请确保您的javascript文件都正常.从video.js版本6开始,默认情况下它不再支持Flash. https://docs.videojs.com/tutorial-faq.html#q-how-can-i-play-rtmp-video-in-videojs

If that doesn't work then make sure that your javascript files are all good. As of version 6 of video.js it no longer supports flash by default. https://docs.videojs.com/tutorial-faq.html#q-how-can-i-play-rtmp-video-in-videojs

我正在为服务器使用Nginx.

I am using nginx for my server.

https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/

https://github.com/arut/nginx-rtmp-module

如果您愿意为CD.video和video-js.css文件使用CDN,则将头替换为

If you would rather use a CDN for the video.js and video-js.css files replace the head with

<!--The latest versions of video.js no longer support flash or rtmp-->
<link href="https://vjs.zencdn.net/5.19/video-js.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/5.19/video.js"></script>

注意:您最好花时间学习HLS或DASH而不是闪存

Note: Your time is better spent learning HLS or DASH rather than flash

这篇关于如何使用videojs播放rtmp直播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:39