update
This commit is contained in:
parent
3288c0889a
commit
9d8fbbdf49
|
|
@ -1 +0,0 @@
|
|||
ffmpeg -thread_queue_size 512 -f v4l2 -input_format mjpeg -framerate 30 -video_size 1920x1080 -i /dev/video0 -f alsa -i hw:0,0 -init_hw_device qsv=hw:/dev/dri/renderD128 -filter_hw_device hw -fflags +genpts -use_wallclock_as_timestamps 1 -vf "format=nv12,hwupload=extra_hw_frames=64,format=qsv" -c:v h264_qsv -b:v 3.3M -maxrate 3.3M -bufsize 10M -g 25 -af "aresample=async=1:first_pts=0" -c:a aac -ar 48000 -b:a 96k -vsync 1 -copytb 1 -f mpegts udp://239.255.255.254:39000?localaddr=127.0.0.1
|
||||
|
|
@ -1 +0,0 @@
|
|||
ffmpeg -fflags nobuffer -i "udp://239.255.255.254:39000?localaddr=127.0.0.1&fifo_size=5000000&overrun_nonfatal=1" -c:v copy -c:a aac -f flv rtmp://127.0.0.1:1935/shree/bhattji
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"input": "hdmi",
|
||||
"hdmi": {
|
||||
"resolution": "1920x1080",
|
||||
"audio_source": "hw:0,0",
|
||||
"framerate": "30"
|
||||
},
|
||||
"url": "https://cdn.urmic.org/unavailable.mp4",
|
||||
"rtmp": {
|
||||
"mount": "channel_name",
|
||||
"password": "live",
|
||||
"port": "1935"
|
||||
},
|
||||
"srt": {
|
||||
"stream_id_1": "har",
|
||||
"stream_id_2": "har",
|
||||
"stream_id_3": "mahadev",
|
||||
"port": "1937"
|
||||
},
|
||||
"udp": "udp://@224.1.1.1:8000",
|
||||
"custom": ""
|
||||
}
|
||||
|
|
@ -12,16 +12,14 @@ $defaults = [
|
|||
'rtmp' => [
|
||||
'mount' => 'channel_name',
|
||||
'password' => 'live',
|
||||
'port' => '1935'
|
||||
],
|
||||
'srt' => [
|
||||
'stream_id_1' => 'har',
|
||||
'stream_id_2' => 'har',
|
||||
'stream_id_3' => 'mahadev',
|
||||
'port' => '1937'
|
||||
],
|
||||
'udp'=>'udp://@224.1.1.1:8000',
|
||||
'custom'=>''
|
||||
'udp' => 'udp://@224.1.1.1:8000',
|
||||
'custom' => ''
|
||||
];
|
||||
|
||||
if (file_exists($jsonFile)) {
|
||||
|
|
@ -50,13 +48,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
'rtmp' => [
|
||||
'mount' => $posted('rtmp_mount', $defaults['rtmp']['mount']),
|
||||
'password' => $posted('rtmp_password', $defaults['rtmp']['password']),
|
||||
'port' => $posted('rtmp_port', $defaults['rtmp']['port'])
|
||||
],
|
||||
'srt' => [
|
||||
'stream_id_1' => $posted('srt_stream_id_1', $defaults['srt']['stream_id_1']),
|
||||
'stream_id_2' => $posted('srt_stream_id_2', $defaults['srt']['stream_id_2']),
|
||||
'stream_id_3' => $posted('srt_stream_id_3', $defaults['srt']['stream_id_3']),
|
||||
'port' => $posted('srt_port', $defaults['srt']['port'])
|
||||
],
|
||||
'udp' => $posted('udp', $defaults['udp']),
|
||||
'custom' => $posted('custom', $defaults['custom'])
|
||||
|
|
@ -103,7 +99,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
<div class="dropdown">
|
||||
<select name="hdmi_resolution">
|
||||
<?php
|
||||
$res = ['1920x1080', '1600x1200', '1360x768', '1280x1024', '1280x720', '1024x768', '720x576','640x480'];
|
||||
$res = ['1920x1080', '1600x1200', '1360x768', '1280x1024', '1280x720', '1024x768', '720x576', '640x480'];
|
||||
foreach ($res as $r) {
|
||||
$sel = ($data['hdmi']['resolution'] === $r) ? 'selected' : '';
|
||||
echo "<option value=\"" . htmlspecialchars($r) . "\" $sel>$r</option>";
|
||||
|
|
@ -161,12 +157,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
<input type="text" id="rtmp_password" name="rtmp_password" value="<?php echo htmlspecialchars($data['rtmp']['password']); ?>" placeholder="live">
|
||||
<label for="rtmp_password">Password</label>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<input type="text" id="rtmp_port" name="rtmp_port" value="<?php echo htmlspecialchars($data['rtmp']['port']); ?>" placeholder="1935">
|
||||
<label for="rtmp_port">Port Number</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card wide">
|
||||
<h3>SRT Caller Setting</h3>
|
||||
<div class="input-group">
|
||||
|
|
@ -181,12 +172,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
<input type="text" id="srt_stream_id_3" name="srt_stream_id_3" value="<?php echo htmlspecialchars($data['srt']['stream_id_3']); ?>" placeholder="pass3">
|
||||
<label for="srt_stream_id_3">Stream ID 3</label>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<input type="text" id="srt_port" name="srt_port" value="<?php echo htmlspecialchars($data['srt']['port']); ?>" placeholder="1937">
|
||||
<label for="srt_port">Port Number</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card wide">
|
||||
<h3>UDP</h3>
|
||||
<div class="input-group">
|
||||
|
|
@ -217,7 +203,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||
<br>
|
||||
|
||||
<?php
|
||||
// optional status messages
|
||||
if (!empty($saveError)) echo '<p style="color:red;text-align:center;">' . htmlspecialchars($saveError) . '</p>';
|
||||
if (!empty($saveSuccess)) echo '<p style="color:green;text-align:center;">' . htmlspecialchars($saveSuccess) . '</p>';
|
||||
?>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,140 +0,0 @@
|
|||
{
|
||||
"video": {
|
||||
"resolution": "1920x1080",
|
||||
"format": "h264_qsv",
|
||||
"framerate": "25",
|
||||
"data_rate": "3.3M",
|
||||
"gop": "25"
|
||||
},
|
||||
"audio": {
|
||||
"format": "aac",
|
||||
"sample_rate": "48000",
|
||||
"bit_rate": "96k",
|
||||
"db_gain": "mp2"
|
||||
},
|
||||
"service_display": "disable",
|
||||
"output_display": "1920x1080@60.00",
|
||||
"output_display_audio": "0,3",
|
||||
"service_rtmp_multiple": "enable",
|
||||
"service_rtmp_hls": "enable",
|
||||
"service_rtmp_dash": "enable",
|
||||
"service_srt_multiple": "disable",
|
||||
"service_udp": "disable",
|
||||
"service_custom": "disable",
|
||||
"rtmp_multiple": {
|
||||
"1": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"2": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"3": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"4": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"5": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"6": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"7": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"8": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"9": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"10": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"11": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
}
|
||||
},
|
||||
"srt_multiple": {
|
||||
"1": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"2": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"3": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"4": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"5": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"6": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"7": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"8": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"9": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"10": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
},
|
||||
"11": {
|
||||
"url": "",
|
||||
"name": "",
|
||||
"enabled": false
|
||||
}
|
||||
},
|
||||
"udp": "",
|
||||
"custom_output": ""
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ $defaults = [
|
|||
'format' => 'h264_qsv',
|
||||
'framerate' => '25',
|
||||
'data_rate' => '3.3M',
|
||||
'gop' => '12'
|
||||
'gop' => '25'
|
||||
],
|
||||
'audio' => [
|
||||
'format' => 'aac',
|
||||
|
|
|
|||
|
|
@ -62,16 +62,14 @@ function update_service($which_service)
|
|||
'rtmp' => [
|
||||
'mount' => 'channel_name',
|
||||
'password' => 'live',
|
||||
'port' => '1935'
|
||||
],
|
||||
'srt' => [
|
||||
'stream_id_1' => 'har',
|
||||
'stream_id_2' => 'har',
|
||||
'stream_id_3' => 'mahadev',
|
||||
'port' => '1937'
|
||||
],
|
||||
'udp' => 'udp://@224.1.1.1:8000',
|
||||
'custom' => ''
|
||||
'custom' => '',
|
||||
];
|
||||
|
||||
$jsonFile = __DIR__ . '/input.json';
|
||||
|
|
@ -100,11 +98,14 @@ function update_service($which_service)
|
|||
case "url":
|
||||
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i " . $data['url'];
|
||||
break;
|
||||
case "udp":
|
||||
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i " . $data['udp']."?reuse=1&fifo_size=1000000&overrun_nonfatal=1";
|
||||
break;
|
||||
case "rtmp":
|
||||
$input .= "ffmpeg -hwaccel auto -stream_loop -1 -re -i rtmp://127.0.0.1:" . $$input_rtmp_port . "/" . $$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;
|
||||
case "srt":
|
||||
$input .= "-stream_loop -1 -re -i srt://127.0.0.1:" . $data['srt']['port'] . "/" . $data['srt']['stream_id_1'] . "/" . $data['srt']['stream_id_2'] . "/" . $data['srt']['stream_id_3'];
|
||||
$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_port_srt = $data['srt']['port'];
|
||||
break;
|
||||
}
|
||||
|
|
@ -166,7 +167,7 @@ function update_service($which_service)
|
|||
$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'] . ' -vsync 1 -copytb 1 -f mpegts udp://239.255.255.254:39000?localaddr=127.0.0.1';
|
||||
' -c:a ' . $data['audio']['format'] . ' -ar ' . $data['audio']['sample_rate'] . ' -b:a ' . $data['audio']['bit_rate'] . ' -vsync 1 -copytb 1 -f mpegts udp://127.0.0.1:39000';
|
||||
|
||||
$service = $input;
|
||||
$file = "/var/www/encoder-main.sh";
|
||||
|
|
@ -231,7 +232,7 @@ events {
|
|||
$nginx .= "
|
||||
rtmp {
|
||||
server {
|
||||
listen " . $input_rtmp_port . ";
|
||||
listen 1935;
|
||||
chunk_size 4096;
|
||||
|
||||
application " . $input_rtmp_mount . " {
|
||||
|
|
@ -298,7 +299,7 @@ http {
|
|||
file_put_contents($file, $nginx);
|
||||
|
||||
if ($service_rtmp_multiple === "enable") {
|
||||
$rtmp = 'ffmpeg -fflags nobuffer -i "udp://239.255.255.254:39000?localaddr=127.0.0.1&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://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';
|
||||
$file = "/var/www/encoder-rtmp.sh";
|
||||
file_put_contents($file, $rtmp);
|
||||
exec('sudo cp /var/www/nginx.conf /etc/nginx/nginx.conf');
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
{"timestamps": ["2025-11-21T00:47:40", "2025-11-21T00:47:50", "2025-11-21T00:48:00", "2025-11-21T00:48:10", "2025-11-21T00:48:20", "2025-11-21T00:48:30", "2025-11-21T00:48:40", "2025-11-21T00:48:50", "2025-11-21T00:49:00", "2025-11-21T00:49:10", "2025-11-21T00:49:20", "2025-11-21T00:49:30", "2025-11-21T00:49:40", "2025-11-21T00:49:50", "2025-11-21T00:50:00", "2025-11-21T00:50:10", "2025-11-21T00:50:20", "2025-11-21T00:50:30", "2025-11-21T00:50:40", "2025-11-21T00:50:50", "2025-11-21T00:51:00", "2025-11-21T00:51:10", "2025-11-21T00:51:20", "2025-11-21T00:51:30", "2025-11-21T00:51:40", "2025-11-21T00:51:50", "2025-11-21T00:52:00", "2025-11-21T00:52:10", "2025-11-21T00:52:20", "2025-11-21T00:52:30", "2025-11-21T00:52:40", "2025-11-21T00:52:50", "2025-11-21T00:53:00", "2025-11-21T00:53:10", "2025-11-21T00:53:20", "2025-11-21T00:53:30", "2025-11-21T00:53:40", "2025-11-21T00:53:50", "2025-11-21T00:54:00", "2025-11-21T00:54:10", "2025-11-21T00:54:20", "2025-11-21T00:54:30", "2025-11-21T00:54:40", "2025-11-21T00:54:50", "2025-11-21T00:55:00", "2025-11-21T00:55:10", "2025-11-21T00:55:20", "2025-11-21T00:55:30", "2025-11-21T00:55:40", "2025-11-21T00:55:50", "2025-11-21T00:56:00", "2025-11-21T00:56:10", "2025-11-21T00:56:20", "2025-11-21T00:56:30", "2025-11-21T00:56:40", "2025-11-21T00:56:50", "2025-11-21T00:57:00", "2025-11-21T00:57:10", "2025-11-21T00:57:20", "2025-11-21T00:57:30", "2025-11-21T00:57:40"], "cpu_percent": [54.4, 3.4, 3.8, 22.4, 2.4, 2.0, 0.8, 1.1, 0.9, 0.3, 0.3, 0.2, 0.5, 0.9, 3.5, 3.6, 1.3, 3.6, 2.7, 2.5, 0.9, 0.5, 2.1, 1.5, 1.3, 1.1, 0.7, 0.7, 0.3, 0.5, 0.7, 0.9, 2.3, 1.7, 3.7, 2.4, 0.6, 0.7, 1.4, 0.9, 1.0, 1.3, 1.6, 1.1, 1.1, 1.3, 1.5, 2.2, 1.1, 0.8, 1.9, 1.1, 1.5, 2.0, 1.1, 1.0, 0.7, 0.7, 0.4, 0.6, 0.6], "ram_percent": [12.0, 11.8, 14.2, 22.7, 22.5, 21.8, 20.5, 20.8, 20.6, 20.6, 20.6, 20.6, 20.7, 20.7, 20.7, 20.3, 20.4, 20.5, 20.7, 20.9, 20.8, 20.9, 20.7, 20.9, 20.8, 20.9, 20.9, 20.9, 20.9, 20.9, 20.9, 20.9, 20.7, 20.8, 20.7, 20.7, 20.7, 20.7, 20.7, 20.7, 20.8, 20.8, 20.8, 20.8, 20.8, 20.8, 20.8, 20.8, 20.6, 20.7, 20.6, 20.7, 20.8, 20.8, 20.8, 20.8, 20.8, 20.9, 20.9, 20.9, 20.6], "net_in_Bps": [0, 13501, 22329, 2404969, 53853, 57493, 14638, 40680, 17757, 4260, 4827, 4201, 11309, 31748, 62882, 113763, 49417, 115006, 80963, 96983, 22749, 13419, 88845, 62690, 51701, 51111, 20978, 25306, 4696, 14746, 27890, 33941, 133589, 79093, 78531, 34527, 43981, 47012, 25193, 41142, 49470, 73030, 95967, 60869, 39479, 41704, 38551, 71921, 48684, 29186, 73650, 48191, 48310, 64889, 30548, 20121, 27287, 22316, 7927, 45252, 45871], "net_out_Bps": [0, 13848, 15883, 3517467, 53929, 119586, 47714, 39702, 21887, 3644, 4141, 3729, 11688, 29952, 67199, 127605, 50725, 148075, 96740, 128403, 26506, 12856, 100371, 69040, 50795, 50332, 19916, 24557, 3919, 13919, 26614, 34587, 135280, 84589, 106634, 37939, 44131, 47621, 28339, 40672, 49609, 74210, 97532, 60964, 39693, 43234, 42344, 72846, 50265, 30179, 81170, 50862, 52123, 70809, 34170, 22933, 27265, 21764, 7253, 44382, 45358], "disk_read_Bps": [60545190, 7092722, 8560429, 5907517, 10328, 11464, 0, 14741, 478701, 0, 0, 0, 0, 0, 13102, 33985, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4094, 0], "disk_write_Bps": [1371607, 129375, 396369, 281719, 145029, 759959, 137580, 20883, 75347, 9417, 20882, 9417, 9417, 12283, 17606, 22929, 26204, 9417, 27024, 30300, 13102, 27433, 36441, 19243, 18834, 25386, 6141, 6551, 21701, 6960, 22519, 10236, 12693, 20472, 9007, 39306, 42992, 22110, 12692, 13102, 6960, 36849, 6551, 23747, 18015, 7779, 26204, 15968, 6960, 22109, 23747, 6141, 21701, 31123, 40534, 45856, 16786, 6141, 22109, 7369, 11054], "disk_percent": [7.3, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2, 7.2], "sample_interval": 10.0, "generated_at": "2025-11-21T00:57:40Z"}
|
||||
12
install.sh
12
install.sh
|
|
@ -267,7 +267,11 @@ if __name__ == "__main__":
|
|||
main()
|
||||
EOL
|
||||
|
||||
# srt server setup
|
||||
|
||||
sudo mkdir -p /etc/srt/;
|
||||
cat > /etc/srt/srt.sh<< 'EOL'
|
||||
/etc/srt/srt -c /var/www/sls.conf
|
||||
EOL
|
||||
sudo chmod +x /etc/srt/srt.sh
|
||||
sudo cp srt /etc/srt/
|
||||
cat > /etc/systemd/system/srt.service<< 'EOL'
|
||||
|
|
@ -291,10 +295,6 @@ SyslogIdentifier=srt
|
|||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
cat > /etc/srt/srt.sh<< 'EOL'
|
||||
/etc/srt/srt -c /var/www/html/sls.conf
|
||||
EOL
|
||||
|
||||
cat > /etc/nginx/sites-available/default<< 'EOL'
|
||||
server {
|
||||
listen 80 default_server;
|
||||
|
|
@ -334,3 +334,5 @@ sudo systemctl enable --now nginx.service
|
|||
sudo systemctl status nginx.service --no-pager
|
||||
sudo chmod 777 -R /var/www
|
||||
sudo chown -R www-data:www-data /var/www
|
||||
sudo ufw allow proto udp to 224.0.0.0/4
|
||||
sudo ufw route allow proto udp to 224.0.0.0/4
|
||||
|
|
|
|||
189
setup/install.sh
189
setup/install.sh
|
|
@ -1,189 +0,0 @@
|
|||
sudo mkdir /etc/srt;
|
||||
sudo apt update
|
||||
sudo apt install -y vainfo intel-media-va-driver-non-free i965-va-driver-shaders ffmpeg nginx v4l-utils python3-pip php-fpm mpv libnginx-mod-rtmp alsa-utils vlan git zlib1g-dev
|
||||
sudo pip3 install psutil --break-system-packages
|
||||
|
||||
dpkg -i srt-1.5.5-Linux.deb
|
||||
|
||||
cat >/etc/sudoers.d/www-data<<EOL
|
||||
www-data ALL=(ALL) NOPASSWD: ALL
|
||||
EOL
|
||||
|
||||
cat > /etc/systemd/system/main-encoder.service<<EOL
|
||||
[Unit]
|
||||
Description=Main Encoder by ShreeBhattJi
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash /var/www/html/main-encoder.sh
|
||||
WorkingDirectory=/var/www/html
|
||||
Restart=always
|
||||
User=root
|
||||
Environment=PATH=/usr/bin:/usr/local/bin
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
# graph monitor setup
|
||||
cat > /etc/systemd/system/system-monitor.service<<EOL
|
||||
[Unit]
|
||||
Description=Lightweight System Monitor Sampler by ShreeBhattJi
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /usr/local/bin/nginx_system_monitor_sampler.py
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
User=root
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
cat > /usr/local/bin/nginx_system_monitor_sampler.py<<EOL
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Lightweight sampler for nginx static frontend.
|
||||
"""
|
||||
|
||||
import time, json, os
|
||||
from collections import deque
|
||||
from datetime import datetime
|
||||
import psutil
|
||||
|
||||
OUT_FILE = "/var/www/html/metrics.json"
|
||||
TMP_FILE = OUT_FILE + ".tmp"
|
||||
SAMPLE_INTERVAL = 10.0 # seconds between samples
|
||||
HISTORY_SECONDS = 15 * 60 # 15 minutes
|
||||
MAX_SAMPLES = int(HISTORY_SECONDS / SAMPLE_INTERVAL)
|
||||
|
||||
# circular buffers
|
||||
timestamps = deque(maxlen=MAX_SAMPLES)
|
||||
cpu_hist = deque(maxlen=MAX_SAMPLES)
|
||||
ram_hist = deque(maxlen=MAX_SAMPLES)
|
||||
net_in_hist = deque(maxlen=MAX_SAMPLES)
|
||||
net_out_hist = deque(maxlen=MAX_SAMPLES)
|
||||
disk_read_hist = deque(maxlen=MAX_SAMPLES)
|
||||
disk_write_hist = deque(maxlen=MAX_SAMPLES)
|
||||
disk_percent_hist = deque(maxlen=MAX_SAMPLES)
|
||||
|
||||
_prev_net = psutil.net_io_counters()
|
||||
_prev_disk = psutil.disk_io_counters()
|
||||
_prev_time = time.time()
|
||||
|
||||
def sample_once():
|
||||
global _prev_net, _prev_disk, _prev_time
|
||||
now = time.time()
|
||||
iso = datetime.fromtimestamp(now).isoformat(timespec='seconds')
|
||||
cpu = psutil.cpu_percent(interval=None)
|
||||
ram = psutil.virtual_memory().percent
|
||||
|
||||
net = psutil.net_io_counters()
|
||||
disk = psutil.disk_io_counters()
|
||||
try:
|
||||
disk_percent = psutil.disk_usage("/").percent
|
||||
except Exception:
|
||||
disk_percent = 0.0
|
||||
|
||||
elapsed = now - _prev_time if _prev_time else SAMPLE_INTERVAL
|
||||
if elapsed <= 0:
|
||||
elapsed = SAMPLE_INTERVAL
|
||||
|
||||
in_rate = (net.bytes_recv - _prev_net.bytes_recv) / elapsed
|
||||
out_rate = (net.bytes_sent - _prev_net.bytes_sent) / elapsed
|
||||
|
||||
read_rate = (disk.read_bytes - _prev_disk.read_bytes) / elapsed
|
||||
write_rate = (disk.write_bytes - _prev_disk.write_bytes) / elapsed
|
||||
|
||||
timestamps.append(iso)
|
||||
cpu_hist.append(round(cpu, 2))
|
||||
ram_hist.append(round(ram, 2))
|
||||
net_in_hist.append(int(in_rate))
|
||||
net_out_hist.append(int(out_rate))
|
||||
disk_read_hist.append(int(read_rate))
|
||||
disk_write_hist.append(int(write_rate))
|
||||
disk_percent_hist.append(round(disk_percent, 2))
|
||||
|
||||
_prev_net = net
|
||||
_prev_disk = disk
|
||||
_prev_time = now
|
||||
|
||||
def write_json_atomic():
|
||||
payload = {
|
||||
"timestamps": list(timestamps),
|
||||
"cpu_percent": list(cpu_hist),
|
||||
"ram_percent": list(ram_hist),
|
||||
"net_in_Bps": list(net_in_hist),
|
||||
"net_out_Bps": list(net_out_hist),
|
||||
"disk_read_Bps": list(disk_read_hist),
|
||||
"disk_write_Bps": list(disk_write_hist),
|
||||
"disk_percent": list(disk_percent_hist),
|
||||
"sample_interval": SAMPLE_INTERVAL,
|
||||
"generated_at": datetime.utcnow().isoformat(timespec='seconds') + "Z"
|
||||
}
|
||||
with open(TMP_FILE, "w") as f:
|
||||
json.dump(payload, f)
|
||||
os.replace(TMP_FILE, OUT_FILE)
|
||||
|
||||
def main():
|
||||
global _prev_net, _prev_disk, _prev_time
|
||||
_prev_net = psutil.net_io_counters()
|
||||
_prev_disk = psutil.disk_io_counters()
|
||||
_prev_time = time.time()
|
||||
time.sleep(0.2) # warm-up
|
||||
|
||||
while True:
|
||||
try:
|
||||
sample_once()
|
||||
write_json_atomic()
|
||||
except Exception as e:
|
||||
# systemd journal will capture prints
|
||||
print("Sampler error:", e)
|
||||
time.sleep(SAMPLE_INTERVAL)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
EOL
|
||||
|
||||
# srt server setup
|
||||
sudo chmod +x /etc/srt/srt.sh
|
||||
sudo cp srt /etc/srt/
|
||||
cat > /etc/systemd/system/srt.service<<EOL
|
||||
[Unit]
|
||||
Description=Srt by ShreeBhattJi
|
||||
Documentation=https://dbhatt.org
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
TimeoutStartSec=0
|
||||
Restart=always
|
||||
RestartSec=30s
|
||||
Requires=srt
|
||||
ExecStart=/bin/bash /etc/srt/srt.sh
|
||||
SyslogIdentifier=srt
|
||||
#ExecStop=
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
cat > /etc/srt/srt.sh<<EOL
|
||||
/etc/srt/srt -c /var/www/html/sls.conf
|
||||
EOL
|
||||
|
||||
sudo chmod +x /usr/local/bin/nginx_system_monitor_sampler.py
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now system-monitor.service
|
||||
sudo systemctl status system-monitor.service --no-pager
|
||||
sudo systemctl enable --now main-encoder.service
|
||||
sudo systemctl status main-encoder.service --no-pager
|
||||
sudo systemctl enable --now srt.service
|
||||
sudo systemctl status srt.service --no-pager
|
||||
sudo systemctl enable --now nginx.service
|
||||
sudo systemctl status nginx.service --no-pager
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
srt {
|
||||
worker_threads 8;
|
||||
worker_connections 100;
|
||||
|
||||
log_file /var/log/srt/error.log ;
|
||||
log_level info;
|
||||
|
||||
record_hls_path_prefix /tmp/mov/sls;
|
||||
|
||||
server {
|
||||
listen 1937;
|
||||
latency 2000;
|
||||
|
||||
domain_player domain_playerdomain_playerdomain_player;
|
||||
domain_publisher domain_publisherdomain_publisherdomain_publisher;
|
||||
backlog 100;
|
||||
idle_streams_timeout 15;
|
||||
|
||||
app {
|
||||
app_player app_playerapp_playerapp_player ;
|
||||
app_publisher app_publisherapp_publisherapp_publisher ;
|
||||
|
||||
record_hls off;
|
||||
record_hls_segment_duration 10;
|
||||
|
||||
#relay {
|
||||
# type pull;
|
||||
# mode loop;#loop; hash;
|
||||
# reconnect_interval 10;
|
||||
# idle_streams_timeout -1;#s -1: unlimited
|
||||
# upstreams 127.0.0.1:9090?streamid=live.sls.com/live 192.168.1.100:8080/?streamid=live.test.com/live;
|
||||
#}
|
||||
#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 ;
|
||||
#}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
26
sls.conf
26
sls.conf
|
|
@ -2,7 +2,7 @@ srt {
|
|||
worker_threads 8;
|
||||
worker_connections 100;
|
||||
|
||||
log_file /var/log/srt/error.log ;
|
||||
log_file /var/log/srteserver.log ;
|
||||
log_level info;
|
||||
|
||||
record_hls_path_prefix /tmp/mov/sls;
|
||||
|
|
@ -11,32 +11,24 @@ srt {
|
|||
listen 1937;
|
||||
latency 2000;
|
||||
|
||||
domain_player domain_playerdomain_playerdomain_player;
|
||||
domain_player shree;
|
||||
domain_publisher domain_publisherdomain_publisherdomain_publisher;
|
||||
backlog 100;
|
||||
idle_streams_timeout 15;
|
||||
|
||||
app {
|
||||
app_player app_playerapp_playerapp_player ;
|
||||
app_player bhatt ;
|
||||
app_publisher app_publisherapp_publisherapp_publisher ;
|
||||
|
||||
record_hls off;
|
||||
record_hls_segment_duration 10;
|
||||
|
||||
#relay {
|
||||
# type pull;
|
||||
# mode loop;#loop; hash;
|
||||
# reconnect_interval 10;
|
||||
# idle_streams_timeout -1;#s -1: unlimited
|
||||
# upstreams 127.0.0.1:9090?streamid=live.sls.com/live 192.168.1.100:8080/?streamid=live.test.com/live;
|
||||
#}
|
||||
#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 ;
|
||||
#}
|
||||
relay {
|
||||
type push;
|
||||
mode all;
|
||||
reconnect_interval 10;
|
||||
idle_streams_timeout 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue