Home  >  Article  >  Backend Development  >  How to Retrieve Video Metadata in PHP: Duration, Dimensions, and Size?

How to Retrieve Video Metadata in PHP: Duration, Dimensions, and Size?

Barbara Streisand
Barbara StreisandOriginal
2024-10-31 08:13:021011browse

How to Retrieve Video Metadata in PHP: Duration, Dimensions, and Size?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn