Use FFMPEG in PHP to obtain video thumbnails and total video length. example _ PHP Tutorial

Source: Internet
Author: User
Use FFMPEG in PHP to obtain video thumbnails and total video duration. The copy code is as follows: get the video file thumbnail functiongetVideoCover ($ file, $ time, $ name) {if (empty ($ time) $ time1; the first frame in the first second is intercepted by default $ strlenstrle The code is as follows:


// Obtain the thumbnail of the video file
Function getVideoCover ($ file, $ time, $ name ){
If (empty ($ time) $ time = '1'; // The first frame of the first second is intercepted by default.
$ Strlen = strlen ($ file );
// $ VideoCover = substr ($ file, 0, $ strlen-4 );
// $ VideoCoverName = $videoCover.'.jpg '; // name the thumbnail.
// 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 );
}

// Obtain 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/, //"); // The 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 seconds
Return array ('vtime' => $ vtime,
'Ctime' => $ ctime
);
}

The http://www.bkjia.com/PHPjc/764621.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/764621.htmlTechArticle code is as follows: // Get the thumbnail function of the video file getVideoCover ($ file, $ time, $ name) {if (empty ($ time) $ time = '1 '; // The first frame of the first second is intercepted by default $ strlen = strle...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.