ffmreg thinkphp controller obtains audio and video details (acquisition time)

FFmpeg Download: http://ffmpeg.zeranoe.com/builds/
Download and unzip the FFmpeg folder:
Open any disk you want to install, such as disk d. Create a new folder named "ffmpeg", and copy all the contents of the folder generated in the second step to the "ffmpeg" folder.
Setting environment variables
Right click "my computer - > Properties", then click "advanced system settings", pop up the "system properties" window, and finally click the "environment variables" button:
After clicking the "environment variable" button, pop up the "environment variable" window, find and select the "Path" variable, and click Edit:
Add "; d:\ffmpeg\bin" to the original variable value of "Path" variable (Note:; represents the interval and cannot be omitted; d:\ffmpeg\bin represents the bin folder under the installation Path of FFmpeg). Click "OK" all the way.

Open the command prompt window. Enter the command "FFmpeg – version". If the command prompt window returns the version information of FFmpeg, the installation is successful. You can run FFmpeg in any folder in the command prompt line.

 1 $file_name = 'Rear chord - After the rain (Ring tone).mp3';
 2 $arr = $this->getInfo($file_name);//Return audio information
 3 $time_long = gmdate('H:i:s', $arr['seconds']);
 4  
 5 /**
 6  * Get file information
 7  * @access public
 8  * @param  file      $file     File path
 9  * @return array
10  */
11  
12 function getInfo($file)
13 {
14     $command = sprintf('D:/ffmpeg/bin/ffmpeg -i "%s" 2>&1', $file);//Your installation path
15  
16     ob_start();
17     passthru($command);
18     $info = ob_get_contents();
19     ob_end_clean();
20  
21     $data = array();
22     if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) {
23         $data['duration'] = $match[1]; //Play time
24         $arr_duration = explode(':', $match[1]);
25         $data['seconds'] = $arr_duration[0] * 3600 + $arr_duration[1] * 60 + $arr_duration[2]; //Convert playback time to seconds
26         $data['start'] = $match[2]; //start time
27         $data['bitrate'] = $match[3]; //Bit rate(kb)
28     }
29     if (preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $info, $match)) {
30         $data['vcodec'] = $match[1]; //Video encoding format
31         $data['vformat'] = $match[2]; //Video format
32         $data['resolution'] = $match[3]; //Video resolution
33         $arr_resolution = explode('x', $match[3]);
34         $data['width'] = $arr_resolution[0];
35         $data['height'] = $arr_resolution[1];
36     }
37     if (preg_match("/Audio: (\w*), (\d*) Hz/", $info, $match)) {
38         $data['acodec'] = $match[1]; //Audio coding
39         $data['asamplerate'] = $match[2]; //Audio sampling frequency
40     }
41     if (isset($data['seconds']) && isset($data['start'])) {
42         $data['play_time'] = $data['seconds'] + $data['start']; //Actual playback time
43     }
44     $data['size'] = filesize($file); //file size
45     return $data;
46 }

 

The copyright of this article belongs to the author and the blog park. You are welcome to reprint it. However, without the consent of the author, you must keep this statement and link the original text in an obvious position on the page of the article. Otherwise, you are entitled to pursue legal liability.


Keywords: PHP encoding

Added by BradZynda on Tue, 10 Dec 2019 21:03:40 +0200