[环境搭建] 使用nginx搭建 hls 媒体服务器

1. 安装nginx




2.配置 hls 流媒体服务

修改 nginx 配置文件相关代码块为如下:

bash 复制代码
http {

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    server {
        listen 8080;

        location /hls {
            root /home/yk/VOD;
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            add_header Cache-Control no-cache;
        }
    }
}



3.使用ffmpeg创建被代理的 m3u8 流

根据 nginx 的配置,创建路径 /home/yk/VOD/hls/ 。这个路径是url寻址的根路径,比如 http://hostip:8080/hls/4k , 那么就会寻址到 /home/yk/VOD/hls/4k/ 。

使用ffmpeg 处理一个 MP4 文件,并将输出的所有 ts 文件拷贝到 /home/yk/VOD/hls/4k/ 下。

bash 复制代码
ffmpeg -hwaccel cuda -i 4K.mp4 -c:v hevc_nvenc -b:v 40M -c:a copy -f hls -hls_time 2 -hls_list_size 0 index.m3u8



4.测试

可以使用potplayer来播放 m3u8 资源。open->open URL->填入

http://127.0.0.1:8080/hls/4k/index.m3u8

相关推荐
..空空的人8 分钟前
linux基础指令的认识
linux·运维·服务器
penny_tcf8 分钟前
Linux基础命令halt详解
linux·运维·服务器
鱼跃鹰飞11 分钟前
Leecode热题100-295.数据流中的中位数
java·服务器·开发语言·前端·算法·leetcode·面试
N1cez29 分钟前
vscode 连接服务器 不用输密码 免密登录
服务器·vscode
杨哥带你写代码1 小时前
构建高效新闻推荐系统:Spring Boot的力量
服务器·spring boot·php
荣世蓥1 小时前
10.2 Linux_进程_进程相关函数
linux·运维·服务器
gma9992 小时前
【MySQL】服务器管理与配置
运维·服务器
suri ..3 小时前
【Linux】-----进程第二弹(优先级,环境变量)
linux·运维·服务器
Jay-juice3 小时前
Makefile入门
linux·运维·服务器