Determining Video Metadata: Duration, Dimensions, and Size in PHP
This article provides guidance on retrieving the duration, dimensions, and size of uploaded video files in PHP, regardless of their format.
Solution:
To obtain video metadata in PHP, leverage the getID3 library. This library provides extensive support for video formats. Following is a code example:
<code class="php">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 />");</code>
Note: Ensure that the getID3 library is included before using the above code.
Alternative:
If you have server access, consider using the ffmpeg-php PHP extension. This extension provides more robust video processing capabilities. See: http://ffmpeg-php.sourceforge.net/.
The above is the detailed content of How to Retrieve Video Metadata in PHP: Duration, Dimensions, and Size?. For more information, please follow other related articles on the PHP Chinese website!