@@ -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 = "" ;
@@ -248,8 +250,14 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
248250
249251 // If the thumbnail file already exists, return it. Otherwise, generate it and return it
250252 if (!file_exists ($ destThumbnailPath )) {
251- $ shellOutput = $ this ->executeShellCommand ($ ffmpegCmd );
252- Craft::info ($ ffmpegCmd , __METHOD__ );
253+ if ($ generate ) {
254+ $ shellOutput = $ this ->executeShellCommand ($ ffmpegCmd );
255+ Craft::info ($ ffmpegCmd , __METHOD__ );
256+ } else {
257+ Craft::info ('Thumbnail does not exist, but not asked to generate it: ' . $ filePath , __METHOD__ );
258+ // The file doesn't exist, and we weren't asked to generate it
259+ return '' ;
260+ }
253261 }
254262 $ result = Craft::getAlias ($ settings ['transcoderUrl ' ]) . $ destThumbnailFile ;
255263 }
@@ -481,10 +489,10 @@ public function getAudioFilename($filePath, $audioOptions): string
481489 public function handleGetAssetThumbUrl (GetAssetThumbUrlEvent $ event )
482490 {
483491 $ options = [
484- "width " => $ event ->width ,
492+ "width " => $ event ->width ,
485493 "height " => $ event ->height ,
486494 ];
487- $ thumbUrl = $ this ->getVideoThumbnailUrl ($ event ->asset , $ options );
495+ $ thumbUrl = $ this ->getVideoThumbnailUrl ($ event ->asset , $ options, $ event -> generate );
488496
489497 return empty ($ thumbUrl ) ? null : $ thumbUrl ;
490498 }
0 commit comments