forked from grimelinse/FOS-Streaming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.php
113 lines (92 loc) · 4.64 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
//if(isset($_SERVER['SERVER_ADDR'])) {
// if( $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'] ){
// die('access is not permitted');
// }
//}
include('config.php');
$setting = Setting::first();
$streams = Stream::where('pid', '!=', 0)->where('running', '=', 1)->get();
foreach($streams as $stream) {
if (!checkPid($stream->pid)) {
$stream->checker = 0;
$checkstreamurl = shell_exec('/usr/bin/timeout 15s '.$setting->ffprobe_path.' -analyzeduration 10000000 -probesize 9000000 -i "'.$stream->streamurl.'" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array) json_decode($checkstreamurl);
if(count($streaminfo) > 0) {
$pid = shell_exec(getTranscode($stream->id));
$stream->pid = $pid;
$stream->running = 1;
$stream->status = 1;
if(isset($streaminfo->streams)) {
foreach ((array)$streaminfo->streams as $info) {
if ($info->codec_type == 'video') {
$stream->video_codec_name = $info->codec_long_name;
} else if ($info->codec_type == 'audio') {
$stream->audio_codec_name = $info->codec_long_name;
}
}
}
} else {
$stream->running = 1;
$stream->status = 2;
//need to make recursive
////streamurl 2 checker
shell_exec("kill -9 " . $stream->pid);
shell_exec("/bin/rm -r /usr/local/nginx/html/" . $setting->hlsfolder . "/" . $stream->id . "*");
if($stream->streamurl2) {
$stream->checker = 2;
echo "checking stream 2";
$checkstreamurl = shell_exec('/usr/bin/timeout 15s '.$setting->ffprobe_path.' -analyzeduration 10000000 -probesize 9000000 -i "'.$stream->streamurl2.'" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array) json_decode($checkstreamurl);
if(count($streaminfo) > 0) {
echo getTranscode($stream->id, 2);
$pid = shell_exec(getTranscode($stream->id, 2));
$stream->pid = $pid;
$stream->running = 1;
$stream->status = 1;
if(isset($streaminfo->streams)) {
foreach((array)$streaminfo->streams as $info ) {
if($info->codec_type == 'video') {
$stream->video_codec_name = $info->codec_long_name;
}
else if($info->codec_type == 'audio') {
$stream->audio_codec_name = $info->codec_long_name;
}
}
}
} else {
$stream->running = 1;
$stream->status = 2;
shell_exec("kill -9 " . $stream->pid);
shell_exec("/bin/rm -r /usr/local/nginx/html/" . $setting->hlsfolder . "/" . $stream->id . "*");
//streamurl 3 checker
if($stream->streamurl3) {
$stream->checker = 3;
$checkstreamurl = shell_exec('/usr/bin/timeout 15s ' . $setting->ffprobe_path . ' -analyzeduration 10000000 -probesize 9000000 -i "' . $stream->streamurl3 . '" -v quiet -print_format json -show_streams 2>&1');
$streaminfo = (array)json_decode($checkstreamurl);
if (count($streaminfo) > 0) {
$pid = shell_exec(getTranscode($stream->id, 3));
$stream->pid = $pid;
$stream->running = 1;
$stream->status = 1;
if(isset($streaminfo->streams)) {
foreach ((array)$streaminfo->streams as $info) {
if ($info->codec_type == 'video') {
$stream->video_codec_name = $info->codec_long_name;
} else if ($info->codec_type == 'audio') {
$stream->audio_codec_name = $info->codec_long_name;
}
}
}
} else {
$stream->running = 1;
$stream->status = 2;
$stream->pid = null;
}
}
}
}
}
$stream->save();
}
}