Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/model/QubitDigitalObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2928,16 +2928,26 @@ public static function convertVideoToThumbnail($originalPath, $newPath, $width =

// Get the duration of the video and calculate the position of its thumbnail at 50%
$thumbnailPosition = 0;
$command = "ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 {$originalPath}";
$command = sprintf(
'ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %s',
escapeshellarg($originalPath),
);
exec($command, $output, $status);

if (0 === $status && is_array($output) && 1 === count($output)) {
// ffprobe outputs duration as SS.MICROSECONDS
$thumbnailPosition = intval(floatval($output[0]) / 2);
}

// Do conversion to jpeg
$command = "ffmpeg -y -ss {$thumbnailPosition} -i {$originalPath} -vframes 1 -vf \"scale='min({$width},iw):-1'\" {$newPath}";
exec($command.' 2>&1', $output, $status);
$command = sprintf(
'ffmpeg -y -ss %d -i %s -vframes 1 -vf "scale=\'min(%d,iw):-1\'" %s 2>&1',
$thumbnailPosition,
escapeshellarg($originalPath),
$width,
escapeshellarg($newPath),
);
exec($command, $output, $status);

chmod($newPath, 0644);

Expand Down
Loading