Php+ffmpeg implements automatic transcoding of video to H264 standard MP4 file _php instance

Source: Internet
Author: User
Tags form post
Configuring the php.ini file

Copy the Code code as follows:
File_uploads = on;//whether to allow the switch to upload files over HTTP. The default is on, which is open
Upload_tmp_dir;//File upload to the server where temporary files are stored, if not specified, will use 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 1G
Post_max_size = 1024m;//refers to the maximum value that can be received by the form Post to PHP, and we are also set to 1G

Max_execution_time = 3600;//The Maximum time value (in seconds) for each PHP page to run, 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;//MAX 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:
Copy the Code code as follows:
Add the session parameter to the upmodify upload parameter, as follows:
Scriptdata: {"session_id": ""},
Add the following code to the service-side 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
Copy the Code code as follows:
TAR-XJVF x264-snapshot-20120718-2245-stable.tar.bz2
#进入解压后的源文件目录
CD x264-snapshot-20120718-2245-stable/
./configure--prefix=/usr/local--enable-shared
Make
Make install

//centos 5.4 Install the source installation ffmpeg with h264 extension
TAR-XJVF ffmpeg-2.1.1.tar.bz2
//Enter the extracted directory
CD ffmpeg-2.1.1
./co nfigure--ENABLE-GPL--enable-libx264
Make
Make install
//Reload configuration
Lcfonfig
//test installation succeeded
FFmpeg

If you see the following to indicate that the installation was successful:
Copy the Code code as follows:
FFmpeg version 2.1.1 Copyright (c) 2000-2013 the FFmpeg developers
Built on Dec 23:32:40 with GCC 4.4.7 (gcc) 20120313 (Red Hat 4.4.7-3)
Configuration:--enable-libx264--ENABLE-GPL
Libavutil 52. 48.101/52. 48.101
Libavcodec 55. 39.101/55. 39.101
Libavformat 55. 19.104/55. 19.104
Libavdevice 55. 5.100/55. 5.100
Libavfilter 3. 90.100/3. 90.100
Libswscale 2. 5.101/2. 5.101
Libswresample 0. 17.104/0. 17.104
Libpostproc 52. 3.100/52. 3.100
Hyper Fast Audio and Video encoder
usage: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

Copy the Code code as follows:
$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 Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.