Home > Backend Development > PHP Tutorial > How to Retrieve Video Metadata in PHP?

How to Retrieve Video Metadata in PHP?

Barbara Streisand
Release: 2024-11-01 17:21:30
Original
530 people have browsed it

How to Retrieve Video Metadata in PHP?

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template