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

How to Get Video Duration, Dimensions, and Size in PHP?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-30 19:59:03290browse

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!

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