Php+ffmpeg implements the automatic transcoding of video into H264 standard MP4 file,
Configuring the php.ini File
File_uploads = on;//whether to allow the switch to upload files over HTTP. The default is on is open upload_tmp_dir;//File upload to the server where temporary files are stored, if not specified will be used the system default temporary folder Upload_max_filesize = 1024m;//Wang Wen Business, that is, the maximum size allowed to upload files. The default is 2M, we set to 1gpost_max_size = 1024m;//refers to the maximum value that can be received by the form Post to PHP, we also set to 1gmax_execution_time = 3600;//maximum time value per PHP page run (in seconds) , the default is 30 seconds, set to one hour, because the subsequent transcoding time is long. Max_input_time = 36000;//The maximum time required for each PHP page to receive data, default 60 seconds Memory_limit = 8m;//maximum memory eaten per PHP page, default 8M
File Upload Plugin
Fire rain recommend that you use Uploadify,uploadify is an upload plugin for jquery that implements a progress display. Plug-ins are easy to install and skip over here.
However, there is a problem to note that non-IE browser session will be lost, looked up a lot of information, the final reason is summarized:
Because the flash client, such as Uploadify, produces a useragent that differs from the user-agent of the browser.
Final Solution:
Add the SESSION parameter to the upmodify upload parameter as follows: Scriptdata: {"session_id": ""},//Add the following code to the server receive page: if (@$_request[' session_id ') & & ($session _id=$_request[' session_id ')!=session_id ()) {Session_destroy (); session_id ($session _id); @session_ Start (); }
This solves the FLASH cannot pass the page correctly
Video format Conversion
Now the more popular video format conversion software under Linux is Ffmpeg,ffmpeg is a complete solution for recording, converting and streaming audio and video, a leading audio/video codec class library. In addition to ffmpeg, we need an extension to transcode to H264 format. (At the end of this article, all package download addresses are given)
Installing the source installation h264 extension in CentOS 5.4 environment
TAR-XJVF x264-snapshot-20120718-2245-stable.tar.bz2 #进入解压后的源文件目录 cd x264-snapshot-20120718-2245-stable/./configure --prefix=/usr/local--enable-shared Makemake Install//centos 5.4 Environment installation source installation ffmpeg with h264 extension TAR-XJVF ffmpeg-2.1.1.tar.bz2//into the unpacked directory CD ffmpeg-2.1.1./configure--ENABLE-GPL--enable-libx264makemake install// Reload configuration Lcfonfig//test is installed successfully ffmpeg
If you see the following to indicate that the installation was successful:
FFmpeg version 2.1.1 Copyright (c) 2000-2013 the FFmpeg developersbuilt on Dec 23:32:40 with GCC 4.4.7 (GCC) 20120 313 (Red Hat 4.4.7-3) configuration:--enable-libx264--enable-gpllibavutil 52. 48.101/52. 48.101libavcodec 55. 39.101/55. 39.101libavformat 55. 19.104/55. 19.104libavdevice 55. 5.100/55. 5.100libavfilter 3. 90.100/3. 90.100libswscale 2. 5.101/2. 5.101libswresample 0. 17.104/0. 17.104libpostproc 52. 3.100/52. 3.100Hyper Fast Audio and Video encoderusage:ffmpeg [options] [[infile Options]-I infile] ... {[outfile options] outfile} ... Use-h to get full help or, even better, run ' man ffmpeg '
PHP Call FFmpeg transcoding video
$cmd = ' ffmpeg-i uploadfile/video/test.wmv-c:v libx264-strict-2 uploadfile/mp4/test.mp4 '; exec ($cmd, $status);
Make sure the EXEC function is turned on before running. Otherwise, modify the php.ini file
Finally attach ffmpeg+h264 extension +yasm+apache_mod_h264
Related articles:
PHP implements a way to turn video into MP4 and get a video preview
PHP uses Memcoder to turn video into MP4 format
PHP download flv file or MP4 file does not play