From 7111ca10b5ce2d51d4cc10c9472b99644b4324f6 Mon Sep 17 00:00:00 2001 From: Metacube Date: Sun, 21 Sep 2025 19:26:27 +0200 Subject: [PATCH] Create stream_control.php --- stream_control.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 stream_control.php diff --git a/stream_control.php b/stream_control.php new file mode 100644 index 0000000..0fcd546 --- /dev/null +++ b/stream_control.php @@ -0,0 +1,33 @@ + /dev/null 2>&1 & echo $!', $output); + return $output[0]; +} + +function stopEncoder($pid) { + exec("kill $pid"); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $action = $_POST['action']; + + if ($action === 'start') { + if (!isset($_SESSION['encoder_pid'])) { + $pid = startEncoder(); + $_SESSION['encoder_pid'] = $pid; + echo json_encode(['status' => 'started', 'pid' => $pid]); + } else { + echo json_encode(['status' => 'already_running', 'pid' => $_SESSION['encoder_pid']]); + } + } elseif ($action === 'stop') { + if (isset($_SESSION['encoder_pid'])) { + stopEncoder($_SESSION['encoder_pid']); + unset($_SESSION['encoder_pid']); + echo json_encode(['status' => 'stopped']); + } else { + echo json_encode(['status' => 'not_running']); + } + } +}