update
This commit is contained in:
parent
f45ca950d6
commit
bdc6212d95
|
|
@ -1,54 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$nginx_bottom = "
|
|
||||||
";
|
|
||||||
|
|
||||||
$sls = "
|
|
||||||
srt {
|
|
||||||
|
|
||||||
worker_threads 64;
|
|
||||||
worker_connections 500;
|
|
||||||
|
|
||||||
log_file /tmp/logs/error.log ;
|
|
||||||
log_level info;
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 1937;
|
|
||||||
latency 1000; #ms
|
|
||||||
|
|
||||||
domain_player srt.urmic.org;
|
|
||||||
domain_publisher pass1pass1pass1;
|
|
||||||
backlog 100;
|
|
||||||
idle_streams_timeout 10;#s -1: unlimited
|
|
||||||
app {
|
|
||||||
app_player onshreeganeshaynamah ;
|
|
||||||
app_publisher pass2pass2pass2 ;
|
|
||||||
|
|
||||||
record_hls off;#on, off
|
|
||||||
record_hls_segment_duration 10; #unit s
|
|
||||||
|
|
||||||
#relay {
|
|
||||||
# type push;
|
|
||||||
# mode all; #all; hash
|
|
||||||
# reconnect_interval 10;
|
|
||||||
# idle_streams_timeout 10;#s -1: unlimited
|
|
||||||
# upstreams 192.168.31.106:8080?streamid=uplive.sls.com/live ;
|
|
||||||
#}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
";
|
|
||||||
|
|
||||||
function update_service($which_service)
|
function update_service($which_service)
|
||||||
{
|
{
|
||||||
|
|
||||||
$input = "";
|
$input = "";
|
||||||
$input_source = "";
|
$input_source = "";
|
||||||
$input_rtmp_port = "";
|
|
||||||
$input_port_srt = "";
|
|
||||||
$input_rtmp_mount = "";
|
$input_rtmp_mount = "";
|
||||||
$input_rtmp_pass = "";
|
$input_rtmp_pass = "";
|
||||||
$output = "";
|
$output = "";
|
||||||
|
$srt_pass1 = "";
|
||||||
|
$srt_pass2 = "";
|
||||||
|
$srt_pass3 = "";
|
||||||
$rtmp_multiple[] = [];
|
$rtmp_multiple[] = [];
|
||||||
$srt_multiple[] = [];
|
$srt_multiple[] = [];
|
||||||
$defaults = [
|
$defaults = [
|
||||||
|
|
@ -64,9 +27,9 @@ function update_service($which_service)
|
||||||
'password' => 'live',
|
'password' => 'live',
|
||||||
],
|
],
|
||||||
'srt' => [
|
'srt' => [
|
||||||
'stream_id_1' => 'har',
|
'stream_id_1' => 'pass1',
|
||||||
'stream_id_2' => 'har',
|
'stream_id_2' => 'pass2',
|
||||||
'stream_id_3' => 'mahadev',
|
'stream_id_3' => 'pass3',
|
||||||
],
|
],
|
||||||
'udp' => 'udp://@224.1.1.1:8000',
|
'udp' => 'udp://@224.1.1.1:8000',
|
||||||
'custom' => '',
|
'custom' => '',
|
||||||
|
|
@ -80,15 +43,11 @@ function update_service($which_service)
|
||||||
}
|
}
|
||||||
|
|
||||||
$input_source = $data['input'];
|
$input_source = $data['input'];
|
||||||
$input_rtmp_port = $data['rtmp']['port'];
|
|
||||||
$input_rtmp_mount = $data['rtmp']['mount'];
|
$input_rtmp_mount = $data['rtmp']['mount'];
|
||||||
$input_rtmp_pass = $data['rtmp']['password'];
|
$input_rtmp_pass = $data['rtmp']['password'];
|
||||||
$input_port_srt = $data['srt']['port'];
|
$srt_pass1 = $data['stream_id_1']['pass1'];
|
||||||
|
$srt_pass2 = $data['stream_id_2']['pass2'];
|
||||||
if ($input_rtmp_port === "80" || $input_rtmp_port === "443" || $input_port_srt === "80" || $input_port_srt === "443") {
|
$srt_pass3 = $data['stream_id_3']['pass3'];
|
||||||
echo '<script>alert("80 or 443 port is not allowed .");</script>';
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($input_source) {
|
switch ($input_source) {
|
||||||
case "hdmi":
|
case "hdmi":
|
||||||
|
|
@ -99,14 +58,13 @@ function update_service($which_service)
|
||||||
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i " . $data['url'];
|
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i " . $data['url'];
|
||||||
break;
|
break;
|
||||||
case "udp":
|
case "udp":
|
||||||
$input .= 'ffmpeg -hwaccel auto -stream_loop -1 -re -i "' . $data['udp']."?reuse=1&fifo_size=1000000&overrun_nonfatal=1".'"';
|
$input .= 'ffmpeg -hwaccel auto -stream_loop -1 -re -i "' . $data['udp'];
|
||||||
break;
|
break;
|
||||||
case "rtmp":
|
case "rtmp":
|
||||||
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i rtmp://127.0.0.1:1935/" . $$input_rtmp_mount . "/" . $input_rtmp_pass;
|
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i rtmp://127.0.0.1:1935/" . $$input_rtmp_mount . "/" . $input_rtmp_pass;
|
||||||
break;
|
break;
|
||||||
case "srt":
|
case "srt":
|
||||||
$input .= "-stream_loop -1 -re -i srt://127.0.0.1:1937/" . $data['srt']['stream_id_1'] . "/" . $data['srt']['stream_id_2'] . "/" . $data['srt']['stream_id_3'];
|
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i srt://127.0.0.1:1937/" . $srt_pass1 . "/" . $srt_pass2 . "/" . $srt_pass3;
|
||||||
$input_port_srt = $data['srt']['port'];
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$input .= " ";
|
$input .= " ";
|
||||||
|
|
@ -166,19 +124,19 @@ function update_service($which_service)
|
||||||
$rtmp_multiple = $data['rtmp_multiple'];
|
$rtmp_multiple = $data['rtmp_multiple'];
|
||||||
$srt_multiple = $data['srt_multiple'];
|
$srt_multiple = $data['srt_multiple'];
|
||||||
|
|
||||||
$input .= ' -c:v h264_qsv -b:v ' . $data['video']['data_rate'] . ' -maxrate ' . $data['video']['data_rate'] . ' -bufsize 10M -g ' . $data['video']['gop'] . ' -af "aresample=async=1:first_pts=0" ' .
|
|
||||||
' -c:a ' . $data['audio']['format'] . ' -ar ' . $data['audio']['sample_rate'] . ' -b:a ' . $data['audio']['bit_rate'] . ' -f mpegts udp://127.0.0.1:39000';
|
|
||||||
|
|
||||||
$service = $input;
|
|
||||||
$file = "/var/www/encoder-main.sh";
|
|
||||||
if (file_put_contents($file, $service) !== false) {
|
|
||||||
echo "File saved.";
|
|
||||||
} else {
|
|
||||||
echo "Error writing file.";
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($which_service) {
|
switch ($which_service) {
|
||||||
case 'input':
|
case 'input':
|
||||||
|
$input .= ' -c:v h264_qsv -b:v ' . $data['video']['data_rate'] . ' -maxrate ' . $data['video']['data_rate'] . ' -bufsize 11M -g ' . $data['video']['gop'] . ' -af "aresample=async=1:first_pts=0" ' .
|
||||||
|
' -c:a ' . $data['audio']['format'] . ' -ar ' . $data['audio']['sample_rate'] . ' -b:a ' . $data['audio']['bit_rate'] . ' -f mpegts udp://@239.255.254.254:39000';
|
||||||
|
|
||||||
|
$service = $input;
|
||||||
|
$file = "/var/www/encoder-main.sh";
|
||||||
|
if (file_put_contents($file, $service) !== false) {
|
||||||
|
echo "File saved.";
|
||||||
|
} else {
|
||||||
|
echo "Error writing file.";
|
||||||
|
}
|
||||||
exec('sudo systemctl restart encoder-main');
|
exec('sudo systemctl restart encoder-main');
|
||||||
break;
|
break;
|
||||||
case 'display';
|
case 'display';
|
||||||
|
|
@ -205,8 +163,6 @@ function update_service($which_service)
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($input_rtmp_port))
|
|
||||||
$input_rtmp_port = "1935";
|
|
||||||
|
|
||||||
$rtmp_push = "";
|
$rtmp_push = "";
|
||||||
|
|
||||||
|
|
@ -299,28 +255,91 @@ http {
|
||||||
file_put_contents($file, $nginx);
|
file_put_contents($file, $nginx);
|
||||||
|
|
||||||
if ($service_rtmp_multiple === "enable") {
|
if ($service_rtmp_multiple === "enable") {
|
||||||
$rtmp = 'ffmpeg -fflags nobuffer -i "udp://127.0.0.1:39000?fifo_size=5000000&overrun_nonfatal=1" -c:v copy -c:a aac -f flv rtmp://127.0.0.1:1935/shree/bhattji';
|
$rtmp = 'ffmpeg -fflags nobuffer -i "udp://@239.255.254.254:39000?fifo_size=5000000&overrun_nonfatal=1" -c:v copy -c:a aac -f flv rtmp://127.0.0.1:1935/shree/bhattji';
|
||||||
$file = "/var/www/encoder-rtmp.sh";
|
$file = "/var/www/encoder-rtmp.sh";
|
||||||
file_put_contents($file, $rtmp);
|
file_put_contents($file, $rtmp);
|
||||||
exec('sudo cp /var/www/nginx.conf /etc/nginx/nginx.conf');
|
exec('sudo cp /var/www/nginx.conf /etc/nginx/nginx.conf');
|
||||||
exec("sudo nginx -t 2>&1", $output, $status);
|
exec("sudo nginx -t 2>&1", $output, $status);
|
||||||
if ($status == 0) {
|
if ($status === 0) {
|
||||||
error_log("nginx tested fine ");
|
|
||||||
exec("sudo systemctl restart nginx 2>&1", $o, $s);
|
exec("sudo systemctl restart nginx 2>&1", $o, $s);
|
||||||
exec('sudo systemctl enable encoder-rtmp');
|
exec('sudo systemctl enable encoder-rtmp');
|
||||||
exec('sudo systemctl restart encoder-rtmp');
|
exec('sudo systemctl restart encoder-rtmp');
|
||||||
} else {
|
} else {
|
||||||
error_log("Error Nginx default");
|
|
||||||
exec('sudo cp /var/www/nginx.conf /etc/nginx/');
|
exec('sudo cp /var/www/nginx.conf /etc/nginx/');
|
||||||
exec("sudo systemctl restart nginx");
|
exec("sudo systemctl restart nginx");
|
||||||
exec('sudo systemctl stop encoder-rtmp');
|
exec('sudo systemctl stop encoder-rtmp');
|
||||||
exec('sudo systemctl disable encoder-rtmp');
|
exec('sudo systemctl disable encoder-rtmp');
|
||||||
}
|
}
|
||||||
} {
|
} else {
|
||||||
|
exec('sudo systemctl stop encoder-rtmp');
|
||||||
|
exec('sudo systemctl disable encoder-rtmp');
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "srt";
|
case "srt";
|
||||||
|
if ($service_srt_multiple) {
|
||||||
|
|
||||||
|
$srt_push = "";
|
||||||
|
|
||||||
|
for ($i = 1; $i <= 11; $i++) {
|
||||||
|
if ($srt_multiple[$i]['enabled'] == 1) {
|
||||||
|
$srt_push .= " " . $srt_multiple[$i]['url'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$sls = "
|
||||||
|
srt {
|
||||||
|
|
||||||
|
worker_threads 64;
|
||||||
|
worker_connections 500;
|
||||||
|
|
||||||
|
log_file /tmp/logs/error.log ;
|
||||||
|
log_level info;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 1937;
|
||||||
|
latency 1000; #ms
|
||||||
|
|
||||||
|
domain_player shree;
|
||||||
|
domain_publisher " . $srt_pass1 . " ;
|
||||||
|
backlog 100;
|
||||||
|
idle_streams_timeout 10;
|
||||||
|
app {
|
||||||
|
app_player bhatt ;
|
||||||
|
app_publisher " . $srt_pass2 . " ;
|
||||||
|
|
||||||
|
record_hls off;
|
||||||
|
record_hls_segment_duration 10;
|
||||||
|
|
||||||
|
relay {
|
||||||
|
type push;
|
||||||
|
mode all; #all; hash
|
||||||
|
reconnect_interval 10;
|
||||||
|
idle_streams_timeout -1;
|
||||||
|
upstreams " . $srt_push . " ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
";
|
||||||
|
$service = 'ffmpeg -fflags nobuffer -i "udp://@239.255.254.254:39000?fifo_size=5000000&overrun_nonfatal=1" -c copy -f mpeg srt://127.0.0.1/shree/bhatt/ji';
|
||||||
|
$file = "/var/www/encoder-srt.sh";
|
||||||
|
file_put_contents($file, $service);
|
||||||
|
|
||||||
|
$file = "/var/www/sls.conf";
|
||||||
|
file_put_contents($file, $sls);
|
||||||
|
exec('sudo systemctl enable srt');
|
||||||
|
exec('sudo systemctl restart srt');
|
||||||
|
exec('sudo systemctl enable encoder-srt');
|
||||||
|
exec('sudo systemctl restart encoder-srt');
|
||||||
|
} else {
|
||||||
|
exec('sudo systemctl disable srt');
|
||||||
|
exec('sudo systemctl stop srt');
|
||||||
|
exec('sudo systemctl disable encoder-srt');
|
||||||
|
exec('sudo systemctl stop encoder-srt');
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "udp";
|
case "udp";
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -342,3 +342,4 @@ sudo chmod 777 -R /var/www
|
||||||
sudo chown -R www-data:www-data /var/www
|
sudo chown -R www-data:www-data /var/www
|
||||||
sudo ufw allow proto udp to 224.0.0.0/4
|
sudo ufw allow proto udp to 224.0.0.0/4
|
||||||
sudo ufw route allow proto udp to 224.0.0.0/4
|
sudo ufw route allow proto udp to 224.0.0.0/4
|
||||||
|
sudo ufw deny out to 239.255.254.254 port 39000 proto udp
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue