1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +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:
Daniel Neto 2025-06-10 11:12:16 -03:00
parent 4b3056474c
commit 91e2a4263c

View file

@ -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;
}