Home > Article > Backend Development > How to Get Video Duration, Dimensions, and Size in PHP?
Determining Video Duration, Dimensions, and Size in PHP
Extracting video metadata such as duration, dimensions, and size is a common task when processing video files. This article demonstrates how to accomplish this in PHP.
Utilizing getID3
getID3 is a PHP library that supports video format analysis. To use it:
<code class="php">include_once('pathto/getid3.php'); $getID3 = new getID3; $file = $getID3->analyze($filename);</code>
The extracted metadata can be accessed as follows:
<code class="php">echo("Duration: ".$file['playtime_string']. " / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall". " / Filesize: ".$file['filesize']." bytes<br />");</code>
Employing ffmpeg-php
If server modifications are allowed, install the ffmpeg-php extension:
http://ffmpeg-php.sourceforge.net/
This extension provides a more comprehensive API for video analysis.
The above is the detailed content of How to Get Video Duration, Dimensions, and Size in PHP?. For more information, please follow other related articles on the PHP Chinese website!