Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the duration of the video uploaded?

i'm using ffmpeg to convert videos to desired formats and to generate the thumbnails..

I want to find the total duration of the video to display in the main page along with the thumbnails..

Can i use ffmpeg to find the duration when its being uploaded and store them on the database.?

Is storing the duration in db is necessary or else is there any other method?

like image 780
Vijay Avatar asked Nov 05 '22 12:11

Vijay


1 Answers

Take a look at this: How To Get Video Duration With FFMPEG and PHP

Down a few replies in that page there is a snippet of code that seems to work for a certain user. I must admit I haven't tested it so it's entirely up to you:

$videofile="/var/video/user_videos/partofvideo.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);
//TEST ECHO
echo $matches[1][0];

Hope it helps

like image 153
Juan Cortés Avatar answered Nov 11 '22 04:11

Juan Cortés