Convert video to iPhone friendly H264 with FFMPEG
FFMPEG is a cross-platform solution for recording, converting, and steaming audio and video. There is even a PHP module for gathering media information. It typically cannot be installed by using a yum or apt-get repository though.
Many guides exist for installing FFMPEG on multiple platforms. This quick tutorial will be limited to its use on the CentOS platform. One installation guide for CentOS can be found here: http://www.nazly.net/installing-ffmpeg-and-ffmpeg-php-on-centos/
Once you have installed FFMPEG along with its codecs and PHP module you can now access media information from directly inside of your PHP script. A quick example of how to do so is below:
$movie = new ffmpeg_movie('/var/html/www/video/myvideo.mp4'); $width = $movie->getFrameWidth(); $height = $movie->getFrameHeight();
The above example will gather information about the selected movie, assuming the video actually exists. This is just two of the many object methods supported by the ffmpeg-php module, a complete list can be viewed here: http://ffmpeg-php.sourceforge.net/doc/api/ffmpeg_movie.php
Okay! That's nice! But I want to compress an existing video to an iPhone compatible format! This can be done easily through BASH or whatever shell you prefer within the CentOS console or through an SSH session.
/usr/bin/ffmpeg -y -i "/var/html/www/videos/input.flv" -s 320x180 -r 30000/1001 -b 400k -bt 500k -vcodec libx264 -vpre default -acodec libfaac -ac 2 -ar 44100 -ab 128k "/var/html/www/videos/output.mp4";
The above line reads in the input.flv file then outputs the output.mp4 file.
-y overwrite if existing output file is found
-i input file
-s (frame size) 320x180 or 16:9 iPhone format
-r frame rate Hz 29.97 or 30000/1001
-b bitrate or 400kbps
-bt max bitrate of 500kbps
-vcodec video codec of libc264 for h264 format
-vpre video preset file of default
-acodec audio codec of libfaac for aac audio
-ac number of audio channels set to two
-ar for audio sampling frequency of 44100 (For iPhones you could also do 48000)
-ab audio bitrate of 128kbps
A complete list of ffmpeg options can be found here: http://ffmpeg.org/ffmpeg.html
Will add more ffmpeg tricks later!