Get Duration/length of a video file using FFMpeg

Vipin 0 Response

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

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

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

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.


$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


FFMpeg, Video Streaming
No Tags Found

Leave a Response