How To: Install FFMPEG and FFMPEG-PHP

I was randomly browsing the internet and reading about making a website look better and I encountered ffmpeg-php. ffmpeg is a very powerful tool to record, convert and stream audio and video. Its a very rich tool almost supporting every format out there in the world. It can convert any format to any other format provided the codec. ffmpeg-php is an extension for PHP that provides a rich library to access info about audio and video files. The good thing about ffmpeg-php is that it can retrieve all info about any audio/video file subjected to the condition that the particular audio/video format is supported by your ffmpeg installation. So, now you have a clear idea that you can do wonders with audio/videos while showing them on your site 🙂

I tried some of the functionalities and they worked out of the box. Here’s is complete how to on installing ffmpeg and ffmpeg-php.

FFMPEG:

I tried installing ffmpeg from rpms provided by several Fedora repositories but after installation ffmpeg doesn’t seem to work. After several tries, I installed ffmpeg from source rpms and it worked. Below, I will describe how to install ffmpeg from source rpm.

Step 1:

Make sure that you have ‘rpmbuild’ installed by issuing

[root@bordeaux saini]# rpm -q rpmbuild [Enter]

command. If the above says that rpmbuild is not installed, then install it using yum as given below

[root@bordeaux saini]# yum install rpmbuild [Enter] (do as root)

Step 2:

Download the latest src rpm of ffmpeg from rpmfind.net. Issue the command given below

[root@bordeaux saini]# rpm -hiv ffmpeg-x.x.x.xx-xxx.src.rpm [Enter] (do as root)

Step 3:

Go to ‘/usr/src/redhat/SPECS/’ directory and issue the command given below

1
2
[root@bordeaux saini]# cd /usr/src/redhat/SPECS/ [Enter]
[root@bordeaux SPECS]# rpmbuild -ba ffmpeg.spec [Enter] (do as root)

If it gives an error like package ‘xyz’ is need by ffmpeg. Then install the package ‘xyz’ using yum as

[root@bordeaux SPECS]# yum install xyz [Enter] (do as root)

After installing the dependencies, issue the rpmbuild command ‘rpmbuild -ba ffmpeg.spec’. Now ffmpeg rpms will be build and they will be stored in ‘/usr/src/redhat/RPMS/i386/’.

Step 4:

Go the ‘/usr/src/redhat/RPMS/i386/’ (x86_64 instead of i386 if your OS is 64 bit). Install all the rpms that were built by rpmbuild.

[root@bordeaux saini]# rpm -hiv *.rpm [Enter] (do as root)

Thats it. ffmpeg is now successfully installed on your computer. Half the job is done. Now lets proceed with ffmpeg-php installation.

FFMPEG-PHP:

We will install ffmpeg-php from source bundle.

Step 1:

Make sure that ‘php-devel’ installed on your machine by issuing

[root@bordeaux saini]# rpm -q php-devel [Enter]

command. If the above command says the ‘php-devel’ is not installed, then install it using the following command.

[root@bordeaux saini]# yum install php-devel [Enter] (do as root)

Step 2:

Download the latest version of ffmpeg-php from here. Unpack the file you have downloaded.

1
2
[root@bordeaux saini]# bunzip2 -d ffmpeg-php-0.5.1.tbz2 [Enter]
[root@bordeaux saini]# tar -xvf ffmpeg-php-0.5.1.tar [Enter]

Step 3:

Issue the following command in sequence if everything goes fine.

1
2
3
4
5
[root@bordeaux saini]# cd ffmpeg-php-0.5.1 [Enter]
[root@bordeaux ffmpeg-php-0.5.1]# phpize [Enter]
[root@bordeaux ffmpeg-php-0.5.1]# ./configure [Enter]
[root@bordeaux ffmpeg-php-0.5.1]# make [Enter]
[root@bordeaux ffmpeg-php-0.5.1]# make install [Enter] (do as root)

Step 4:

Open ‘/etc/php.ini’ and add a line ‘extension=ffmpeg.so’ in the category ‘Dynamic Extensions’. For help see the image below.
FFMPEG PHP PHPini Module

Step 5:

Restart apache web server aka ‘httpd’ service by issuing the command.

