Skip to content

Commit 78c2995

Browse files
author
Arjan Brinkman
committed
- Added an optional generate parameter for video encoding
- Return value for thumbnail encoding set to false when ffmpeg is fired, see code description for more info
1 parent 08fdc1e commit 78c2995

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/services/Transcode.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/variables/TranscoderVariable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ class TranscoderVariable extends ManifestVariable
3030
*
3131
* @param $filePath
3232
* @param $videoOptions
33+
* @bool $generate
3334
*
3435
* @return string
3536
*/
36-
public function getVideoUrl($filePath, $videoOptions): string
37+
public function getVideoUrl($filePath, $videoOptions, $generate = true): string
3738
{
38-
return Transcoder::$plugin->transcode->getVideoUrl($filePath, $videoOptions);
39+
return Transcoder::$plugin->transcode->getVideoUrl($filePath, $videoOptions, $generate);
3940
}
4041

4142
/**

0 commit comments

Comments
 (0)