A description of the problem; get the thumbnail and video time length of the FLV video Google has a half-day find can use FFmpeg to get some information about the video, first introduce FFMEPG
Here's a quick look: FFmpeg is a complete solution for recording, converting, and streaming audio and video, a leading audio/video codec class library. The official official version of FFmpeg does not support RMVB and RM formats. But there are a lot of solutions.
The official website of FFmpeg is http://ffmpeg.mplayerhq.hu/.
The Chinese wiki is http://www.ffmpeg.com.cn/, with a lot of information.
㈠ Installation FFMEPG
Operating system: CENTOS6
Find so many installation FFMEPG articles, basically are no comments, need to install so many packages, do not explain what is used, tangled. and install the above steps always problems, and finally have to look for official website, seriously look at, indeed the official information is very easy to use, after must priority crossing network information.
Since FFMEPG natively support the FLV format, that is, there is no need to install what plug-ins only need to install FFMEPG, install FFMEPG There are two ways: ① source package Installation, this does not know how to always error ②yum command installation, CentOS This yum is the best command, hehe
Here are the installation steps:
㈠ Installing the Build environment
#yum install-y automake autoconf libtool gcc gcc-c++
㈡ Installing the required library RPM package to CentOS
RPM-UHV http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Installing modules such as install FFmpeg
Yum-y Install FFmpeg ffmpeg-devel
The installation under CentOS is complete.
Install PHP Support plugin: ffmpeg-php
Installing ffmpeg-php
Cd/usr/local/src
wget http://garr.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.6.0.tbz2
Tar jxvf ffmpeg-php-0.6.0.tbz2
CD ffmpeg-php-0.6.0
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-confi
Make
Make install
Then modify the php.ini file
VI php.ini
Add this sentence to the php.ini file
Extension=ffmpeg.so
And then restart Apache.
/ETC/INIT.D/HTTPD restart
Note wget link that may lapse, estimated to be wall, you can find on the Internet
----------------------------------------------------------------------------------------------------------
But I opened Phpinfo and did not see FFmpeg, do not know how, the official web surface to provide installation method is required to recompile PHP to support the ffmpeg, I am too troublesome, considering that the service is running on CentOS, since CentOS has been able to
Then I'm calling Liunx's shell command using the PHP exec function, which means you don't need to install ffmpeg-php
A reference to the EXEC function of PHP: Using functions such as Exec,system in PHP to call system commands
here are the common commands for getting thumbnails:
Example 1:
Capture a 352x240 size, JPG-formatted image:
Ffmpeg-i test.asf-y-F image2-t 0.001-s 352x240 a.jpg
Example 2:
Convert the first 30 frames of the video into a animated Gif:
Ffmpeg-i test.asf-vframes 30-y-F gif a.gif
Example 3: This is what I need.
Intercept 320*240 thumbnails at the first 8.01 seconds of the video
Ffmpeg-i test.flv-y-F mjpeg-ss 3-t 0.001-s
Example 4:
Convert videos to FLV files (this is most used, and now FLV is basically the standard for network video)
Ffmpeg-i source-s 320x240-b 700k-aspect 4:3-y-f flv dest.flv.
Where: Source: Is the original file name, can be mov,mpeg,avi,wmv various formats, FFMPEG basic support. -S WxH: Specifies the width and height of the video-B: Sets the bitrate of the video-aspect: maintains the video ratio. such as 4:3 or 16:9-y: If the target file exists, overwrite the original target file directly. -F: Specifies the converted file format, here is the FLV format. (In fact, if you do not specify a file format, FFmpeg will also be converted by the file's suffix name). Dest: Conversion of the target file name, and does not necessarily need to be FLV, can be mov,mpeg and other common formats.
Parameter description:
-L License
-H Help
-fromats display available formats, codecs, protocol
-F FMT forced to use format FMT
-I. FileName input file
-Y Overwrite output file
-T duration set record time HH:MM:SS[.XXX] format is also supported
-ss position search to the specified time [-]HH:MM:SS[.XXX] format also supports
S WxH: Specifies the width and height of the video
****************************************************************************
Example 3: The video for FLV format gets the thumbnail at the specified place, remember that the format of-F cast is MJPEG because I want to get a thumbnail of. jpg, there are many articles written on the web that are written ffmpeg-i test.flv-y-F image2-ss 08.010-t 0.001-s 352x240 B.jpg This is a mistake and cannot be output.
Through the screenshot above: we can see the input of the FLV information and output JPG image information, duration is the length of the video required by this article, but I do not know how to get this variable
Here is the code for PHP to invoke the shell command to get the thumbnail image
<?php
EXEC ("/usr/bin/ffmpeg-i/usr/local/apache/htdocs/test.flv-y-F mjpeg-ss 3-t 0.001-s 320x240/usr/local/apache/htdocs/ Test.jpg ", $out, $status);
Print_r ($status);//0 is success 1 is failure
*************************************************
If there are no possible reasons why the picture was generated:
① Write permission is required for the folder where the pictures are generated #chomd 777/usr/local/apache/htdocs
② in php.ini has disable_functions disable PHP call shell command function,
Disable_functions = Proc_open, Popen,exec, System, Shell_exec, PassThru
Workaround: Comment out the disable_functions
#disable_functions = Proc_open, Popen,exec, System, Shell_exec, PassThru
or disable_functions = (remove the Forbidden function)
Save off, turn it on.
Security mode in ③php.ini must be turned off to call the EXEC function
Safe_mode = Off
④ Image time interception is also very important, it is possible that the image is invalid or a black screen
It is recommended to increase the keyframe, usually the first frame is a keyframe, you can use: Vframes: Frame parameter, discard microsecond parameter, keep only time parameter
/usr/bin/ffmpeg-i/usr/local/apache/htdocs/test.flv-y-F mjpeg-ss 3-vframes 1-s 320x240/usr/local/apache/htdocs/test . jpg
****************************************************************************
The above is to solve the method of obtaining thumbnails, I saw someone in the Android development using FFmpeg to get the video thumbnail image of the phone, considering that the bottom of Android is Liunx, should be universal. Here is how to get the length of the video, although duration is required video length, but do not know how to fetch, if someone will, can teach me, kneel beg.
Here's how long it takes to get video using pure PHP:
You search the Internet: PHP gets the FLV video length
Can find a lot of results, but I turned more than 10 pages found the TMD is reproduced, and all can not use, do not know why. This code and weird, you can put the code on the Internet to run, you will find this is not PHP, because the editor does not display syntax highlighting, there is no way I follow the online handwriting on one side of the code, found the error is strange ... Error is also very strange, interested can try, there is no way I decided to search English materials, finally in foreign sites see the code, take a try can. Hahaha or a foreigner's stuff.
The wrong code:
Keyword not highlighted
Here's the correct code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |