How to Retrieve Video Metadata in PHP
Question:
How can I obtain the duration, dimensions, and size of a video file using PHP, regardless of its format?
Answer:
Php does not natively support the retrieval of video metadata. However, external libraries and PHP extensions can be used for this purpose.
Method 1: Using the getID3 Library
The getID3 library (http://getid3.sourceforge.net/) provides methods for extracting metadata from various video formats. To use it:
<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: Remember to include the getID3 classes before using this code.
Method 2: FFMpeg PHP Extension
If you have root access to your server, you can install the FFMpeg PHP extension (http://ffmpeg-php.sourceforge.net/) to access more extensive video metadata functionality. Consult its documentation for usage.
The above is the detailed content of How to Retrieve Video Metadata in PHP?. For more information, please follow other related articles on the PHP Chinese website!