1
0
Fork 0
Discord-RTMP-Notice/start.php

80 lines
2.8 KiB
PHP
Raw Normal View History

2020-06-07 16:12:25 +00:00
<?php
include "config.php";
2020-06-07 18:56:02 +00:00
ini_set("default_socket_timeout", 10);
2020-06-07 16:29:04 +00:00
echo "StreamURL: ".$StreamURL."\n";
echo "DiscordWebhook: ".$DiscordWebhook."\n";
2020-06-07 16:30:11 +00:00
$lastOnlineTime = 0;
2020-06-07 16:12:25 +00:00
while(TRUE)
{
2020-06-12 12:49:25 +00:00
if(($lastOnlineTime + 60) < time())
2020-06-07 16:12:25 +00:00
{
2020-06-12 15:37:45 +00:00
$fileName = "output-".md5(time().rand(11111,99999)).".gif";
2020-06-15 22:50:59 +00:00
$videoFileName = md5(time().rand(11111,99999)).".flv";
2020-06-07 16:12:25 +00:00
2020-06-07 16:29:04 +00:00
echo "Checking stream and creating image...\n";
2020-06-12 13:17:02 +00:00
//system("ffmpeg -i ".$StreamURL." -vframes 1 -q:v 2 -vf scale=535:346 ".$fileName);
2020-06-12 15:37:45 +00:00
system('ffmpeg -r 90 -t 4 -i '.$StreamURL.' -vf "fps=10,scale=350:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 '.$fileName);
2020-06-07 16:12:25 +00:00
if(is_file($fileName))
{
$lastOnlineTime = time();
copy($fileName, "tmp/rtmp/".$fileName);
unlink($fileName);
2020-06-12 13:05:43 +00:00
$jsonStartMessage = file_get_contents("startMessage.json");
$jsonEndMessage = file_get_contents("endMessage.json");
2020-06-07 16:47:46 +00:00
2020-06-12 13:10:29 +00:00
$jsonStartMessage = str_replace("%%adresse%%", $StreamURL, $jsonStartMessage);
$jsonStartMessage = str_replace("%%vorschau%%", "https://files.clatza.dev/tmp/rtmp/".$fileName, $jsonStartMessage);
2020-06-15 22:57:29 +00:00
$jsonStartMessage = str_replace("%%record%%", "https://files.clatza.dev/tmp/rtmp/".$videoFileName, $jsonStartMessage);
$jsonEndMessage = str_replace("%%record%%", "https://files.clatza.dev/tmp/rtmp/".$videoFileName, $jsonEndMessage);
2020-06-07 16:12:25 +00:00
2020-06-12 13:05:43 +00:00
$startOptions = [
2020-06-07 16:12:25 +00:00
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
2020-06-07 18:56:02 +00:00
'timeout' => 5,
2020-06-12 13:05:43 +00:00
'content' => $jsonStartMessage
2020-06-07 16:12:25 +00:00
]
];
2020-06-12 13:05:43 +00:00
$endOptions = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'timeout' => 5,
'content' => $jsonEndMessage
]
];
echo "Sending start info to discord...";
$result = file_get_contents($DiscordWebhook, false, stream_context_create($startOptions));
2020-06-07 18:56:32 +00:00
echo "done.\n";
2020-06-15 16:37:08 +00:00
$lastOnlineTime = time();
2020-06-15 22:52:43 +00:00
system("rtmpdump -r ".$StreamURL." -m 15 -o tmp/rtmp/".$videoFileName);
2020-06-15 16:35:45 +00:00
2020-06-15 16:36:16 +00:00
if(($lastOnlineTime + 10) < time())
2020-06-15 16:35:45 +00:00
{
echo "Sending end info to discord...";
$result = file_get_contents($DiscordWebhook, false, stream_context_create($endOptions));
echo "done.\n";
}else{
2020-06-15 16:51:35 +00:00
$lastOnlineTime = $lastOnlineTime + 3600;
2020-06-15 16:29:14 +00:00
}
2020-06-07 16:29:04 +00:00
}else{
echo "ERROR: Image not generated!\n";
2020-06-07 16:12:25 +00:00
}
}else{
2020-06-12 12:49:25 +00:00
echo "Wait for next check ... ( ".(($lastOnlineTime + 60) - time()).")\n";
2020-06-07 16:12:25 +00:00
sleep(5);
}
}
?>