AutorÃa | Ultima modificación | Ver Log |
<?php
namespace LeadersLinked\Library;
class Video
{
public static function extractPoster($source_filename, $target_filename)
{
try {
$cmd = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration $source_filename";
$response = trim(shell_exec($cmd));
$source_duration = 0;
$lines = explode("\n", $response);
foreach ($lines as $line) {
$line = trim(strtolower($line));
if (strpos($line, 'duration') !== false) {
$values = explode('=', $line);
$source_duration = intval(str_replace($values[1], '#', ''), 10);
}
}
if ($source_duration == 0) {
$second_extract = '00:00:02';
} else {
if ($source_duration > 10) {
$second_extract = '00:00:10';
} else {
$second_extract = '00:00:02';
}
}
$cmd = "/usr/bin/ffmpeg -y -i $source_filename -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y $target_filename";
exec($cmd);
return true;
}
catch (\Throwable $e)
{
return false;
}
}
}