hls+ 在开启worker_processes 2,使用hls+播放会出现卡顿,http返回404错误
liubing-sky opened this issue · 2 comments
配置文件:
#user root;
daemon on;
master_process on;
worker_processes 2;
#worker_rlimit 4g;
#working_directory /usr/local/openresty/nginx/logs;
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
worker_rlimit_nofile 102400;
worker_rlimit_core 2G;
working_directory /tmp;
#pid logs/nginx.pid;
events {
worker_connections 2024;
}
stream_zone buckets=1024 streams=4096;
rtmp {
server {
listen 1940;
application live {
live on;
hls2 on;
mpegts_cache_time 20s;
hls2_fragment 4000ms;
hls2_max_fragment 5000ms;
hls2_playlist_length 12000ms;
wait_key on;
wait_video on;
cache_time 2s;
send_all on;
low_latency off;
fix_timestamp 2s;
# h265 codecid, default 12
hevc_codecid 12;
}
}
}
http {
server {
listen 18080;
location / {
chunked_transfer_encoding on;
root html/;
}
location /hls2 {
hls2_live 1940 app=live;
add_header 'Access-Control-Allow-Origin' '';
add_header Cache-Control no-cache;
add_header "Access-Control-Allow-Credentials" "true";
add_header "Access-Control-Allow-Methods" "";
add_header "Access-Control-Allow-Headers" "Content-Type,Access-Token";
add_header "Access-Control-Expose-Headers" "*";
}
}
}
直接使用ffplay播放,会出现404问题。
worker_processes 1;
使用单进程,如果要开启多进程模式请参考:HLS+ 多进程配置模板
worker_processes 1;
使用单进程,如果要开启多进程模式请参考:HLS+ 多进程配置模板
按照这个是可以了,是因为:
multi_listen unix:/tmp/http 80;
multi_listen unix:/tmp/rtmp 1935;
以及 location /hls2 {
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 8 1M;
proxy_busy_buffers_size 2M;
proxy_max_temp_file_size 0;
set $hls_args location=/hls2&scheme=$scheme;
if ($args) {
set $hls_args $args&location=/hls2&scheme=$scheme;
}
proxy_set_header Host $host:$server_port;
rewrite ^/(.)/(.).(.*)$ /hlsm/$2.$3?$hls_args break;
proxy_pass http://hlsm;
}
这个可以理解为又做了一次代理么?