284 lines
8.5 KiB
PHP
284 lines
8.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$user = $_SESSION['user'];
|
|
$error = null;
|
|
$success = null;
|
|
|
|
// Check for ffmpeg
|
|
$ffmpeg_path = 'ffmpeg'; // or provide full path
|
|
$ffmpeg_check = shell_exec("command -v $ffmpeg_path");
|
|
|
|
if (empty($ffmpeg_check)) {
|
|
$error = "Error: ffmpeg is not installed or not in the system\'s PATH. Video generation is disabled.";
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($error)) {
|
|
$title = $_POST['title'] ?? 'Untitled Video';
|
|
$images = $_FILES['images'] ?? [];
|
|
|
|
$userVideosDir = '/home/blari/executor/workspace/users_data/' . session_id() . '/videos';
|
|
if (!is_dir($userVideosDir)) {
|
|
mkdir($userVideosDir, 0777, true);
|
|
}
|
|
|
|
$uploaded_files = [];
|
|
if (!empty($images)) {
|
|
for ($i = 0; $i < count($images['name']); $i++) {
|
|
if ($images['error'][$i] === UPLOAD_ERR_OK) {
|
|
$tmp_name = $images['tmp_name'][$i];
|
|
$name = basename($images['name'][$i]);
|
|
$upload_path = '/tmp/' . uniqid() . '-' . $name;
|
|
move_uploaded_file($tmp_name, $upload_path);
|
|
$uploaded_files[] = $upload_path;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (count($uploaded_files) > 0) {
|
|
$filename = preg_replace('/[^a-zA-Z0-9_\-]/ ', '_', strtolower($title)) . '_' . time() . '.mp4';
|
|
$outputPath = $userVideosDir . '/' . $filename;
|
|
|
|
// Create a text file for ffmpeg input
|
|
$list_file_path = '/tmp/ffmpeg_list_' . uniqid() . '.txt';
|
|
$list_content = "";
|
|
foreach ($uploaded_files as $file) {
|
|
$list_content .= "file '" . $file . "'\n";
|
|
$list_content .= "duration 3\n"; // Each image shows for 3 seconds
|
|
}
|
|
file_put_contents($list_file_path, $list_content);
|
|
|
|
// FFmpeg command
|
|
$cmd = "$ffmpeg_path -f concat -safe 0 -i $list_file_path -c:v libx264 -r 30 -pix_fmt yuv420p $outputPath 2>&1";
|
|
|
|
$output = shell_exec($cmd);
|
|
|
|
if (file_exists($outputPath)) {
|
|
$success = "Video generated successfully! <a href='video-library.php'>View Video Library</a>";
|
|
} else {
|
|
$error = "Error generating video. Please check server logs. FFmpeg output: <pre>$output</pre>";
|
|
}
|
|
|
|
// Clean up temporary files
|
|
unlink($list_file_path);
|
|
foreach ($uploaded_files as $file) {
|
|
unlink($file);
|
|
}
|
|
} else {
|
|
$error = "Please upload at least one image to generate a video.";
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Video Generator - Digital Marketing Suite</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--bg-color: #f8f9fa;
|
|
--sidebar-bg: #ffffff;
|
|
--text-color: #343a40;
|
|
--heading-color: #212529;
|
|
--primary-color: #007bff;
|
|
--border-color: #dee2e6;
|
|
--card-bg: #ffffff;
|
|
--shadow: 0 0 15px rgba(0, 0, 0, 0.05);
|
|
}
|
|
body {
|
|
margin: 0;
|
|
font-family: 'Inter', sans-serif;
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
display: flex;
|
|
}
|
|
.sidebar {
|
|
width: 260px;
|
|
background-color: var(--sidebar-bg);
|
|
border-right: 1px solid var(--border-color);
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
position: fixed;
|
|
box-shadow: var(--shadow);
|
|
}
|
|
.sidebar-header {
|
|
padding: 1.5rem;
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
color: var(--primary-color);
|
|
border-bottom: 1px solid var(--border-color);
|
|
text-align: center;
|
|
}
|
|
.sidebar-nav {
|
|
flex-grow: 1;
|
|
list-style: none;
|
|
padding: 1rem 0;
|
|
margin: 0;
|
|
}
|
|
.sidebar-nav a {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 1rem 1.5rem;
|
|
text-decoration: none;
|
|
color: var(--text-color);
|
|
font-weight: 500;
|
|
transition: background-color 0.2s, color 0.2s;
|
|
border-left: 3px solid transparent;
|
|
}
|
|
.sidebar-nav a:hover, .sidebar-nav a.active {
|
|
background-color: #e9ecef;
|
|
color: var(--primary-color);
|
|
border-left-color: var(--primary-color);
|
|
}
|
|
.sidebar-footer {
|
|
padding: 1.5rem;
|
|
border-top: 1px solid var(--border-color);
|
|
}
|
|
.logout-btn {
|
|
display: block;
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border: none;
|
|
border-radius: 8px;
|
|
background: var(--primary-color);
|
|
color: #ffffff;
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
text-align: center;
|
|
text-decoration: none;
|
|
transition: background-color 0.2s;
|
|
}
|
|
.logout-btn:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
.main-content {
|
|
margin-left: 260px;
|
|
flex-grow: 1;
|
|
padding: 3rem;
|
|
}
|
|
h1 {
|
|
font-size: 2.2rem;
|
|
font-weight: 700;
|
|
color: var(--heading-color);
|
|
margin-bottom: 2rem;
|
|
}
|
|
.generator-form {
|
|
background-color: var(--card-bg);
|
|
border-radius: 12px;
|
|
padding: 2.5rem;
|
|
border: 1px solid var(--border-color);
|
|
box-shadow: var(--shadow);
|
|
max-width: 700px;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
font-weight: 500;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.form-group input, .form-group textarea, .form-group select {
|
|
width: 100%;
|
|
padding: 0.8rem;
|
|
border-radius: 8px;
|
|
border: 1px solid var(--border-color);
|
|
font-size: 1rem;
|
|
transition: border-color 0.2s, box-shadow 0.2s;
|
|
}
|
|
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
|
|
outline: none;
|
|
border-color: var(--primary-color);
|
|
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
|
|
}
|
|
.submit-btn {
|
|
display: inline-block;
|
|
padding: 0.8rem 1.5rem;
|
|
border: none;
|
|
border-radius: 8px;
|
|
background-color: var(--primary-color);
|
|
color: #ffffff;
|
|
font-size: 1rem;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s;
|
|
}
|
|
.submit-btn:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
.message {
|
|
padding: 1rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 1.5rem;
|
|
font-weight: 500;
|
|
}
|
|
.message.success {
|
|
background-color: #d4edda;
|
|
color: #155724;
|
|
border: 1px solid #c3e6cb;
|
|
}
|
|
.message.error {
|
|
background-color: #f8d7da;
|
|
color: #721c24;
|
|
border: 1px solid #f5c6cb;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="sidebar">
|
|
<div class="sidebar-header">Digital Suite</div>
|
|
<nav class="sidebar-nav">
|
|
<a href="dashboard.php">Dashboard</a>
|
|
<a href="post-generator.php">Post Generator</a>
|
|
<a href="image-library.php">Image Library</a>
|
|
<a href="video-generator.php" class="active">Video Generator</a>
|
|
<a href="video-library.php">Video Library</a>
|
|
<a href="website-builder.php">Website Builder</a>
|
|
<a href="analytics.php">Analytics</a>
|
|
<a href="settings.php">Settings</a>
|
|
</nav>
|
|
<div class="sidebar-footer">
|
|
<a href="?action=logout" class="logout-btn">Logout</a>
|
|
</div>
|
|
</div>
|
|
|
|
<main class="main-content">
|
|
<h1>AI Video Generator</h1>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="message success"><?= $success ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<div class="message error"><?= $error ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form class="generator-form" method="POST" action="video-generator.php" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="title">Video Title</label>
|
|
<input type="text" id="title" name="title" placeholder="e.g., My Awesome Slideshow" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="images">Images</label>
|
|
<input type="file" id="images" name="images[]" accept="image/*" multiple required>
|
|
</div>
|
|
<button type="submit" class="submit-btn" <?php if (!empty($error) && strpos($error, 'ffmpeg') !== false) echo 'disabled'; ?>>Generate Video</button>
|
|
</form>
|
|
</main>
|
|
</body>
|
|
</html>
|