These days to do project, one of the requirements is that the user uploads the video file to the server, and then the server automatically intercepts the video as the corresponding thumbnail image, the server-side language is written in PHP, find a half-day data, found that ffmpeg-php can meet the demand, So here's a quick introduction to the configuration and usage of the extension library.
The test server environment Wampserver Version 2.1,php5.3.5,ffmpeg-php Configuration and usage steps are as follows:
1. Download ffmpeg-php, Ffmpeg-php-5.3-win32-all.zip
2. Place the Php_ffmpeg.dll in the PHP extension directory (e.g. E:\Program files\wamp\bin\php\php5.3.5\ext)
3. Place other DLL files in the system directory (e.g. C:\Windows\System32)
4. Modify PHP.ini, add the Extension=php_ffmpeg.dll configuration item, the result is as follows:
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_ffmpeg.dll
( note : To modify php.ini in the Apache directory (for example, E:\Program Files\wamp\bin\apache\apache2.2.17\bin\php.ini) in the Wamp environment, and to enable GD2 and GetText module)
5. Restart the Apache server
6. Print out the phpinfo to see if the output is as follows, and if so, the ffmpeg-php module is properly configured
Ffmpeg
ffmpeg-php version |
0.6.0-svn |
Ffmpeg-php built on |
SEP 8 2010 12:13:47 |
ffmpeg-php GD Support |
Enabled |
FFmpeg libavcodec Version |
Lavc52.87.4 |
FFmpeg Libavformat Version |
Lavf52.78.3 |
FFmpeg Swscaler Version |
SwS0.11.0 |
Directive |
Local Value |
Master Value |
Ffmpeg.allow_persistent |
0 |
0 |
Ffmpeg.show_warnings |
0 |
0 |
7. Write the test code, the sample code intercepts the second frame of the video as a thumbnail image
1 Public functionTestmp4 ()2 {3 if(extension_loaded(' FFmpeg ')) {//determine if FFmpeg is loaded4 $mov=NewFfmpeg_movie (' E:\\program files\\wamp\\www\\bbshow\\test\\guangfa15s.mp4 ');//the path to the video5Dump$mov);6 $ff _frame=$mov->getframe (2);7 $GD _image=$ff _frame-togdimage ();8 $img=$_server[' Document_root ']. " /test.jpg ";//to create an absolute path to a picture9Imagejpeg ($GD _image,$img);//creating a JPG imageTenImagedestroy ($GD _image);//destroying an image One}Else{ A Echo"FFmpeg not Loaded"; - } -}
8. Run the test code to generate a JPG thumbnail image on the server side
9. Please refer to the Official API (http://ffmpeg-php.sourceforge.net/doc/api/) for detailed instructions on using the ffmpeg-php.
Use of ffmpeg-php on Windows systems