Skip to content

Commit 0ce7573

Browse files
committed
* Added getFileInfo to extract information about the video/audio file
1 parent 7496e09 commit 0ce7573

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
// The path to the ffmpeg binary
2929
"ffmpegPath" => "/usr/bin/ffmpeg",
3030

31+
// The path to the ffprobe binary
32+
"ffprobePath" => "/usr/bin/ffprobe",
33+
34+
// The options to use for ffprobe
35+
"ffprobeOptions" => "-v quiet -print_format json -show_format -show_streams",
36+
3137
// The path where the transcoded videos are stored
3238
"transcoderPath" => $_SERVER['DOCUMENT_ROOT'] . "/transcoder/",
3339

src/services/Transcoder.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
174174
if (file_exists($destThumbnailPath)) {
175175
$result = Craft::$app->config->get("transcoderUrl", "transcoder").$destThumbnailFile;
176176
} else {
177-
$pid = shell_exec($ffmpegCmd);
177+
$shellOutput = shell_exec($ffmpegCmd);
178178
Craft::info($ffmpegCmd, __METHOD__);
179179
$result = Craft::$app->config->get("transcoderUrl", "transcoder").$destThumbnailFile;
180180
}
@@ -183,6 +183,36 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
183183
return $result;
184184
}
185185

186+
/**
187+
* Extract information from a video
188+
*
189+
* @param $filePath
190+
*
191+
* @return array
192+
*/
193+
public function getFileInfo($filePath): array
194+
{
195+
196+
$result = null;
197+
$filePath = $this->getAssetPath($filePath);
198+
199+
if (file_exists($filePath)) {
200+
// Build the basic command for ffprobe
201+
$ffprobeOptions = Craft::$app->config->get("ffprobeOptions", "transcoder");
202+
$ffprobeCmd = Craft::$app->config->get("ffprobePath", "transcoder")
203+
.' '.$ffprobeOptions
204+
.' '.escapeshellarg($filePath);
205+
206+
$shellOutput = shell_exec($ffprobeCmd);
207+
Craft::info($ffprobeCmd, __METHOD__);
208+
$result = json_decode($shellOutput, true);
209+
Craft::info(print_r($result, true), __METHOD__);
210+
Craft::dd($result);
211+
}
212+
213+
return $result;
214+
}
215+
186216
/**
187217
* Extract a file system path if $filePath is an Asset object
188218
*

src/variables/TranscoderVariable.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string
5757
return $result;
5858
}
5959

60+
/**
61+
* Extract information from a video/audio file
62+
*
63+
* @param $filePath
64+
*
65+
* @return array
66+
*/
67+
public function getFileInfo($filePath): array
68+
{
69+
$result = Transcoder::$plugin->transcoder->getFileInfo($filePath);
70+
71+
return $result;
72+
}
73+
6074
/**
6175
* Get a download URL
6276
*

0 commit comments

Comments
 (0)