PHP uses the FFmpeg interface to get video playback length, bitrate, thumbnails, and creation time _php instances

Source: Internet
Author: User
Tags explode php define strlen

FFmpeg is a video plug-in, we can use the call FFmpeg interface to get information about the video, including video playback time, video code rate, video thumbnail and video creation time, this article to you how to use the FFmpeg interface to get video information, A friend in Need can refer to it.

FFmpeg 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. " </br> ";
   $result = System ($STR);
   }

Fmpeg read video playback time length and bit rate

<?php define (' 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 ];
    Play time $arr _duration = explode (': ', $match [1]); $data [' seconds '] = $arr _duration[0] * 3600 + $arr _duration[1] * + $arr _duration[2]; Convert playback time to seconds $data [' start '] = $match [2]; Start time $data [' bitrate '] = $match [3]; Bit rate (KB)} if (Preg_match ()/video: (. *?), (. *?), (. *?) [, \s]/", $info, $match)) {$data [' vcodec '] = $match [1];//video encoding format $data [' vformat '] = $match [2];//video Format $data [' R Esolution '] = $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 '); Print_r ($video _info);?>

Fmpeg The total length of the video file and the time it was created

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
   );
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.