PHP + FFMPEG automatic Transcoding of H264 standard Mp4 files

Source: Internet
Author: User
Tags form post
Www. fire-rain.comblogFFMPEG_H264_MP4PHP + FFMPEG automatic transcoding H264 standard Mp4 File recently made an online teaching network project, need to upload any format of video automatic h264 standard video, using html5 playback. Finally, PHP + FFMPEG is used for implementation. Here we will share our detailed solutions with you! Configure ph

Http://www.fire-rain.com/blog/FFMPEG_H264_MP4 PHP + FFMPEG automatic transcoding H264 standard Mp4 File recently made an online teaching network project, need to upload any format of video automatic h264 standard video, using html5 playback. Finally, PHP + FFMPEG is used for implementation. Here we will share our detailed solutions with you! Configure ph

Link: http://www.fire-rain.com/blog/FFMPEG_H264_MP4

PHP + FFMPEG automatic Transcoding of H264 standard Mp4 files

Recently, I am working on an online tutorial Network project. I need to upload videos in any format to automatically play h264 standard videos using html5. Finally, PHP + FFMPEG is used for implementation. Here we will share our detailed solutions with you!

Configuration php.iniFile
File_uploads = on; // whether to allow file upload over HTTP. The default value is ON, which is the place where the upload_tmp_dir; // file is uploaded to the server for storing temporary files. If this value is not specified, the system will use the default Temporary Folder upload_max_filesize = 1024 m; // wangwen business, that is, the maximum file size that can be uploaded. The default value is 2 M. We set it to 1Gpost_max_size = 1024 m; // it refers to the maximum value that can be received by PHP through form POST. We also set it to 1Gmax_execution_time = 3600; // The maximum time (in seconds) for running each PHP page. The default value is 30 seconds. It is set to one hour because the transcoding time is long. Max_input_time = 36000; // maximum time required for receiving data on each PHP page. The default value is 60 seconds. memory_limit = 8 m. // The maximum memory size consumed by each PHP page. The default value is 8 M.
File Upload plugin

Flame rain is recommendeduploadify,UploadifyYesJQueryTo display the progress. The plug-in is easy to install, Which is skipped here.
However, you need to note that non-ie browserssessionWill be lost. I checked a lot of information. The final reason is:

BecauseuploadifyThe flash client is used. The useragent generated by the flash client is different from the user-agent of the browser.

Final Solution:

// Add the session parameter to the upmodify upload parameter, as shown in the following code: scriptData: {"SESSION_ID": ""}, // Add the following code to the server receiving page: if (@ $ _ REQUEST ['session _ id'] & ($ session_id = $ _ REQUEST ['session _ id'])! = Session_id () {session_destroy (); session_id ($ session_id); @ session_start ();}

This solves the problem that FLASH cannot pass pages correctly.

Video Format Conversion

Currently, FFMPEG is a popular video format conversion software in Linux. FFMPEG is a complete solution for recording, conversion, and streaming audio and video. It is a set of leading Audio/Video Codec class libraries. In addition to FFMPEG, an extension is required to transcode to H264 format. (All software packages are provided at the end of the article)

Install the h264 extension with the source code in centos 5.4

Tar-xjvf x264-snapshot-20120718-2245-stable.tar.bz2 # enter the decompressed source file directory cd x264-snapshot-20120718-2245-stable /. /configure -- prefix =/usr/local -- enable-shared make install // install source code in centos 5.4 environment install ffmpeg with h264 extension tar-xjvf ffmpeg-2.1.1.tar.bz2 // enter the directory cd after decompression ffmpeg-2.1.1. /configure -- enable-gpl -- enable-libx264 make install // reload the configuration lcfonfig // test whether the installation is successful ffmpeg

If you see the following content, the installation is successful:

 ffmpeg version 2.1.1 Copyright (c) 2000-2013 the FFmpeg developers built on Dec 17 2013 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 calls ffmpeg to transcode the video
 $cmd = 'FFMPEG  -i  uploadfile/video/test.wmv -c:v libx264 -strict -2 uploadfile/mp4/test.mp4'; exec($cmd, $status);

Before running the command, make sure that the exec function is enabled. Otherwise, modify the php. ini file.

The FFMPEG + H264 extension + YASM + apache_mod_h264 is attached.

Original article address: PHP + FFMPEG automatic Transcoding of H264 standard Mp4 files, thanks to the original author for sharing.

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.