Saturday, November 21, 2009

vi Basics - How to edit a file

To edit using vi, type vi along with file name
vi abc.c
vi works like a console app. Now to start editing press i

To use any command like save or quit etc. press " : " (colon without quotes)
From edit mode, press ESC to go to normal mode and press :

Enter w to save/write the changes to file.
Enter q to quit vi

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/'

While Installing FFMPEG, when I was installing ffmpeg-php, I got this warning and it didn't work any further.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/' - /usr/lib/php/modules/ undefined symbol: le_ffmpeg_frame in Unknown on line 0

Tried to find the solution but didn't get any help. So I ended up reinstalling with different changes and using different guides. Following changes helped:::

First of all get 0.6.0 version, i.e ffmpeg-php-0.6.0.

Now after download: use vi to edit the ffmpeg_frame.c and search and replace PIX_FMT_RGBA32 with PIX_FMT_RGB32
To do this run the following commands:

cd ../ffmpeg-php-0.6.0
vi ffmpeg_frame.c
Now run this command:

Now run ./configure && make && make install

This should solve the problem. Worked for me.

Installing FFMPEG on Centos

This is a bit troublesome work. I spent around 9 hours banging my head with ffmpeg and did many tries to install this. And there are alot of guides for this and ***I was honored*** to install using a few of them :P. I am compiling here the set of commands that worked for me and I will also include a few alternatives in some cases and solutions to some problem which may arise.

/*********Only for beginners***********/
First of all a very little introduction to installing FFMPEG. We will be follow these procedures:
  1. We will first download the required packages (different libs and extensions). These include::: mplayer, flvtool2, lame, libogg, libvorbis, ffmpeg-php etc.
  2. The above packages are in compressed form so we will uncompress those.
  3. The uncompressed set of files are source for those, so we will compile and build them.
  4. At the end we will configure these with our apache.

To download wget is used.
e.g. wget --no-check-certificate
To extract, we use:
tar -xjf amrwb- etc
To compile we use:
make install
This will make its binaries.
/******end of Only for beginners******/

/******Real stuff starts here*********/

First of all get all the packages we need:
//Better make a separate folder for this stuff here:::
wget --no-check-certificate
(If any of the above links are expired, you may just search google for these, but prefer using the latest version. An IMPORTANT note, use ffmpeg-php-0.6.0. Older version will make problems. This solves most of the issues.

Now extract them all.
tar -xjf amrwb-
tar -xjf essential-20071007.tar.bz2
tar -xjf ffmpeg-php-0.6.0.tbz2
tar -xzf flvtool2-1.0.6.tgz
tar -xzf lame-398-2.tar.gz
tar -xzf libogg-1.1.4.tar.gz
tar -xzf libvorbis-1.2.3.tar.gz
Now make directory for codecs and move them there.
mkdir /usr/local/lib/codecs
mv essential-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
We will now download MPlayer and FFMPEG using SVN and update.
svn checkout svn:// ffmpeg
svn checkout svn:// mplayer
cd mplayer/
svn update
IMPORTANT: Download these both from SVN, by other ways it will give error (I got them).

If you do not have SVN, you can install it using:
yum install subversion
yum install ruby
yum install ncurses-devel
or you can use apt-get too
Some guides asked to update configuration file too. But for me it worked without it. To update libs use vi
vi /etc/
It will open up vi editor. Add the following line:
and then load config file using
ldconfig -v
Now make all other libs

cd amrwb-
make install

cd ../flvtool2-1.0.6
ruby setup.rb config && ruby setup.rb setup && ruby setup.rb install

cd ../lame-398-2
make install

cd ../libogg-1.1.4
make install

ldconfig -v

cd ../libvorbis-1.2.3
make install

cd ../mplayer/
make install

cd ../ffmpeg
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
make install
Here, you may have problem with ffmpeg. I was having some issues with libvorbis. I first tried it by removing this. It works but you may need libvorbis. You may try using other version of vorbis we downloaded above. FFMPEG will take some time too on ./configure and make.
Also some of the guides used
echo '#define HAVE_LRINTF 1' >> config.h
after configure. I didn't use it but I think it will help.

Now add links to codecs:
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/lib/
Now here comes an IMPORTANT part. This is a must do, it solved my all issues :P
Goto ffmpeg-php and edit ffmpeg_frame.c

cd ../ffmpeg-php-0.6.0
vi ffmpeg_frame.c
Now run this command:
save and quit. Use :wq for this.

Now in the same folder (i.e. ffmpeg-php-0.6.0) do the following.
make install
Now major stuff is done. We just have to add the php extension to php.ini file. You will first need to locate php.ini. You may find it in /etc/
vi /etc/php.ini
Add this line at the end
Ok, all done now. Just restart the server and check phpinfo for ffmpeg extension.
To restart use:
/etc/init.d/httpd restart
You can also use your server's cpanel/plesk for restarting the service.

Now to test you may run php command for phpinfo. Use this:
php -r 'phpinfo();' | grep ffmpeg
You should get version info and build date etc.
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => Nov 21 2009 23:35:23
ffmpeg-php gd support => enabled
ffmpeg libavcodec version => Lavc52.32.0
ffmpeg libavformat version => Lavf52.36.0
ffmpeg swscaler version => SwS0.7.1
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0
PWD => /usr/src/ffmpeg-php-0.6.0
_SERVER["PWD"] => /usr/src/ffmpeg-php-0.6.0
_ENV["PWD"] => /usr/src/ffmpeg-php-0.6.0
I will discuss a serious error in another post.

Developer Instincts