Retrieving Video Metadata in PHP: Duration, Dimensions, and Size
In PHP, obtaining vital video metadata such as duration, dimensions, and size can be achieved using reliable methods. One recommended option is integrating getID3, a library specifically designed for extracting information from media files.
Using getID3
To utilize getID3, include its PHP classes and instantiate an object to analyze the target video file:
<code class="php">include_once('pathto/getid3.php'); $getID3 = new getID3; $file = $getID3->analyze($filename);</code>
From the analyzed file data, retrieve the desired metadata 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>
Alternative Method: ffmpeg-php
If server modification is permitted, you can install the ffmpeg-php extension. This provides a more specialized PHP interface for accessing ffmpeg's powerful media analysis capabilities.
By leveraging these techniques, you can efficiently extract essential video metadata in PHP, offering valuable insights for your applications.
The above is the detailed content of How to Get Video Metadata (Duration, Dimensions, and Size) in PHP?. For more information, please follow other related articles on the PHP Chinese website!