[root@bordeaux saini]# service httpd restart [Enter] (do as root)

Step 6:

Write a test php file and test your ffmpeg-php installation.

phpinfo();

Save the above code in ‘info.php’ and save the file in ‘/var/www/html/’ and browse http://localhost/info.php . If you see something like this.
FFMPEG PHP Linux
Then the ffmpeg-php is successfully installed on your machine. Now you can jump into the world of video manipulation via your website.

 

How To: Configure VNC Server

Vncserver is just another application available in almost all the available Linux based distros. Configuring vncserver is very easy. But the default desktop view in vncviewer is gray scale desktop with very pathetic GUI. To view normal Gnome or KDE desktop in vncviewer, assigning a custom port for usage, user configuration and to adjust the resolution of the vncviewer window, some files need to be configured properly. Here are the required configuration in any version of Fedora/Fedora Core. But with minor modifications these can be applied to other distros like Ubuntu, SuSE, Gentoo etc.

Step 1: Installing Vncviewer, Vncserver

As root do this

[root@bordeaux saini]# yum install vnc [Enter]

Step 2: Configuring resolution, port & user

The default location of server configuration file for vncserver is ‘/etc/sysconfig/’. To configure the resolution, user and port open ‘/etc/sysconfig/vncservers’ in you favorite editor and add two lines per user configuration shown ..

VNCSERVERS=":"
VNCSERVERARGS[]="-geometry x x"

Example :

VNCSERVERS="3:saini"
VNCSERVERARGS[3]="-geometry 1000x700"

You can choose any display port, but it should not be in use by another X server. Window height and width can be anything (not in fraction of course). But keep in mind that the system on which you are going to view the desktop using vncviewer should have greater resolution than what you specify here, otherwise scrollbars will appear.

Step 3: Configuring Desktop Environment

The user specific configuration files of vncviewer resides in ‘.vnc’ directory in user’s home directory. (e.g. ‘/home/saini/.vnc/’). Open ‘.vnc/xstartup’ in your favorite editor and edit as below

  • For Gnome

The ‘xstartup’ file shout look like this

#!/bin/sh
 
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
 
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
startx &
  • For KDE

The ‘xstartup’ file should look like this

#!/bin/sh
 
# Uncomment the following two lines for normal desktop:
#unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
 
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#vncconfig -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
startkde &

Step 4: Configuring password

For setting up vncviewer password for user ‘xyz’, login as user ‘xyz’ and issue ‘vncpasswd’ command on a terminal/konsole (or whatever). Enter password twice and you are done with password setting.

Step 5: Starting Vncserver

To start vncserver, login as root and issue ‘service vncserver start’ command. If service started successfully, you are ready to use vncviewer on a remote/local machine.

Step 6: Accessing through Vncviewer

  • From Linux based machines
[saini@bordeaux saini]# vncviewer IP_Address:displayPort [Enter] #(IP Address is for the machine where you set up vncserver)
  • From Windows

On windows there is a software called RealVnc. Install it and enter <IPAddress>:<displayPort> in the dialog box.
[I explained how to connect via windows because it may help someone get a bit of relief.]

Screenshots:

  • Vncviewer with Gnome as Desktop environment

VNC Server VNC Viewer Screenshot GNOME

  • Vncviewer with KDE as Desktop environment

VNC Server VNC Viewer Screenshot KDE

Vnc is nice tool if you want to avoid using windows. I use it all the time. While I am forced to work on windows system, I install vncviewer and use it in full screen mode 😛 It also helps when you want to run some gui based application and monitor is remotely. Because if you close vncviewer window and use vncviewer again, you will be given the desktop session where you left it (all windows open and applications running).

 

How To: Install PHP-Ming

Yesterday, I came across a library called ming for php which can do wonders while converting videos to .swf (flash), images to .swf and much more. The best thing is that ming provides wrappers in C/C++/PHP/Python/Perl/Tcl etc. So, can be used within any one of these languages. But, the damn thing drove me crazy while installing. It was very tough experience installing it as the available howtos didn’t help much. But finally I somehow managed with the installation and it worked 🙂 So, I thought of writing this how to, so that anyone having the same problem can find it helpful.

