如何在 PHP 中获取视频时长、尺寸和大小?

2021-12-21 00:00:00 ffmpeg php video duration

我想知道如何在PHP中获取上传视频文件的时长、尺寸和大小.该文件可以是任何视频格式.

I want to know how to get the duration, dimension and size of uploaded video file in PHP. The file can be in any video format.

推荐答案

getID3 支持视频格式.请参阅:http://getid3.sourceforge.net/

getID3 supports video formats. See: http://getid3.sourceforge.net/

所以,在代码格式中,就像:

So, in code format, that'd be like:

include_once('pathto/getid3.php');
$getID3 = new getID3;
$file = $getID3->analyze($filename);
echo("Duration: ".$file['playtime_string'].
" / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
" / Filesize: ".$file['filesize']." bytes<br />");

注意:您必须先包含 getID3 类,然后才能使用!见上面的链接.

Note: You must include the getID3 classes before this will work! See the above link.

如果您有能力修改服务器上的 PHP 安装,那么为此目的的 PHP 扩展是 ffmpeg-php.请参阅:http://ffmpeg-php.sourceforge.net/

If you have the ability to modify the PHP installation on your server, a PHP extension for this purpose is ffmpeg-php. See: http://ffmpeg-php.sourceforge.net/

相关文章