@@ -200,12 +200,14 @@ public function getVideoUrl($filePath, $videoOptions): string
200200 /**
201201 * Returns a URL to a video thumbnail
202202 *
203- * @param $filePath string path to the original video or an Asset
204- * @param $thumbnailOptions array of options for the thumbnail
203+ * @param string $filePath path to the original video or an Asset
204+ * @param array $thumbnailOptions of options for the thumbnail
205+ * @param bool $generate whether the thumbnail should be
206+ * generated if it doesn't exists
205207 *
206- * @return string URL of the video thumbnail
208+ * @return string URL of the video thumbnail
207209 */
208- public function getVideoThumbnailUrl ($ filePath , $ thumbnailOptions ): string
210+ public function getVideoThumbnailUrl ($ filePath , $ thumbnailOptions, $ generate = true ): string
209211 {
210212
211213 $ result = "" ;
@@ -247,7 +249,7 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
247249 $ ffmpegCmd .= ' -f image2 -y ' . escapeshellarg ($ destThumbnailPath ) . ' >/dev/null 2>/dev/null ' ;
248250
249251 // If the thumbnail file already exists, return it. Otherwise, generate it and return it
250- if (!file_exists ($ destThumbnailPath )) {
252+ if (!file_exists ($ destThumbnailPath ) && $ generate ) {
251253 $ shellOutput = $ this ->executeShellCommand ($ ffmpegCmd );
252254 Craft::info ($ ffmpegCmd , __METHOD__ );
253255 }
@@ -481,10 +483,10 @@ public function getAudioFilename($filePath, $audioOptions): string
481483 public function handleGetAssetThumbUrl (GetAssetThumbUrlEvent $ event )
482484 {
483485 $ options = [
484- "width " => $ event ->width ,
486+ "width " => $ event ->width ,
485487 "height " => $ event ->height ,
486488 ];
487- $ thumbUrl = $ this ->getVideoThumbnailUrl ($ event ->asset , $ options );
489+ $ thumbUrl = $ this ->getVideoThumbnailUrl ($ event ->asset , $ options, $ event -> generate );
488490
489491 return empty ($ thumbUrl ) ? null : $ thumbUrl ;
490492 }
0 commit comments