Use FFMPEG in PHP to obtain video thumbnails and total video duration _ php instance

Source: Internet
Author: User
This article describes how to use FFMPEG in PHP to obtain video thumbnails and video durations. For more information, see 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
);
}

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.