Here is a complete howto on installing php-ming in Fedora. (I installed it on Fedora 7 and with php5, but howto is supposed to work with other versions as well.) Though there are rpms available for earlier versions of ming, but I wanted the latest, so installed from source.

Resources:
libming : http://www.libming.net/
PHP : http://php.net/

Step 1

First of all make sure that you have php-devel package, otherwise you will not be able to install ming at all. Do the following as root.

[root@bordeaux root]# rpm -q php-devel [Enter]

If the above command says php-devel is not installed, then fetch php-devel for your php version from here and install as given below, else proceed to step 2.

[root@bordeaux root]# rpm -hiv php-devel-5.2.2-3.i386.rpm [Enter]

Step 2

Download latest version of ming from here.

Step 3

Untar the downloaded package.

[saini@bordeaux saini]# tar -xvzf ming-0.4.0.beta5.tar.gz [Enter]

Step 4

Change directory to ‘./ming-0.4.0.beta5’ and issue ./configure and make as given below

1
2
3
4
[saini@bordeaux saini]# cd ming-0.4.0.beta5 [Enter]
[saini@bordeaux ming-0.4.0.beta5]# ./configure --enable-cXX --enable-php [Enter]
[saini@bordeaux ming-0.4.0.beta5]# make [Enter]
[root@bordeaux ming-0.4.0.beta5]# make install [Enter] (as root)

Step 5

Go to ‘./php_ext’ directory and issue ‘make’ and ‘make install’.

1
2
3
[saini@bordeaux ming-0.4.0.beta5]# cd php_ext [Enter]
[saini@bordeaux php_ext]# make [Enter]
[root@bordeaux php_ext]# make install [Enter] (as root)

Step 6

Open make_modules.sh in your favorite editor and uncomment the line ‘make install’ and run make_modules.sh.

[root@bordeaux php_ext]# bash make_modules.sh [Enter] (as root)

Step 7

Go to ‘./tmp/modules/’ directory and copy ming.so to ‘/usr/lib/php/modules/’

1
2
[root@bordeaux php_ext]# cd tmp/modules/ [Enter]
[root@bordeaux modules]# cp ming.so /usr/lib/php/modules/ [Enter] (as root)

If ming.so is not found in ‘php_ext/tmp/modules/, then update your db using ‘updatedb’ and locate ming.so and if found on locate, then copy it to ‘/usr/lib/php/modules/’. If not found at all, try recompiling or issue some random commands related to make.

Step 8

Go to ‘/usr/local/lib/’ and check if libming.so, libming.so.0 etc. are present there. If yes proceed else I don’t know what to do 🙁

Step 9(a)

Go to ‘/usr/lib/php/modules/’ and issue these commands.

1
2
3
4
[root@bordeaux modules]# ln -s /usr/local/lib/libming.so libming.so (as root)
[root@bordeaux modules]# ln -s /usr/local/lib/libming.so.0 libming.so.0 (as root)
[root@bordeaux modules]# ln -s /usr/local/lib/libming.so.0.3.0 libming.so.0.3.0 (as root)
[root@bordeaux modules]# ln -s /usr/local/lib/libming.so.0.4.0 libming.so.0.4.0 (as root)

Step 9(b)

Go to ‘/usr/lib/’ and issue these commands.

1
2
3
4
[root@bordeaux lib]# ln -s /usr/local/lib/libming.so libming.so (as root)
[root@bordeaux lib]# ln -s /usr/local/lib/libming.so.0 libming.so.0 (as root)
[root@bordeaux lib]# ln -s /usr/local/lib/libming.so.0.3.0 libming.so.0.3.0 (as root)
[root@bordeaux lib]# ln -s /usr/local/lib/libming.so.0.4.0 libming.so.0.4.0 (as root)

Step 10

Restart the httpd service by issuing the command below

[root@bordeaux root]# service httpd restart [Enter] (as root)

Step 11

Write a file ‘/var/www/html/info.php’ with following contents

phpinfo();

and point your web browser to http://localhost/info.php . Now search for ‘ming’ and check whether its enabled or not.

PHP Ming in Fedora

If enabled, yes you have successfully installed php-ming 🙂 Hope this helps.

 

How To: Install and Configure Shoutcast Radio

