16 lines
822 B
PHP
16 lines
822 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
$name = 'video-'.date('Ymd-His').'.mp4';
|
|
$out = "/var/www/html/generated/$name";
|
|
$ss = glob('/var/www/html/screenshots/*.png');
|
|
rsort($ss); $ss = array_slice($ss, 0, 10);
|
|
if (count($ss) < 2) { echo json_encode(['ok'=>false,'error'=>'need 2+ screenshots']); exit; }
|
|
$list = "/tmp/ffmpeg-list-".uniqid().".txt";
|
|
$f = '';
|
|
foreach ($ss as $s) $f .= "file '$s'\nduration 2\n";
|
|
file_put_contents($list, $f);
|
|
$cmd = "ffmpeg -y -f concat -safe 0 -i $list -vf 'scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2' -c:v libx264 -pix_fmt yuv420p -t 20 $out 2>&1 | tail -1";
|
|
$r = trim(shell_exec($cmd));
|
|
$ok = file_exists($out) && filesize($out) > 1000;
|
|
echo json_encode(['ok'=>$ok,'video'=>"/generated/$name",'frames'=>count($ss),'engine'=>'ffmpeg']);
|