民浩

 

Nginx搭建hls流媒体服务器

第一种方案:ffmpeg+nginx

 
新的ffmpeg已经支持HLS。(本人也参与了代码供献,给自己做个广告:))
 
点播:
 
生成hls分片:
 
ffmpeg -i <媒体文件> -c:v libx264 -c:a -f hls /usr/local/nginx/html/test.m3u8
 
 
 
直播:
 
ffmpeg -i udp://@:1234 -c:v libx264 -c:a -f hls  /usr/local/nginx/html/test.m3u8
 
 
 
建立web服务器:
 
默认配置就可以。
 
 server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
}
 
 
 
启动nginx。
 
客户端访问:http://IP/test.m3u8
 
在windows上可以用vlc播放。
 
 
 
第二个文案,用nginx-rtmp-module
 
      
rtmp {
 
    server {
 
        listen 1935;
 
        chunk_size 4000;
      
        #HLS
 
        # For HLS to work please create a directory in tmpfs (/tmp/app here)
        # for the fragments. The directory contents is served via HTTP (see
        # http{} section in config)
        #
        # Incoming stream must be in H264/AAC. For iPhones use baseline H264
        # profile (see ffmpeg example).
        # This example creates RTMP stream from movie ready for HLS:
        #
        # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264 
        #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 
        #    -f flv rtmp://localhost:1935/hls/movie
        #
        # If you need to transcode live stream use 'exec' feature.
        #
        application hls {
            live on;
            hls on;
            hls_path /tmp/app;
            hls_fragment 5s;
        }
    }
}
 
http {
 
    server {
 
        listen      80;
        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            alias /tmp/app;
            expires -1;
        }
    }
}

posted on   民浩  阅读(713)  评论(0编辑  收藏  举报

编辑推荐:
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
阅读排行:
· 开发的设计和重构,为开发效率服务
· 从零开始开发一个 MCP Server!
· Ai满嘴顺口溜,想考研?浪费我几个小时
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
历史上的今天:
2012-10-09 【高清视频压制教程】使用MeGUI压制视频教程(以PSP视频为例)(转载)

导航

统计

点击右上角即可分享
微信分享提示