From 4807970727010fd6041ba4d3491668989ca6a20e Mon Sep 17 00:00:00 2001 From: Steve Breker Date: Tue, 30 Jun 2026 09:47:01 -0700 Subject: [PATCH] Refactor ffmpeg video thumbnail generation --- lib/model/QubitDigitalObject.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/model/QubitDigitalObject.php b/lib/model/QubitDigitalObject.php index 3caba68034..366fe69ec0 100644 --- a/lib/model/QubitDigitalObject.php +++ b/lib/model/QubitDigitalObject.php @@ -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);