This article mainly introduces the use of FFmpeg in PHP to get video thumbnails and video total time long examples, the need for friends can refer to the
The code is as follows:
Get thumbnails of video files
function Getvideocover ($file, $time, $name) {
if (empty ($time)) $time = ' 1 ';//default intercept first second frame
$strlen = strlen ($file);
$videoCover = substr ($file, 0, $strlen-4);
$videoCoverName = $videoCover. JPG ';//thumbnail name
EXEC ("Ffmpeg-i". $file. "-y-f mjpeg-ss". $time. "-T 0.001-s 320x240". $name. "", $out, $status);
$str = "Ffmpeg-i". $file. "-y-f mjpeg-ss 3-t". $time. "-S 320x240". $name;
echo $str. "
";
$result = System ($STR);
}
Gets the total length and creation time of the video file
function GetTime ($file) {
$vtime = EXEC ("Ffmpeg-i". $file. " 2>&1 | grep ' Duration ' | Cut-d '-F 4 | sed s/,//");//Total length
$ctime = Date ("y-m-d h:i:s", Filectime ($file));//Creation time
$duration = Explode (":", $time);
$duration _in_seconds = $duration [0]*3600 + $duration [1]*60+ round ($duration [2]);//Convert to second
Return Array (' Vtime ' => $vtime,
' CTime ' => $ctime
);
}
Note : Please pay attention to the triple Programming Tutorials section for more wonderful articles .