Nginx搭建rmtp转化m3u8流媒体服务

参考: https://www.cnblogs.com/yanjieli/archive/2019/03/28/10615638.html

 

首先需要安装ffmpeg : 

安装过程:https://www.cnblogs.com/benwu/articles/15065925.html

 

安装nginx , 并添加 nginx-rtmp-module  模块

下载nginx-rtmp-module-master源码 并解压到  /root/module/nginx-rtmp-module-master 目录中

执行命名配置nginx

# ./configure --prefix=/opt/nginx-1.9.5 --add-module=/root/module/nginx-rtmp-module-master --with-http_ssl_module 

配置文件添加

    server {
        listen       9002;
        server_name  localhost;
        location / {
           types {
               application/vnd.apple.mpegurl m3u8;
               video/mp2t ts;
           }
           root /data/ffmpeg/hls;
           index  index.html index.htm;
           add_header Cache-Control no-cache;
           add_header Access-Control-Allow-Origin *;
        }
    }

-hls_list_size m3u8 文件保存ts的个数;
-hls_wrap  ts文件保存的个数(不设置保存所有);
-hls_flags delete_segments  自动删除旧的ts,只保留最新的几个
-start_number 1  指定生成的ts的起始序号

/data/ffmpeg/hls: 视频分隔的地址

 

执行ffmpeg ,生成 m3u8格式的文件

ffmpeg -i rtmp://devlivepull.migucloud.com/live/VESWXNYJ_C0 \
-vcodec copy -acodec copy -vbsf h264_mp4toannexb -f hls -hls_list_size 0 -hls_time 10 /data/ffmpeg/hls/play.m3u8

输出如下:

目录 /data/ffmpeg/hls  中会不断的生成 ts 和m3u8文件

生成文件测试

<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8 />
    <title>videojs-contrib-hls embed</title>
    <link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
</head>
 
<body>
    <h1>Video.js播放m3u8</h1> 
    <video-js id="my_video_1" class="vjs-default-skin" controls='true' preload="auto" width="640" height="268">
        <source src="http://218.56.130.6:9002/play.m3u8" type="application/x-mpegURL">
    </video-js> 
    <script src="https://unpkg.com/video.js/dist/video.js"></script>
    <script src="https://unpkg.com/@videojs/http-streaming/dist/videojs-http-streaming.js"></script> 
    <script>
        var player = videojs('my_video_1');
    </script> 
</body> 
</html>

 

批量转换:https://blog.csdn.net/weixin_44943157/article/details/118696704



posted @ 2022-05-12 16:16  南极山  阅读(1947)  评论(0)    收藏  举报