views:

48

answers:

1

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?

+1  A: 

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

thisMayhem