example, FFmpeg read video playback time length and bit rate
The code is as follows:
The code is as follows |
Copy Code |
<?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 [' resolution '] = $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 coding $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); ?> |
In this case, PassThru is used, and some virtual masters may be able to disable this command
Example 2
The code is as follows |
Copy Code |
Get thumbnails of video files function Getvideocover ($file, $time, $name) { if (empty ($time)) $time = ' 1 ';//default intercept first second frame $strlenstrlen = 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 of//cuplayer.com $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]);//cuplayer.com converted to seconds Return Array (' Vtime ' => $vtime, ' CTime ' => $ctime ); } |