1
0
Discord-RTMP-Notice/start.php

70 lines
2.1 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
{
$fileName = "output-".time().".jpg";
2020-06-12 12:49:25 +00:00
$videoFileName = "record-".time().".dump";
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-07 16:12:25 +00:00
system("ffmpeg -i ".$StreamURL." -vframes 1 -q:v 2 -vf scale=535:346 ".$fileName);
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:05:43 +00:00
$jsonStartMessage = str_replace("%%adresse%%", $StreamURL, $jsonMessage);
$jsonStartMessage = str_replace("%%vorschau%%", "https://files.clatza.dev/tmp/rtmp/".$fileName, $jsonMessage);
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-12 12:49:25 +00:00
2020-06-12 13:05:43 +00:00
system("rtmpdump -r ".$StreamURL." -m 15 -o /dev/null");
echo "Sending end info to discord...";
$result = file_get_contents($DiscordWebhook, false, stream_context_create($endOptions));
echo "done.\n";
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);
}
}
?>