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.