Shoutcast is a mp3 broadcasting/streaming media server software provided by NullSoft. One can setup a server on any system, GNU/Linux / Windows/ MacOS and can stream mp3 over the network, internet/intranet. I setup shoutcast on my system a long back and found it very useful. Here is a step by step how to on how you can setup shoutcast on a GNU/Linux system.

Shoutcast can be installed even if you don’t have root privileges. But in that case you can’t use port less than 1024 for broadcasting. Below, I’ll explain how to install it for a non-root user.

Shoutcast server depends on a tool shoutcast DNAS for audio input in Linux. So, here we go

Step 1

Download the latest version of shoutcast from here. Download the one for Linux (glibc).

Step 2

Let us assume we want to install shoutcast in a directory named ‘shoutcast’ in user’s home directory and we want to broadcast punjabi songs.

1
2
3
[saini@bordeaux shoutcast]# tar -xvzf sc_serv_1.9.8_Linux.tar.gz [Enter]
[saini@bordeaux shoutcast]# mkdir punjabi [Enter]
[saini@bordeaux shoutcast]# mv sc_serv.conf punjabi/sc_serv_punjabi.conf [Enter]

Step 3

Open sc_serv_punjabi.conf in your favorite editor and modify certain parameters as per you requirements. The essentials are below.

1
2
3
4
5
6
7
8
9
10
11
12
13
MaxUser=20
Password=yourPassword
PortBase=8300 #(Confirm that this port and the port PortBase+1 is not being used)
LogFile=none
RealTime=0
ScreenLog=0
ShowLastSongs=10
SrcIP=ANY
DestIP=ANY
Yport=80
NameLookups=0
AdminPassword=yourAdminPassword
TitleFormat=%s [IIIT Radio]

etc. My sc_serv.conf can be accessed here. That was all for installing the shoutcast server.

Now, the installation of DNAS tool is still pending. Here is a step by step procedure to install DNAS tool.

Step 1

Download the latest version of DNAS tool from here.

Step 2

1
2
3
4
[saini@bordeaux shoutcast]# tar -xvzf sc_trans_posix_040.tgz [Enter]
[saini@bordeaux shoutcast]# cd sc_trans_040/ [Enter]
[saini@bordeaux sc_trans_040]# mv sc_trans_linux ../ [Enter]
[saini@bordeaux sc_trans_040]# mv sc_trans.conf ../punjabi/sc_trans_punjabi.conf [Enter]

Step 3

Go to punjabi directory and open sc_trans_punjabi.conf in your favorite editor and make changes according to your needs. Here are some

1
2
3
4
5
6
7
8
9
PlaylistFile=/exactPathTo/punjabi.lst
ServerIP=
ServerPort=
 # 8300 in this case
Password=
 # yourPassword in this case
StreamTitle= %s
StreamURL=
Shuffle=1 # (1 for random songs)

etc. My sc_trans.conf can be accessed here.

Step 4

Generate a list of all the songs (mp3) you have and put it in punjabi.lst in punjabi directory.

[saini@bordeaux punjabi]# find /pathToPunjabiDir/ -type f -name "*.mp3" > punjabi.lst [Enter]

My dummy punjabi.lst can be accessed here.

The configuration part of shoutcast server with audio input is complete. Now we have to run the server so that we can listen to music.

Go to the shoutcast directory and run the sc_serv first and then run the sc_trans_linux. Here is way to do that.

1
2
[saini@bordeaux shoutcast]# ./sc_serv punjabi/sc_serv_punjabi.conf > /dev/null 2> /dev/null &
[saini@bordeaux shoutcast]# ./sc_trans_linux punjabi/sc_trans_punjabi.conf > /dev/null 2> /dev/null &

Now your system is a shoutcast server. Any client can use mplayer, vlc, amarok or any other multimedia player that support streaming media to listen to the music being played on your server.

1
2
[saini@bordeaux saini]# mplayer http://yourIp:port [Enter]
[saini@bordeaux saini]# mplayer http://localhost:8300 [Enter] # (in the above case).

If you want shoutcast to start every time your system boots. Put these lines in /etc/rc.local

