This article mainly introduces how to use the FFmpeg interface in php to obtain the video playback duration, bit rate, thumbnail, and creation time, which has some reference value. if you need it, you can understand it. FFmpeg is a video plug-in. we can call the FFmpeg interface to obtain video information, including video playback duration, video bit rate, video thumbnails, and video creation time, this article introduces how php uses the FFmpeg interface to obtain video information. For more information, see.
FFmpeg:
Function getVideoCover ($ file, $ time, $ name) {if (empty ($ time) $ time = '1 '; // The first frame of the first second is intercepted by default $ strlen = strlen ($ file); // $ videoCover = substr ($ file, 0, $ strlen-4 ); // $ videoCoverName = $videoCover.'.jpg '; // name the thumbnail // 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 );}
Fmpeg video playback duration and bit rate
& 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] * 60 + $ arr_duration [2]; // Convert the 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 encoding $ data ['asamplerate'] = $ match [2]; // Audio sampling frequency Rate} 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 obtains 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 );}
The above is all the content of this article. I hope it will help you learn and support PHP.
More php uses the FFmpeg interface to obtain video playback duration, bit rate, thumbnails, and creation time!