mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Add getVideoInfo function to retrieve video metadata
Introduced a new function, getVideoInfo(), that utilizes ffprobe to extract video width, height, and bitrate from a specified file path. The function returns this information in an associative array, enhancing the ability to gather video details programmatically.
This commit is contained in:
parent
4b3056474c
commit
91e2a4263c
1 changed files with 23 additions and 0 deletions
|
@ -768,3 +768,26 @@ function addKeywordToFFmpegCommand(string $command, string $keyword): string
|
|||
// Reconstruct the command
|
||||
return implode(' ', $commandParts);
|
||||
}
|
||||
|
||||
function getVideoInfo($filePath)
|
||||
{
|
||||
$cmd = get_ffprobe() . " -v error -select_streams v:0 -show_entries stream=width,height,bit_rate -of json " . escapeshellarg($filePath);
|
||||
$cmd = removeUserAgentIfNotURL($cmd);
|
||||
$output = shell_exec($cmd);
|
||||
$json = json_decode($output, true);
|
||||
|
||||
$info = [
|
||||
'width' => null,
|
||||
'height' => null,
|
||||
'bitrate' => null
|
||||
];
|
||||
|
||||
if (!empty($json['streams'][0])) {
|
||||
$stream = $json['streams'][0];
|
||||
$info['width'] = $stream['width'] ?? null;
|
||||
$info['height'] = $stream['height'] ?? null;
|
||||
$info['bitrate'] = isset($stream['bit_rate']) ? intval($stream['bit_rate']) : null;
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue