Back to Top

Get Duration/length of a video file using FFMpeg

Updated 20 October 2012

If u are making a video site, the duration/length of the video file is very impotent factor caz thumbnail generation is totally based on the length of the video .I am using FFMPEG and linux shell script to get the duration of the video
code:
****

#/bin/sh
ffmpeg -i inputfile 2>&1 | grep Duration | 
cut -d ' ' -f 4 | sed s/,//

The output of this video file is 00:00:12.00.

explanation:
***********
what i am doing here is very simple (if you are a newbie in linux arena dont bother )
ffmpeg -i input file gives the input values of the file and i am using pipes to transfer the information and after that grep and streame editor(SED) plz refer this site for further reference

Linux shell programming 

if you want to use this data to your PHP file you can easily use it with exec() e.g.

Start your headless eCommerce
now.
Find out More

PHP CODE
————

$file=sample.avi;
$time = exec("$ffmpeg -i /path/".$file." 2>&1 | 
grep Duration | cut -d ' ' -f 4 | sed s/,//");
echo $time;

so cheers with FFMPEG and if stuck anywhere drop a mail in my mailbox

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home