Selasa, 07 Agustus 2012

Install FFMPEG di VPS Kloxo


Install FFMPEG di VPS Kloxo ini adalah dokumentasi pribadi, cara yang aku tulis ini berhasil dengan kasus yang saya hadapi, mungkin saja bakal berbeda dengan kasus lain.

Okay, aku berencana untuk rebuild sebuah VPS (yang sebelumnya sudah running Kloxo) karena module FFMPEG nya nggak bisa di load, uhm lebih tepatnya aku nggak tau cara nge-loadnya. Utak atik sana-sini ternyata malah bikin system error dan gak tau lagi gimana cara balikinnya, fiuhh.. Akhirnya kuputuskan untuk rebuild saja.


Oh ya, kasus diatas aku menginstal FFMPEG dengan installer ini, ya emang sih modulenya terinstal dengan lengkap, cuman nggak tau gimana ngeloadnya, haha.. #dasarcupu

Setelah VPS rebuilded dengan CentOS 5.8, aku segera melakukan proses instalasi Kloxo, proses berjalan dengan mulus tanpa hambatan, mengganti webserver dengan Apache, handler suPHP, dan DNS dengan tinydns.

Aku melakukan upgrade versi PHP ke 5.3, karena versi default Kloxonya cuma 5.2, cara yang kupakai adalah cara ini, aku copas disini ya.

Spoiler :
1. Create /etc/yum.repos.d/ius.repo with content:
[ius]
name=IUS Community Packages for Enterprise Linux 5 - $basearch
baseurl=http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/$basearch
enabled=1
gpgcheck=0

and /etc/yum.repos.d/epel.repo:
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
enabled=1
gpgcheck=0
exclude=nginx*

and /etc/yum.repos.d/atomic.repo:
[atomic]
name=custom-atomic - atomicrocketturtle.com
baseurl=http://www.atomicorp.com/channels/atomic/centos/5/$basearch/
enabled=1
gpgcheck=0
includepkgs=mod_ruid* php-zend* php-ioncube*

2. Run 'yum install yum-plugin-replace'

3. Run 'yum replace php --replace-with=php53u'

4. Run again "yum list php|grep -i 'installed'" and if found content like 'php-mbstring' (for example) and then run 'yum remove php-mbstring' and run 'yum remove php53u-mbstring'

Special for xcache, ioncube and zend

1. Go to Kloxo control panel and then click 'php config' and then disable 'ioncube' and 'zend'

2. Run 'cp -rf /etc/php.ini /usr/local/lxlabs/kloxo/file/phpini/php.ini.template-5.3'

3. Open '/usr/local/lxlabs/kloxo/file/phpini/php.ini.temp' and remove the portion:
;
; xcache
__lx__enable_xcache_val
;
; ioncube loader
__lx__enable_ioncube_val
;
; zend engine loader/optimizer 
__lx__enable_zend_val

4. Run 'yum remove php-xcache php-ioncube-loader php-zend-optimizer'

5. Run 'yum install php53u-xcache php53u-ioncube-loader php-zend-guard-loader' for replace 'zend-optimizer' on php53

6. Test if xcache, ioncube and zend successful as php module with 'php -v'

