Use FFmpeg in PHP to get video thumbnails and video total time-long instances

Source: Internet
Author: User
Tags strlen

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 .

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.