Ffmpeg - extract thumbnail from middle of clip
Hey. I am using the following ffmpeg command to fetch a thumbnail from the beginning of a clip using ffmpeg:
/usr/local/bin/ffmpeg -ss 00:00:1 -i $fileName.flv -s 150x100 -vframes 1 $fileName.jpg
Is it possible to extract a thumbnail from the middle of the duration of clips using ffmpeg only?
Each clip has a different length.
If ffmpeg does not provide this option, I know that it is possible to get the duration of clips in this type of 00: 00: 01.26 format, and then I suppose that I can split it in half, but I am not sure if this is the best approach, and I also (embarrassed to say) not really sure how to split this format in half with PHP.
Sample code would be appreciated.
Thank.
source to share
You can get the middle like this:
<?php
// get duration
$time = exec("/local/bin/ffmpeg -i $fileName.flv 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
// duration in seconds; half the duration = middle
$duration = explode(":",$time);
$durationInSeconds = $duration[0]*3600 + $duration[1]*60+ round($duration[2]);
$durationMiddle = $durationInSeconds/2;
// recalculte to minutes and seconds
$minutes = $durationMiddle/60;
$realMinutes = floor($minutes);
$realSeconds = round(($minutes-$real_minutes)*60);
?>
And then use your command with $realMinutes
and $realSeconds
:
/usr/local/bin/ffmpeg -ss $realMinutes:$realSeconds:1 -i $fileName.flv -s 150x100 -vframes 1 $fileName.jpg
source to share