7. Rename 'xcache.ini' or 'xcache.noini' to '_xcache.ini' (because kloxo will be rename 'xcache.ini' to 'xcache.noini'
Note: terkhusus masalah dengan XCache yang tidak terload (bila kamu ingin meng-enable nya), file xcache.ini jangan di rename, atau bisa reinstall dengan command yum reinstall php53u-xcache

Setelah sukses instalasi php 5.3, sekarang saatnya menginstal FFMPEG. Aku memakai tutorial ini, gak pake installer dari ffmpeginstaller.com lagi, hehe... Caranya aku copas juga ya.

Spoiler :
Installation
First you need to add a file in yum repository directory for dag packages installation. For this edit the following file:

vi /etc/yum.repos.d/dag.repo
add the following contents to the file,
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=0
enabled=1
Then enter the command,
yum install ffmpeg ffmpeg-devel
To check what audio/video formats are supported :
ffmpeg -formats > ffmpeg-format.txt
Open the ffmpeg-formats.txt to see the ooutput
D means decode
E means encode
V means video
A means audio
T = Truncated
Installation of FFMPEG-PHP Extension
FFmpeg-php is a very good extension and wrapper for PHP which can pull useful information about video through API interface. In order to install it you will need to download the source file and then compile and install extension in your server.
For downloading the source tarball click here
If you are unable to download with the above link, please use the below command:


cd /usr/local/src/
wget http://space.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2
Extract the souce tarball. If you don’t see phpize, your php may be an rpm installed one and you need to install php-devel rpms to get phpize in the server.

tar -xjf ffmpeg-php-0.6.0.tbz2
cd ffmpeg-php-0.6.0/
phpize
./configure
make
make install
Editing PHP.INI
Once you have done that without any problems then you will see the php extension file /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so (this location may depend on the php version) and you will need mention that extension in php.ini file
vi /usr/local/lib/php.ini
Put the below two lines at the end of the php.ini file

[ffmpeg]
extension=ffmpeg.so

Then restart the server
service httpd restart
To check whether ffmpeg enabled with php, point your browser to test.php file. It should show the confirmation of installed ffmpeg php extension:
// # vi test.php
phpinfo();
?>

In any case the ffmpeg does not show in the phpinfo() test, make sure that php.ini path to ffmpeg.so is correct. Still the problem occurs, the reason could be you might be using older version of ffmpeg-php which is buggy. Just download the latest version of ffmpeg-php source then compile it.
Installing Mplayer + Mencoder
Just issue the following yum commands to install the rest of the packages.
yum install mplayer mencoder
Installing FlvTool2
Flvtool2 is a flash video file manipulation tool. It can calculate meta-data and can cut and edit cue points for flv files.
yum install flvtool2
Installing LAME MP3 Encoder, Libogg, LIBVORBIS
LAME is a high quality MPEG Audio Layer III (MP3) encoder is licensed under the LGPL. Both quality and speed improvements are still happening, probably making LAME the only MP3 encoder still being actively developed.
yum install lame libogg libvorbis
This is the full installation steps which I did in all the live servers .
Nah, waktu instal ini aku ada masalah, dari console ssh reportnya, ffmpeg-php compile error – make: *** [ffmpeg_frame.lo] Error 1. The best way, always ask si mbah dan aku dapat artikel ini.

Spoiler :
If you are getting the following error while compiling the latest release of ffmpeg-php-0.6.0 , This will article will let you know how to get this fix.
Error:
/usr/src/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function âzim_ffmpeg_frame_toGDImageâ:
/usr/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: âPIX_FMT_RGBA32â undeclared (first use in this function)
/usr/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: (Each undeclared identifier is reported only once
/usr/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: for each function it appears in.)
/usr/src/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function âzim_ffmpeg_frame_ffmpeg_frameâ:
/usr/src/ffmpeg-php-0.6.0/ffmpeg_frame.c:421: error: âPIX_FMT_RGBA32â undeclared (first use in this function)
make: *** [ffmpeg_frame.lo] Error 1

Solution:-

Under the ffmpeg-php-0.6.0 directory modify the file: ffmpeg_frame.c with nano or vi editor and replace every instance of PIX_FMT_RGBA32 with PIX_FMT_RGB32
# nano ffmpeg_frame.c
# Search for PIX_FMT_RGBA32 and replace it with PIX_FMT_RGB32
# Exit from the editor

Then run the following commands:
# cd /usr/local/src/ffmpeg-php-0.6.0
# cp -aP ffmpeg_frame.loT ffmpeg_frame.lo
# make clean
# ./configure
#   make
#   make install

This should fix the errors given above. Finally add the ffmpeg.so extension in php.ini and check phpinfo for the server you should see ffmpeg listed.
Setelah mem-fixkan dengan cara diatas, jangan lupa untuk menambah settingan di php.ini supaya module bisa terload.

Alhamdulillah masalah sudah fixed. Kalau ada yang error, silahkan tanya mbah saya, hehe.. #mbah.google

Rating: 4