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! View Video Library"; } else { $error = "Error generating video. Please check server logs. FFmpeg output:
$output"; } // 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."; } } ?>