php learner
php learner

Reputation: 251

How can we track a video file duration in PHP

Hi I need to save video file duration. when it is uploaded. How can I do that in PHP.

Upvotes: 0

Views: 562

Answers (2)

halfdan
halfdan

Reputation: 34244

Copy/Paste from a script I wrote a while ago:

$videofile="/var/video/user_video.avi";
ob_start();
passthru("/usr/bin/ffmpeg -i \"{$videofile}\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();

$search='/Duration: (.*?),/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);

echo $matches[1][0];

Upvotes: 6

Fenton
Fenton

Reputation: 251242

If the information is available in the extended information (such as id3 tags) you can use the id3 library to get the information...

http://getid3.sourceforge.net/

It also enables you to get the height and width of the video.

Upvotes: 0

Related Questions