OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
videoAI
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/17/2025 10:17:24 AM
rwxrwxr-x
📁
audio
-
05/27/2025 11:39:08 AM
rwxrwxrwx
📄
export.php
7.03 KB
05/27/2025 08:33:14 AM
rw-r--r--
📁
files
-
01/20/2025 01:42:22 PM
rwxrwxrwx
📄
index.php
17.01 KB
05/27/2025 11:38:13 AM
rw-r--r--
📄
script.js
6.46 KB
01/20/2025 05:12:16 PM
rw-r--r--
📄
styles.css
1.01 KB
01/21/2025 10:07:14 AM
rw-r--r--
📄
video_process.php
17.44 KB
05/27/2025 11:38:14 AM
rwxrwxrwx
📄
zexport.php
3.56 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
zindex.php
4.48 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
zscript.js
5.78 KB
01/20/2025 11:47:19 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 mergeAudioFiles($audioFile1, $audioFile2, $timestamp, $order = 'first_then_second') { $serverBaseDir = '/var/www/cream/videoAI/'; $audioDir = $serverBaseDir . 'audio/'; // Ensure the directory exists if (!is_dir($audioDir)) { mkdir($audioDir, 0777, true); } $outputFileName = '_' . $timestamp . 'merged_audio.mp3'; $outputPath = $audioDir . $outputFileName; // Escape file paths for shell commands $audioFile1Escaped = escapeshellarg($audioFile1); $audioFile2Escaped = escapeshellarg($audioFile2); $outputPathEscaped = escapeshellarg($outputPath); // Create temporary concat file list $concatListPath = $audioDir . 'concat_list_' . $timestamp . '.txt'; if ($order === 'first_then_second') { $concatContent = "file $audioFile1Escaped\nfile $audioFile2Escaped"; } else { $concatContent = "file $audioFile2Escaped\nfile $audioFile1Escaped"; } file_put_contents($concatListPath, $concatContent); // FFmpeg command to concatenate audio files $ffmpegPath = 'ffmpeg'; $concatListPathEscaped = escapeshellarg($concatListPath); $command = "$ffmpegPath -f concat -safe 0 -i $concatListPathEscaped -c copy $outputPathEscaped"; exec($command . " 2>&1", $outputLog, $returnVar); // Cleanup temporary concat list unlink($concatListPath); if ($returnVar === 0) { return 'audio/' . $outputFileName; } else { error_log("Audio merge failed: " . implode("\n", $outputLog)); return false; } } function uploadAudioFile($fileInputName, $uploadDir = 'audio/uploaded/', $timestamp) { $serverBaseDir = '/var/www/cream/videoAI/'; $fullUploadDir = $serverBaseDir . $uploadDir; // Ensure the upload directory exists if (!is_dir($fullUploadDir)) { mkdir($fullUploadDir, 0755, true); } if (isset($_FILES[$fileInputName]) && $_FILES[$fileInputName]['error'] === UPLOAD_ERR_OK) { $file = $_FILES[$fileInputName]; $fileName = $timestamp . '_' . basename($file['name']); $fileTmpName = $file['tmp_name']; $fileSize = $file['size']; $fileType = $file['type']; // Validate file size (limit to 10MB) $maxFileSize = 10 * 1024 * 1024; // 10MB if ($fileSize > $maxFileSize) { return ['error' => 'Audio file is too large. Maximum size is 10MB.']; } // Validate file type (allow common audio formats) $allowedTypes = ['audio/mpeg', 'audio/mp3', 'audio/wav', 'audio/ogg', 'audio/m4a']; if (!in_array($fileType, $allowedTypes)) { return ['error' => 'Audio file type not allowed. Please upload MP3, WAV, OGG, or M4A files.']; } $fileDestination = $fullUploadDir . $fileName; if (move_uploaded_file($fileTmpName, $fileDestination)) { return ['success' => true, 'path' => $fileDestination, 'relative_path' => $uploadDir . $fileName]; } else { return ['error' => 'Failed to upload audio file.']; } } return ['error' => 'No audio file uploaded or upload error occurred.']; } 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/'); $timestamp = time(); $imageFiles = $_FILES['images']; $tempImagePaths = []; $captions = isset($_POST['captions']) ? $_POST['captions'] : []; $audioString = ''; foreach ($captions as $caption) { $audioString .= $caption . ". "; } // Generate text-to-speech audio file $ttsAudioPath = texttovoice($timestamp, $audioString); $finalAudioPath = $ttsAudioPath; // Default to TTS audio // Handle additional audio file upload and merging if (isset($_FILES['additional_audio']) && $_FILES['additional_audio']['error'] === UPLOAD_ERR_OK) { $audioUploadResult = uploadAudioFile('additional_audio', 'audio/uploaded/', $timestamp); if (isset($audioUploadResult['success']) && $audioUploadResult['success']) { $uploadedAudioPath = $audioUploadResult['path']; $serverTtsAudioPath = $serverBaseDir . $ttsAudioPath; // Get audio merge order preference $audioOrder = isset($_POST['audio_order']) ? $_POST['audio_order'] : 'tts_first'; $mergeOrder = ($audioOrder === 'uploaded_first') ? 'second_then_first' : 'first_then_second'; // Merge the audio files $mergedAudioPath = mergeAudioFiles($serverTtsAudioPath, $uploadedAudioPath, $timestamp, $mergeOrder); if ($mergedAudioPath) { $finalAudioPath = $mergedAudioPath; } else { $message = "Warning: Audio merge failed, using TTS audio only. "; } } else { $message = "Warning: " . $audioUploadResult['error'] . " Using TTS audio only. "; } } $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); $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>"; } $audioDir = $finalAudioPath; // Use the final audio path (merged or TTS only) } else { $message = "Error uploading images."; $videoLink = ""; } } else { $message = "Invalid request method."; $videoLink = ""; } if (isset($audioDir) && $audioDir) { $audioMessage = "<audio id=\"audioPreview\" controls> <source src=\"$audioDir\" type=\"audio/mpeg\"> Your browser does not support the audio element... </audio>"; } else { $audioMessage = "<p>No audio generated.</p>"; } ?> <!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> <?= $videoLink ?><br> <h1>Generated Audio</h1> <?= $audioMessage ?><br> <?php if (isset($message) && !empty($message)): ?> <div class="alert alert-info"> <?= $message ?> </div> <?php endif; ?> <button class="btn btn-primary" onclick="playAll()">Play all</button> <button class="btn btn-primary" onclick="mergeAudioVideo('<?= isset($audioDir) ? $audioDir : '' ?>','<?= isset($videoSourcePath) ? $videoSourcePath : '' ?>')">Merge</button> <!-- Form to add additional audio file --> <div class="mt-4"> <h3>Add Additional Audio (Optional)</h3> <form method="post" enctype="multipart/form-data" class="mb-3"> <!-- Include existing form data as hidden fields --> <?php if (isset($_POST['captions'])): ?> <?php foreach ($_POST['captions'] as $index => $caption): ?> <input type="hidden" name="captions[<?= $index ?>]" value="<?= htmlspecialchars($caption) ?>"> <?php endforeach; ?> <?php endif; ?> <?php if (isset($_POST['durations'])): ?> <?php foreach ($_POST['durations'] as $index => $duration): ?> <input type="hidden" name="durations[<?= $index ?>]" value="<?= htmlspecialchars($duration) ?>"> <?php endforeach; ?> <?php endif; ?> <!-- Re-include image files would require storing them temporarily, so this form is mainly for demonstration. In practice, you'd need to modify the main form to include the audio upload option --> <div class="form-group"> <label for="additional_audio">Upload Audio File (MP3, WAV, OGG, M4A):</label> <input type="file" class="form-control" id="additional_audio" name="additional_audio" accept=".mp3,.wav,.ogg,.m4a,audio/*"> </div> <div class="form-group"> <label for="audio_order">Audio Order:</label> <select class="form-control" id="audio_order" name="audio_order"> <option value="tts_first">Text-to-Speech first, then uploaded audio</option> <option value="uploaded_first">Uploaded audio first, then Text-to-Speech</option> </select> </div> <button type="submit" class="btn btn-success">Regenerate with Additional Audio</button> </form> </div> </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'); if (video && audio) { // Play both video and audio video.play(); audio.play(); } } </script> </html>