[英]hls stream not working in nginx-rtmp-module
I've created media streaming service using nginx-rtmp-module我使用nginx-rtmp-module创建了媒体流服务
nginx.config file 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
Using ffmpeg command I'm creating streaming file使用 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
When I check stream/storage/live/ folder I didn't see any .ts and index.m3u8 file created on folder.当我检查stream/storage/live/文件夹时,我没有看到在文件夹上创建任何.ts和index.m3u8文件。
I've tried play rtmp video in VLC player but it's not playing, I didn't get any error but still video not play on VLC player.我试过在 VLC 播放器中播放 rtmp 视频,但它没有播放,我没有收到任何错误,但视频仍然无法在 VLC 播放器上播放。
Check if nginx necessary permission to write to hls_path /Users/dev/Desktop/stream/storage/live/
.检查 nginx 是否需要写入
hls_path /Users/dev/Desktop/stream/storage/live/
的权限。 Or otherwise, you can add user root;
否则,您可以添加
user root;
at the first line of your nginx conf.在 nginx conf 的第一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.