OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
videoAI21-1-25
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/17/2025 10:17:24 AM
rwxrwxr-x
📁
audio
-
01/22/2025 07:07:41 AM
rwxrwxrwx
📄
export.php
6.97 KB
05/19/2025 10:07:22 AM
rw-r--r--
📁
files
-
01/22/2025 07:01:42 AM
rwxrwxrwx
📄
index.php
4.93 KB
05/19/2025 10:07:22 AM
rw-r--r--
📄
script.js
6.46 KB
01/22/2025 07:01:36 AM
rw-r--r--
📄
styles.css
929 bytes
01/22/2025 07:01:36 AM
rw-r--r--
📄
video_process.php
11.12 KB
05/19/2025 10:07:22 AM
rw-r--r--
📄
zexport.php
3.56 KB
05/19/2025 10:07:22 AM
rw-r--r--
📄
zindex.php
4.48 KB
05/19/2025 10:07:22 AM
rw-r--r--
📄
zscript.js
5.78 KB
01/22/2025 07:01:36 AM
rw-r--r--
Editing: video_process.php
Close
<?php include '../assets/php/validate.logged.php'; include '../assets/php/db_config.php'; include '../assets/php/function.php'; function texttovoice($timestamp, $data) { $apiKey = "sk-proj-FrlWqCTIyid7DZGorv0uT3BlbkFJzqrUB0km57kpp4aFPNV7"; $url = "https://api.openai.com/v1/audio/speech"; $payload = array( "model" => "tts-1", "input" => $data, "voice" => "ash" ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: Bearer $apiKey" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if ($response === false) { echo 'cURL Error: ' . curl_error($ch); curl_close($ch); return false; } // Ensure the directory exists and is writable $audioDir = $_SERVER['DOCUMENT_ROOT'] . '/videoAI/audio/'; if (!is_dir($audioDir)) { mkdir($audioDir, 0777, true); // Create directory if it does not exist } // Save the response to a file $root = $audioDir . '_' . $timestamp . 'speech.mp3'; if (file_put_contents($root, $response) === false) { echo 'Failed to save the audio file.'; curl_close($ch); return false; } curl_close($ch); return 'audio/_' . $timestamp . 'speech.mp3'; } function deleteDirectory($dir) { if (!file_exists($dir)) { return false; } if (!is_dir($dir)) { return unlink($dir); } $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { $filePath = "$dir/$file"; (is_dir($filePath)) ? deleteDirectory($filePath) : unlink($filePath); } return rmdir($dir); } function uploadFiles($fileInputName, $uploadDir = 'files/temp/') { // Ensure the upload directory exists and is writable if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); // Create directory if it does not exist } // Check if files are uploaded if (isset($_FILES[$fileInputName])) { $files = $_FILES[$fileInputName]; $results = []; // To collect results or errors foreach ($files['tmp_name'] as $key => $tmpName) { $fileName = basename($files['name'][$key]); $fileTmpName = $files['tmp_name'][$key]; $fileError = $files['error'][$key]; $fileSize = $files['size'][$key]; $fileType = $files['type'][$key]; // Check for upload errors if ($fileError === UPLOAD_ERR_OK) { // Validate file size (e.g., limit to 5MB) $maxFileSize = 5 * 1024 * 1024; // 5MB if ($fileSize > $maxFileSize) { $results[] = "File $fileName is too large."; continue; } // Validate file type (e.g., only allow image files) $allowedTypes = ['image/jpeg', 'image/png', 'image/gif']; if (!in_array($fileType, $allowedTypes)) { $results[] = "File $fileName type is not allowed."; continue; } // Move file to the upload directory $fileDestination = $uploadDir . $fileName; if (move_uploaded_file($fileTmpName, $fileDestination)) { $results[] = "File $fileName uploaded successfully."; } else { $results[] = "Failed to move file $fileName."; } } else { // Handle upload errors $results[] = "Error uploading file $fileName: " . $fileError; } } return $results; // Return an array of results or errors } else { return ["No files were uploaded."]; } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Check if files are uploaded if (isset($_FILES['images']) && !empty($_FILES['images']['name'][0])) { $outputDir = 'files/output/'; $tempDir = 'files/temp/'; $serverBaseDir = escapeshellcmd('/var/www/cream/videoAI/'); // // Create temporary directory if it does not exist // if (!is_dir($tempDir)) { // mkdir($tempDir, 0777, true); // } $timestamp = time(); $imageFiles = $_FILES['images']; $tempImagePaths = []; $captions = isset($_POST['captions']) ? $_POST['captions'] : []; $audioString = ''; foreach ($captions as $caption) { $audioString .= $caption . ". "; } // Generate audio file (assuming texttovoice() is defined elsewhere) $audioDir = texttovoice($timestamp, $audioString); $durations = isset($_POST['durations']) ? $_POST['durations'] : []; $imageCount = 0; // Debugging: Print file upload errors foreach ($imageFiles['error'] as $error) { if ($error !== UPLOAD_ERR_OK) { echo "File upload error: $error<br>"; } } foreach ($imageFiles['tmp_name'] as $key => $tmpName) { if ($imageFiles['error'][$key] === UPLOAD_ERR_OK) { $fileName = sprintf('image%04d.png', ++$imageCount); $tempImagePath = $serverBaseDir . $tempDir . $fileName; if (move_uploaded_file($tmpName, $tempImagePath)) { $tempImagePaths[] = $tempImagePath; } else { echo "Failed to move uploaded file: $tmpName to $tempImagePath<br>"; } } else { echo "File upload error: " . $imageFiles['error'][$key] . "<br>"; } } if (!is_array($durations) || count($durations) !== count($tempImagePaths)) { $durations = array_fill(0, count($tempImagePaths), 5); } $listFilePath = $serverBaseDir . $tempDir . 'filelist.txt'; $fileListContent = ''; foreach ($tempImagePaths as $index => $path) { $duration = isset($durations[$index]) ? floatval($durations[$index]) : 5; $fileListContent .= "file '" . $path . "'\n"; $fileListContent .= "duration " . $duration . "\n"; } $fileListContent .= "file '" . $tempImagePaths[count($tempImagePaths) - 1] . "'\n"; $fileListContent .= "duration " . $durations[count($durations) - 1] . "\n"; file_put_contents($listFilePath, $fileListContent); $outputFileName = $timestamp . 'output_video.mp4'; $outputPath = $serverBaseDir . $outputDir . $outputFileName; // FFmpeg command $ffmpegPath = escapeshellcmd('ffmpeg'); $listFilePathEscaped = escapeshellarg($listFilePath); $outputPathEscaped = escapeshellarg($outputPath); $command = "$ffmpegPath -f concat -safe 0 -i $listFilePathEscaped -c:v libx264 -vf scale=1280:720,fps=30,format=yuv420p -vsync vfr $outputPathEscaped"; exec($command . " 2>&1", $outputLog, $returnVar); // // Debugging: Print command and output log // echo "<br>Command:<br>$command<br>"; // echo "<br>Output Log:<br><pre>" . implode("\n", $outputLog) . "</pre>"; // Cleanup // array_map('unlink', $tempImagePaths); // unlink($listFilePath); // deleteDirectory($tempDir); $outputLogString = implode("\n", $outputLog); $videoSourcePath = "/videoAI/files/output/" . $outputFileName; if ($returnVar === 0) { $message = "Video created successfully!"; $videoLink = '<video id="videoPreview" width="100%" height="360" controls> <source src="' . $videoSourcePath . '" type="video/mp4"> Your browser does not support the video tag. </video>'; } else { $message = "Failed to create video."; $videoLink = "<pre>$outputLogString</pre>"; } } else { $message = "Error uploading images."; $videoLink = ""; } } else { $message = "Invalid request method."; $videoLink = ""; } if ($audioDir) { $message .= "<audio id=\"audioPreview\" controls> <source src=\"$audioDir \" type=\"audio/mpeg\"> Your browser does not support the audio element... </audio>"; } // // Output the result message and video link // echo $message; // echo $videoLink; // die; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Video and Audio Result</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.3.0/css/bootstrap.min.css"> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="/assets/css/styles.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.8/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.3.3/js/bootstrap.min.js"></script> <script src="script.js"></script> </head> <body> <? include('../assets/php/navbar.php') ?> <div class="container"> <h1>Generated Video</h1> <!-- <?= $message ?><br> --> <?= $videoLink ?><br> <h1>Generated Audio</h1> <?php if ($audioDir): ?> <audio id="audioPreview" controls> <source src="<?= $audioDir ?>" type="audio/mpeg"> Your browser does not support the audio element... </audio> <?php else: ?> <p>No audio generated.</p> <?php endif; ?><br> <button class="btn btn-primary" onclick="playAll()"> Play all</button> <button class="btn btn-primary" onclick="mergeAudioVideo('<?= $audioDir ?>','<?= $videoSourcePath ?>')"> Merge</button> </div> </body> <script> function mergeAudioVideo(audio, video) { // Create a form element var form = $('<form>', { 'action': 'export.php', 'method': 'post' }); // Append the audio input $('<input>', { 'type': 'hidden', 'name': 'audio', 'value': audio }).appendTo(form); // Append the video input $('<input>', { 'type': 'hidden', 'name': 'video', 'value': video }).appendTo(form); // Append the form to the body and submit it form.appendTo('body').submit(); } function playAll() { // Get the video and audio elements var video = document.getElementById('videoPreview'); var audio = document.getElementById('audioPreview'); // Play both video and audio video.play(); audio.play(); } </script> </html>