Hello,
I have an flv file uploaded to a server. I would like to display its duration in the following format "minutes:seconds". Can anybody help me with this ?
Thank you
Hello,
I have an flv file uploaded to a server. I would like to display its duration in the following format "minutes:seconds". Can anybody help me with this ?
Thank you
i am using php and ffmpeg to get duration of the video.
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
}
exec($cmd);
print_r() the $time variable to see. make sure ffmpeg installed on your machine.. hope this will help.
There is also a FFMPEG PHP extension ie. apt-get install php5-ffmpeg then
$movie = new ffmepg_movie("path/to/movie.flv");
$duration_in_seconds = $movie->getDuration();
This has worked for me previously. The extension is good for retrieving meta-data and testing if an uploaded file is an FLV, etc.
I´d use the getID3 PHP library, written in plain old PHP without any dependencies.
It not only gives you the duration of the .flv movie in seconds, but converts it to minute:seconds format already. Here is a code sample with v. 1.7.9 (latest stable version of getid3):
<?php
// getId3 library uses deprecated eregi_* functions
// which generate errors under PHP 5.3 - so I excluded them
error_reporting(E_ALL ^ E_DEPRECATED);
// just for debugging/sample
header('Content-Type: text/plain');
// include the getid3 base class in order to use the lib
require_once('./lib/getid3.php');
// path to your .flv file
$filename = './sample.flv';
$getID3 = new getID3();
$fileInfo = $getID3->analyze($filename);
// echoes something like 127.8743
print 'Playtime in seconds: ' . $fileInfo['playtime_seconds'];
print chr(10);
// echoes something like: 2:07
print 'Playtime in minute:seconds format: ' . $fileInfo['playtime_string'];
Thank you for all your help. I would also like to generate a thumbnail from the flv file. I am currently trying to accomplish this using this code. But I seem to be doing something wrong.
$cmd = "ffmpeg -i /home/web1/wpmu.site.com/htdocs/wp-content/blogs.dir/7/files/2010/10/4973_3.flv -f image2 -vframes 1 -ss 00:00:01 -y -s 100x100 /home/web1/wpmu.site.com/htdocs/wp-content/blogs.dir/7/files/2010/10/4973_3.png";
exec($cmd, $output, $return);
I included it on a test.php page. It should run just by refreshing the page right? I added the path to the png file myself. What can be wrong with this ?
Thanks
Here is my code to grab a frame and generate the image from the video...
// get the duration and a random place within that
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
exec($cmd);
// get the screenshot
exec("ffmpeg -i " . $videoPath . " -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg " . $imageOutput . " 2>&1");
$second variable is random number between 0 and total duration. and the second exec() is to create a image file from selected frame.
$imageOutput is absolute path location to the generated image. eg: /home/ariawan/image-generated.jpg