PHP uses the FFmpeg interface to get video playback duration, bitrate, thumbnails, and creation time

Source: Internet
Author: User
FFmpeg is a video plug-in, we can use the call FFmpeg interface to obtain information about the video, including video playback length, video bitrate, video thumbnail and video creation time, this article introduces how PHP uses FFmpeg interface to obtain video information, You need a friend to refer to.

FFmpeg get thumbnail images of video files:

function Getvideocover ($file, $time, $name) {   if (empty ($time)) $time = ' 1 ';//default intercept first Second first 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". $name. ", $out, $status);   $str = "Ffmpeg-i". $file. "-y-f mjpeg-ss 3-t". $time. "-S". $name;   echo $str. " </br> ";   $result = System ($STR);   }

Fmpeg read video playback duration and bitrate

<?phpdefine (' Ffmpeg_path ', '/usr/local/ffmpeg2/bin/ffmpeg-i '%s ' 2>&1 ');     function Getvideoinfo ($file) {$command = sprintf (Ffmpeg_path, $file);  Ob_start ();  PassThru ($command);  $info = Ob_get_contents ();     Ob_end_clean ();  $data = Array (); if (Preg_match ("/duration: (. *), Start: (. *?), bitrate: (\d*) kb\/s/", $info, $match)) {$data [' Duration '] = $match [1] ; Playback time $arr _duration = explode (': ', $match [1]); $data [' seconds '] = $arr _duration[0] * 3600 + $arr _duration[1] * + $ar R_DURATION[2]; Convert playback time to seconds $data [' start '] = $match [2]; Start time $data [' bitrate '] = $match [3]; Bitrate (KB)} if (Preg_match ("/video:"), (. *?), (. *?), (. *?) [, \s]/", $info, $match)) {$data [' vcodec '] = $match [1];//video encoding format $data [' vformat '] = $match [2];//video Format $data [' Reso Lution '] = $match [3];    Video resolution $arr _resolution = Explode (' x ', $match [3]);    $data [' width '] = $arr _resolution[0];  $data [' height '] = $arr _resolution[1]; } if (Preg_match ("/audio: (\w*), (\d*) hz/", $info, $maTCH) {$data [' acodec '] = $match [1];//audio encoding $data [' asamplerate '] = $match [2];//audio sampling frequency} if (Isset ($data [' seconds ' ]) && isset ($data [' Start ']) {$data [' play_time '] = $data [' seconds '] + $data [' start '];//actual playback time} $data [' Size '] = filesize ($file);  File size return $data;} Usage $video_info = getvideoinfo (' video.mp4 ');p rint_r ($video _info);? >

Fmpeg get 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 Seconds   return array (' vtime ' = > $vtime,   ' ctime ' = $ctime   );}

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.

Related Article

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.