1
2
/home/saini/shoutcast/sc_serv /home/saini/shoutcast/punjabi/sc_serv_punjabi.conf > /dev/null 2> /dev/null &
/home/saini/shoutcast/sc_trans_linux /home/saini/shoutcast/punjabi/sc_trans_punjabi.conf > /dev/null 2> /dev/null &

Shoutcast is fun and its more fun when everyone listens to what you are listening to 🙂

 

How To: Install WordPress on LAMP

Recently, I bought this domain name and shifted all my blogs here on saini.co.in . As I chose wordpress as the software to blog. So, just installed it and started using it right away. Installing wordpress is one of the most easiest things that you’ll ever do. Below is a step by step howto on installing wordpress and importing your current wordpress.com blog to your domain.

Step 1:

Download latest version of wordpress from here.

Step 2:

Go to the directory where you want to install it. Here I am taking gofedora.com as reference website where we want to install the wordpress and ~/htdocs/ as the web directory for gofedora.com . Modify above details in accordance with your needs.

If you downloaded .zip format then do this

[saini@bordeaux htdocs]# unzip wordpress-X.X.X.zip [Enter]

If you download .tar.gz format then do this

[saini@bordeaux htdocs]# tar -xvzf wordpress-X.X.X.zip [Enter]

Step 3:

[saini@bordeaux htdocs]# mv wordpress/* . [Enter]

If you visit http://gofedora.com now, you’ll get an error as shown in the image below …

Wordpress Error Without wp-config

Step 4:

Open the file wp-config-sample.php in your favorite text editor and edit the things shown in the image below.

Sample wp-config

Enter your database name, database username, database password and the table prefix for the wordpress database. e.g. one can use linux_ as table prefix. If you have the database on the same system, then there is no need to change the database host otherwise change it accordingly.

Step 5:

[saini@bordeaux htdocs]# mv wp-config-sample.php wp-config.php [Enter]

Step 6:

Go to http://gofedora.com/ and you’ll see a welcome page if you gave correct setting in wp-config.php . The page is like in the image below.

Wordpress Blog Config

Fill the settings properly. Anyway you can change them afterwards. Fill the blog name and email id and click Install WordPress.

Step 7:

You’ll see a web-page like in the image below, if everything goes fine. Copy the password on the page and paste at some temporary place and click login.

Wordpress Copy Password

Step 8:

You’ll be presented with a login page. Enter ‘admin’ as username and the password you copied from the previous page.

Wordpress Admin Login

Step 9:

Congratulations ! You have successfully installed wordpress and created the admin login. Go to Users -> Authors & Users and click Edit in the row with admin as author. Change the password on the next page as below ..

Wordpress Change Password

This is all you have to do to install wordpress. Below is how you import wordpress.com blog to your domain.

Step 1:

Login as admin on you wordpress.com blog and go to Manage -> Export and download the exported blog to your system as show in the image below.

Wordpress Export Blog

Step 2:

Create directory named ‘uploads’ in ~/htdocs/wp-content/ and change permissions to 777 so that wordpress can upload your blog there.

1
2
3
[saini@bordeaux htdocs]# cd wp-content [Enter]
[saini@bordeaux wp-content]# mkdir uploads [Enter]
[saini@bordeaux wp-content]# chmod 777 uploads [Enter]

Step 3:

Go to Manager -> Import section and click on ‘wordpress’ . Upload the .xml file that you download from your wordpress.com blog in step 1 on the page as shown in the image below ..

Wordpress Import Blog

Step 4:

If uploading goes successful, then all your posts will be imported from your wordpress.com blog and will be stored in the database as gofedora.com . Now it will ask you for the author of the new blog posts at gofedora.com as show below …

Choose New Author

Step 5:

Change the permission of uploads back to normal as show below

[saini@bordeaux wp-content]# chmod 744 uploads [Enter]

Everything is done. Now you blog has been shifted to your domain and you can go on with the new blog. But keep in the mind the the images you used in wordpress.com blog posts are not stored in your local database, they are still linked back to your wordpress.com blog images. So, don’t just go and delete your wordpress.com blog. That would be fatal.

The steps for installing wordpress on a windows system are the same, but you have to use some notepads and whatever to edit files 🙂

Enjoy blogging at your domain. Hope the above howto helps.