FFMPEG and ffmpeg-php

From Wiki
Jump to: navigation, search

There are packages available for ffmpeg however ffpmeg-php must be built from source.

ffmpeg install

FFMPEG packages are available via rpmfusion.org.

yum install epel-release
yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm
 yum install ffmpeg ffmpeg-devel

ffmpeg-php install

Check out source code and compile it.

cd /usr/local/src
git clone https://github.com/tony2001/ffmpeg-php.git
cd ffmpeg-php
phpize
./configure
make && make install

If you want an older version of ffmpeg-php you can also install it as follows.

cd /usr/local/src
wget -O - http://watters.ws/rpms/ffmpeg/ffmpeg-php-0.6.0.tbz2 | tar xjvf - 
cd ffmpeg-php-0.6.0
phpize
./configure
sed -i -e "s/PIX_FMT_RGBA32/PIX_FMT_RGB32/" ffmpeg_frame.c
make
make install

Enable extension for PHP:

echo "extension=ffmpeg.so" >> /usr/local/lib/php.ini 

Make sure that the extension is loaded.

php -i | grep -i ffmpeg

You should see output similar to this:

ffmpeg
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => Aug 11 2014 20:13:01
ffmpeg-php gd support  => enabled
ffmpeg libavcodec version => Lavc52.72.2
ffmpeg libavformat version => Lavf52.64.2
ffmpeg swscaler version => SwS0.11.0
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0

Finally, restart apache:

/etc/init.d/httpd restart

ffmpeg test script

<?php
/**
 * FFMPEG-PHP Test Script
 *
 * Special thanks to http://www.sajithmr.me/ffmpeg-sample-code for this code example!
 * See the tutorial at http://myownhomeserver.com on how to install ffmpeg-php.
 */
// Check if the ffmpeg-php extension is loaded first
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');

// Determine the full path for our video
$vid = realpath('vid.mp4');

// Create the ffmpeg instance and then display the information about the video clip.
$ffmpegInstance = new ffmpeg_movie($vid);
echo "getDuration: " . $ffmpegInstance->getDuration() . "<br />".
"getFrameCount: " . $ffmpegInstance->getFrameCount() . "<br />".
"getFrameRate: " . $ffmpegInstance->getFrameRate() . "<br />".
"getFilename: " . $ffmpegInstance->getFilename() . "<br />".
"getComment: " . $ffmpegInstance->getComment() . "<br />".
"getTitle: " . $ffmpegInstance->getTitle() . "<br />".
"getAuthor: " . $ffmpegInstance->getAuthor() . "<br />".
"getCopyright: " . $ffmpegInstance->getCopyright() . "<br />".
"getArtist: " . $ffmpegInstance->getArtist() . "<br />".
"getGenre: " . $ffmpegInstance->getGenre() . "<br />".
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() . "<br />".
"getYear: " . $ffmpegInstance->getYear() . "<br />".
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() . "<br />".
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() . "<br />".
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() . "<br />".
"getBitRate: " . $ffmpegInstance->getBitRate() . "<br />".
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() . "<br />".
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() . "<br />".
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() . "<br />".
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() . "<br />".
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() . "<br />".
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() . "<br />".
"hasAudio: " . $ffmpegInstance->hasAudio();

?>

Links

http://rpmfusion.org/Configuration