@@ -86,11 +86,13 @@ class Transcode extends Component
8686 *
8787 * @param $filePath string path to the original video -OR- an Asset
8888 * @param $videoOptions array of options for the video
89+ * @param bool $generate whether the video should be encoded
8990 *
9091 * @return string URL of the transcoded video or ""
9192 */
92- public function getVideoUrl ($ filePath , $ videoOptions ): string
93+ public function getVideoUrl ($ filePath , $ videoOptions, $ generate = true ): string
9394 {
95+
9496 $ result = '' ;
9597 $ settings = Transcoder::$ plugin ->getSettings ();
9698 $ filePath = $ this ->getAssetPath ($ filePath );
@@ -190,6 +192,10 @@ public function getVideoUrl($filePath, $videoOptions): string
190192 if (file_exists ($ destVideoPath ) && (@filemtime ($ destVideoPath ) >= @filemtime ($ filePath ))) {
191193 $ url = $ settings ['transcoderUrls ' ]['video ' ] ?? $ settings ['transcoderUrls ' ]['default ' ];
192194 $ result = Craft::getAlias ($ url ).$ destVideoFile ;
195+
196+ // skip encoding
197+ } elseif (!$ generate ) {
198+ $ result = "" ;
193199 } else {
194200 // Kick off the transcoding
195201 $ pid = $ this ->executeShellCommand ($ ffmpegCmd );
@@ -266,6 +272,12 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t
266272 /** @noinspection PhpUnusedLocalVariableInspection */
267273 $ shellOutput = $ this ->executeShellCommand ($ ffmpegCmd );
268274 Craft::info ($ ffmpegCmd , __METHOD__ );
275+
276+ // if ffmpeg fails which we can't check because the process is ran in the background
277+ // dont return the future path of the image or else we can't check this in the front end
278+
279+ return false ;
280+
269281 } else {
270282 Craft::info ('Thumbnail does not exist, but not asked to generate it: ' .$ filePath , __METHOD__ );
271283
0 commit comments