mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Enhance NGINX configuration for audio streaming support and CORS handling
This commit is contained in:
parent
0d2d5edbd8
commit
d80771d827
2 changed files with 125 additions and 25 deletions
|
@ -15,18 +15,18 @@ rtmp {
|
|||
allow play all;
|
||||
#creates our "live" full-resolution HLS videostream from our incoming encoder stream and tells where to put the HLS video manifest and video fragments
|
||||
application live {
|
||||
#allow play all;
|
||||
allow play all;
|
||||
live on;
|
||||
#hls on;
|
||||
#hls_nested on;
|
||||
#hls_path /HLS/live;
|
||||
#hls_playlist_length 60m;
|
||||
#hls_fragment 4s;
|
||||
hls on;
|
||||
hls_nested on;
|
||||
hls_path /HLS/live;
|
||||
hls_playlist_length 60m;
|
||||
hls_fragment 4s;
|
||||
drop_idle_publisher 30s;
|
||||
sync 500ms;
|
||||
|
||||
#hls_keys on;
|
||||
#hls_fragments_per_key 20;
|
||||
hls_keys on;
|
||||
hls_fragments_per_key 20;
|
||||
|
||||
#Experimental. Force dropped stream, or ended stream from being watched. (idle_streams)
|
||||
#idle_streams off;
|
||||
|
@ -35,12 +35,13 @@ rtmp {
|
|||
on_play http://avideo/plugin/Live/on_play.php;
|
||||
on_record_done http://avideo/plugin/Live/on_record_done.php;
|
||||
|
||||
exec ffmpeg -re -i rtmp://localhost/live/$name
|
||||
# -c:v libx264 -preset veryfast -vf scale=-2:240 -r 20 -g 40 -keyint_min 40 -sc_threshold 0 -bf 2 -b_strategy 1 -b:v 400k -maxrate 500k -bufsize 1000k -c:a aac -b:a 96k -ac 2 -ar 44100 -f flv rtmp://localhost/adaptive/$name_low
|
||||
-c:v libx264 -preset veryfast -vf scale=-2:480 -r 30 -g 60 -keyint_min 60 -sc_threshold 0 -bf 2 -b_strategy 1 -b:v 1200k -maxrate 1500k -bufsize 3000k -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://localhost/adaptive/$name_mid;
|
||||
# -c:v libx264 -preset veryfast -vf scale=-2:720 -r 30 -g 60 -keyint_min 60 -sc_threshold 0 -bf 2 -b_strategy 1 -b:v 2400k -maxrate 2800k -bufsize 5600k -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://localhost/adaptive/$name_hi;
|
||||
#exec ffmpeg -re -analyzeduration 10M -probesize 10M -i rtmp://localhost/live/$name
|
||||
# -thread_queue_size 512 -filter_complex "[0:v]split=3[v1][v2][v3];[v1]scale=-2:480[v480];[v2]scale=-2:720[v720];[v3]scale=-2:1080[v1080]"
|
||||
# -map "[v480]" -map 0:a:0? -c:v libx264 -preset ultrafast -profile:v baseline -level 3.0 -r 30 -g 120 -keyint_min 120 -crf 27 -maxrate 900k -bufsize 1800k -c:a aac -b:a 96k -ar 32000 -ac 1 -f flv rtmp://localhost/adaptive/${name}_low
|
||||
# -map "[v720]" -map 0:a:0? -c:v libx264 -preset ultrafast -profile:v baseline -level 3.0 -r 30 -g 120 -keyint_min 120 -crf 23 -maxrate 2000k -bufsize 4000k -c:a aac -b:a 128k -ar 32000 -ac 2 -f flv rtmp://localhost/adaptive/${name}_mid
|
||||
# -map "[v1080]" -map 0:a:0? -c:v libx264 -preset ultrafast -profile:v baseline -level 3.0 -r 30 -g 120 -keyint_min 120 -crf 20 -maxrate 4500k -bufsize 9000k -c:a aac -b:a 160k -ar 48000 -ac 2 -f flv rtmp://localhost/adaptive/${name}_hi 2>>/var/www/tmp/ffmpeg_nginx.log;
|
||||
|
||||
exec ffmpeg -i rtmp://localhost/live/$name -vn -c:a aac -b:a 64k -ar 44100 -ac 2 -f flv rtmp://localhost/adaptive/${name}_audio;
|
||||
exec ffmpeg -i rtmp://localhost/live/$name -vn -c:a aac -b:a 64k -ar 44100 -ac 2 -f flv rtmp://localhost/audio/${name};
|
||||
|
||||
recorder video {
|
||||
record all manual;
|
||||
|
@ -59,10 +60,28 @@ rtmp {
|
|||
#}
|
||||
}
|
||||
|
||||
application adaptive {
|
||||
#application adaptive {
|
||||
# live on;
|
||||
# hls on;
|
||||
# hls_path /HLS/live;
|
||||
# hls_nested on;
|
||||
# hls_playlist_length 60m;
|
||||
# hls_fragment 4s;
|
||||
# allow play all;
|
||||
# allow publish 127.0.0.1;
|
||||
# deny publish all;
|
||||
|
||||
# hls_keys on;
|
||||
# hls_fragments_per_key 20;
|
||||
# hls_variant _low BANDWIDTH=900000;
|
||||
# hls_variant _mid BANDWIDTH=1000000;
|
||||
# hls_variant _hi BANDWIDTH=2500000;
|
||||
#}
|
||||
|
||||
application audio {
|
||||
live on;
|
||||
hls on;
|
||||
hls_path /HLS/live;
|
||||
hls_path /HLS/audio;
|
||||
hls_nested on;
|
||||
hls_playlist_length 60m;
|
||||
hls_fragment 4s;
|
||||
|
@ -70,14 +89,8 @@ rtmp {
|
|||
allow publish 127.0.0.1;
|
||||
deny publish all;
|
||||
|
||||
hls_keys on;
|
||||
hls_fragments_per_key 20;
|
||||
hls_variant _audio BANDWIDTH=64000;
|
||||
#hls_variant _low BANDWIDTH=900000;
|
||||
hls_variant _mid BANDWIDTH=1000000;
|
||||
#hls_variant _hi BANDWIDTH=2500000;
|
||||
hls_variant _audio BANDWIDTH=64000 CODECS="mp4a.40.2";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http {
|
||||
|
@ -132,6 +145,44 @@ http {
|
|||
}
|
||||
}
|
||||
|
||||
location /audio {
|
||||
expires 60;
|
||||
add_header 'Cache-Control' 'public';
|
||||
|
||||
root /HLS;
|
||||
|
||||
location ~ \.m3u8$ {
|
||||
expires -1;
|
||||
add_header 'Cache-Control' 'no-cache';
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length';
|
||||
}
|
||||
|
||||
location ~ \.ts$ {
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Cache-Control' 'no-cache';
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length';
|
||||
}
|
||||
|
||||
# CORS setup geral
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length';
|
||||
|
||||
# Preflight requests
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Authorization endpoint
|
||||
location = /auth_key_check {
|
||||
|
@ -183,6 +234,5 @@ http {
|
|||
listen 8443 ssl;
|
||||
ssl_certificate TLS_CERTIFICATE_FILE;
|
||||
ssl_certificate_key TLS_CERTIFICATE_KEY;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ rtmp {
|
|||
# -map "[v720]" -map 0:a:0? -c:v libx264 -preset ultrafast -profile:v baseline -level 3.0 -r 30 -g 120 -keyint_min 120 -crf 23 -maxrate 2000k -bufsize 4000k -c:a aac -b:a 128k -ar 32000 -ac 2 -f flv rtmp://localhost/adaptive/${name}_mid
|
||||
# -map "[v1080]" -map 0:a:0? -c:v libx264 -preset ultrafast -profile:v baseline -level 3.0 -r 30 -g 120 -keyint_min 120 -crf 20 -maxrate 4500k -bufsize 9000k -c:a aac -b:a 160k -ar 48000 -ac 2 -f flv rtmp://localhost/adaptive/${name}_hi 2>>/var/www/tmp/ffmpeg_nginx.log;
|
||||
|
||||
#exec ffmpeg -i rtmp://localhost/live/$name -vn -c:a aac -b:a 64k -ar 44100 -ac 2 -f flv rtmp://localhost/adaptive/${name}_audio;
|
||||
exec ffmpeg -i rtmp://localhost/live/$name -vn -c:a aac -b:a 64k -ar 44100 -ac 2 -f flv rtmp://localhost/audio/${name};
|
||||
|
||||
#recorder video {
|
||||
# record all manual;
|
||||
|
@ -78,12 +78,25 @@ rtmp {
|
|||
|
||||
# hls_keys on;
|
||||
# hls_fragments_per_key 20;
|
||||
# hls_variant _audio BANDWIDTH=64000;
|
||||
# hls_variant _low BANDWIDTH=400000;
|
||||
# hls_variant _mid BANDWIDTH=1000000;
|
||||
# hls_variant _hi BANDWIDTH=2200000;
|
||||
#}
|
||||
|
||||
application audio {
|
||||
live on;
|
||||
hls on;
|
||||
hls_path /HLS/audio;
|
||||
hls_nested on;
|
||||
hls_playlist_length 60m;
|
||||
hls_fragment 4s;
|
||||
allow play all;
|
||||
allow publish 127.0.0.1;
|
||||
deny publish all;
|
||||
|
||||
hls_variant _audio BANDWIDTH=64000 CODECS="mp4a.40.2";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
http {
|
||||
|
@ -142,6 +155,43 @@ http {
|
|||
}
|
||||
}
|
||||
|
||||
location /audio {
|
||||
expires 60;
|
||||
add_header 'Cache-Control' 'public';
|
||||
|
||||
root /HLS;
|
||||
|
||||
location ~ \.m3u8$ {
|
||||
expires -1;
|
||||
add_header 'Cache-Control' 'no-cache';
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length';
|
||||
}
|
||||
|
||||
location ~ \.ts$ {
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Cache-Control' 'no-cache';
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length';
|
||||
}
|
||||
|
||||
# CORS setup geral
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Expose-Headers' 'Content-Length';
|
||||
|
||||
# Preflight requests
|
||||
if ($request_method = 'OPTIONS') {
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
# Authorization endpoint
|
||||
location = /auth_key_check {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue