nginx - hls 流在 nginx-rtmp-module 中不起作用
问题描述
nginx.config 文件
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile off;
tcp_nopush on;
server {
listen 3002;
server_name localhost;
location /live {
# Disable cache
add_header Cache-Control no-cache;
# CORS setup
add_header 'Cache-Control' 'no-cache';
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' 'Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /Users/dev/Desktop/stream/storage/;
add_header Cache-Control no-cache;
}
}
include servers/*;
}
# RTMP Config
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
ping 30s;
notify_method get;
application live{
live on;
exec_pull ffmpeg -re -i http://127.0.0.1/$app/$name
-vcodec libx264 -threads 0 -vprofile baseline -acodec aac -strict -2 -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1:1935/show/${name}_720
-vcodec libx264 -threads 0 -vprofile baseline -acodec aac -strict -2 -b:v 1024k -b:a 128k -vf "scale=854:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1:1935/show/${name}_480
-vcodec libx264 -threads 0 -vprofile baseline -acodec aac -strict -2 -b:v 300k -b:a 96k -vf "scale=426:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://127.0.0.1:1935/show/${name}_240;
}
application show {
live on;
# Turn on HLS
hls on;
hls_nested on;
record off;
hls_path /Users/dev/Desktop/stream/storage/live/;
# Instruct clients to adjust resolution according to bandwidth
hls_variant _720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
hls_variant _480 BANDWIDTH=448000; # Medium bitrate, SD resolution
hls_variant _240 BANDWIDTH=288000; # Low bitrate, sub-SD resolution
}
}
}
# End RTMP Config
使用 ffmpeg 命令我正在创建流文件
ffmpeg -re -i sample.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://127.0.0.1/live/my_video
当我检查stream/storage/live/文件夹时,我没有看到在文件夹上创建任何.ts和index.m3u8文件。
我试过在 VLC 播放器中播放 rtmp 视频,但它没有播放,我没有收到任何错误,但视频仍然无法在 VLC 播放器上播放。
解决方案
检查 nginx 是否需要写入权限hls_path /Users/dev/Desktop/stream/storage/live/
。或者,您可以user root;
在 nginx conf 的第一行添加。
推荐阅读
- javascript - ConditionalExpression 中的意外赋值
- c# - 如何从 actionContext ASP.NET Web API 2 中的 URL 获取参数
- python-3.x - 验证数据为空:django
- simics - 有没有办法调整 Simics 内存窗口显示粒度?
- reactjs - 使用 useFormContext 反应钩子表单不适用于数组字段
- python - Skipping x rows in an iterable of a subset of a dataframe
- javascript - 从对象数组中推入数组中的值
- linux - 如何删除文件夹中具有特殊扩展名的重复项
- python - 按值从列表中选择未找到定位器
- kubernetes - 如何将配置连接器写入机密或配置映射以在部署中使用?