convert avi to flv using ffmpeg with Thumbnail

Video upload functionality is needed in every networking site. I will give best option the create the thumbnail from video file and convert video file to flv format.

convert avi to flv using ffmpeg with Thumbnail

For conversion of video files and creating the thumbnail we need the ffmpeg software need to be installed on server. Here I used the linux server. For installing the FFmpeg I used following article.

http://mysql-apache-php.com/ffmpeg-install.htm

After installing the ffmpeg software in linux you can use the command prompt for converting the video file.

Use the following command for covert the avi or video file to flv format.

#ffmpeg -i VIDEOFILE.avi  -ab 56 -ar 44100 -b 200 -r 15 -s 320×240 -f flv final.flv

If you are using the PHP then you can use following code in your PHP script for converting the video file.


exec("ffmpeg -i VIDEOFILE.avi  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv final.flv");

//For creating the thumbnail use the following code

exec("ffmpeg -y -i moviefile.avi -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110x90 new.png");

converting the video files to flv format that takes some time. So I recommend not to convert the video file to flv while uploading.

Just create the thumbnail and show to use.

For converting the video file to flv format use the cronjob. Create two or One cronjob setting and daily two or more time through script convert the video files to flv.

convert the wma files through php script in linux

When we use the mobile download we always get the wma files as song file. If you want to convert wma files to mp3 file. For that I written the simple PHP sciprt for converting the wma files through php scirpt.

convert the wma files through php script in linux

Use the following scirpt.

<?php
// Script made for convertion of  .wma to .M3 Converter (media conversion) in Linux
//You need the  mplayer and lame installted in your linux OS

set_time_limit(0);
ReadDirs('/var/www/html/songs/wmamp3/');
function ReadDirs($dir){
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." &amp;&amp; $file != ".." &amp;&amp; $file != "Thumb.db") {
$info = pathinfo($file);
if($info['extension']=='wma') {
$mp3_file = str_replace('.wma','',$file);
$cmd = "mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader '".$dir.$file."';lame -m s -V 3 audiodump.wav;mv audiodump.wav.mp3 '".$dir."mp3/".$mp3_file.".mp3';rm -f audiodump.wav";
system($cmd);
}

}
}
closedir($handle);
}
}
?>

Above script will take wma files from folder and convert all files to mp3 files.

convert the wma files through php script in linux
convert the wma files through php script in linux

 

execute shell script daily through cron

Normally running the shell script we will use the following command. If shell script not running then you need to do shell script executable. using following command

execute shell script daily through cron

#./shell_script.sh
If shell script not running then you need to do shell script executable. using following command

#chmod +x shell_script.sh

for running the shell scirpt daily through use the following command

#su
#PASSWORD
#crontab -e

Put following lines in cron file.
* * 1 * * /bin/sh /home/myuser/shellscript/shell_script.sh

 

execute shell script daily through cron
execute shell script daily through cron

rsync copy files from remote server to other server

I always need to use this method for copy files one remote machine to another machine. there are many tool to do that. filezilla, winscp and many more. But I like command prompt.

rsync copy files from remote server to other server

scp is command is very useful for file transfer on remote machine.

To copy local file on remote machine use following command

#scp FILENAME  USERNAME@55.86.59.95:/home/USER/

To copy file from remote machine use following command

#scp USERNAME@55.86.59.95:/home/USER/FILENAME  .
or use
#scp USERNAME@55.86.59.95:/home/USER/FILENAME  *

To copy file from remote machin using scp command with port

#scp -P54 USERNAME@55.86.59.95:/home/USER/FILENAME  .
or use
#scp -P54 USERNAME@55.86.59.95:/home/USER/FILENAME  *

Above commands will execute faster than other tools.

rsync copy files from remote server to other server
rsync copy files from remote server to other server

accidentally deleted mysql root user

Some time back I accidentally deleted mysql root user. Then when checked mysql then mysql is not accessible to me from root user. I have the trick to restore mysql database.

accidentally deleted mysql root user

I am using the fedora 14 on my machine. After trying so many things at the end I found the solution.

use the following steps:

First I stoped mysql using following command.

#/etc/init.d/mysqld stop

Then I created one file with following conent

#file mysql_reset

UPDATE mysql.user SET Password=PASSWORD(‘newpassword’) WHERE User=’root’;

#mysqld_safe –init-file=/home/techiego/mysql-init &

Than again I stooped mysql process and restarted mysql. I was able to access my mysql again.

accidentally deleted mysql root user
accidentally deleted mysql root user

How to configure haproxy load balancing on amazon ec2

Confused how to configure load balancer on Amazon. Here we given you detail instructions about How to configure haproxy load balancing on amazon EC2

Many people take amazon EC2 cloud hosting. Amazon does gives the load balancer for application load balancing. But Amazon load balancer is not that much good. Amazon load balancer is not working on hardware or software base. That balancer just sending request to server one by one. Many people confused how to configure load balancer on Amazon EC2.

Here I am going to give you detail instructions about setting up the HaProxy load balancer on Amazon EC2.

How to configure haproxy load balancing on amazon ec2

What is Haproxy?

AProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless.

How to configure haproxy load balancing on amazon ec2
How to configure haproxy load balancing on amazon ec2

For Haproxy load balancing I recommend to create the micro instance first. Then login to micro instance and install haproxy on that machine. I taken the Centos 5.0 virgin os. Use following command for install the haproxy.

#yum install haproxy

Then Open the haproxy config file.

# vi /etc/haproxy.cfg

For detail configuration you should read the Haproxy config documentation.

http://haproxy.1wt.eu/download/1.3/doc/configuration.txt

Haproxy’s default load balancing style is roundrobin. Which is trusted and good. With this load balancing I am serving around two million pages daily. Means I am handling 6 to 7 million requests per day. I am not having any issues.

I used the three backend server for delivery of my application and one server for serving the static data which is having images and js and css and application files.

Here is my configuration file


global
 maxconn     4096 # Total Max Connections. This is dependent on ulimit
 daemon
 nbproc      4 # Number of processing cores. Dual Dual-core Opteron is 4 cores for example.

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
 mode        http
 log         global
 option      dontlognull
 option      httpclose
 option      httplog
 option      forwardfor
 option      redispatch
 timeout connect 10000 # default 10 second time out if a backend is not found
 timeout client 300000
 timeout server 300000
 maxconn     60000
 retries     3

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
#frontend  main *:80
frontend http-in
 bind :80
 acl url_static       path_beg       -i /static /images /javascript /stylesheets
 acl url_static       path_end       -i .jpg .gif .png .css .js
 acl url_stats        path_beg    /haproxy-stats
 use_backend        be_stats    if url_stats

 use_backend static          if url_static
 default_backend             app

#-------------------------------------------------
#back-end statistics section
#----------------------------------------------------------------
backend be_stats
 stats uri /haproxy-stats
#    stats show-node

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
 balance     roundrobin
 server      static 10.211.164.138:80 check
 #server      static 10.211.185.111:80 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
 balance     roundrobin
 server  app1 10.214.284.241:80 check
 server  app2 10.208.168.131:80 check
 server  app3 10.212.158.126:80 check

You can use the above code in haproxy.cfg file. You just need to change the IP address which are listed under backend static and backend app section. You just put your static server(amazon EC2 instance’s internal IP address).

You should use internal IP address of server because that will reduce the bandwidth uses of Amazon EC2 server. Do not use the public IP address for load balance because that will cost you.

Put application database and application files on all the server. Point your domain to your load balancer machine’s Public IP address.

Let say your application is running on following domain.

www.YOURDOMAIN.COM – point to Load balancer macine.

Open your all application and static server’s apache configuration file. put following entry in that file.


<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.YOURDOMAIN.COM

# Other directives here

</VirtualHost>

after this just restart the apache server of all servers.

If you are having any issues or questions about setting up the haproxy on amazon EC2 server Please write to me.

How to connect amazon instance through linux command prompt

There are many articles we can found for to connect to amazon ec2 machine though ssh. But all I found for windows. Using putty and putty key gen tool you can connect to amazon ec2 linux machine.

How to connect amazon instance through linux command prompt

How to connect amazon instance through linux command prompt
How to connect amazon instance through linux command prompt

If you are having the linux box and you want to connect to amazon ec2 machine then that is very easy. You just need to install the following package to connect to amazon ec2 machine.

Install the ec2-api-tools on linux or mac machine. use the following command.

# yum install ec2-api-tools

When you first try to create the amazon instance that time you need to create the key pair file. You got the .pem file as key pair file. That file is very important for connecting to amazon instance machines.

Keep your key pair file(.pem ) in safe location and dont give this file anyone. Go to directory where you kept the key pair file.

#ssh -i ec2-YOURKEY.pem root@ec2-51-18-49-55.compute-1.amazonaws.com

Using above command you can connect to amazon EC2 linux boxes.

how to install memcached on centos

We given steps for install memcached on centos. Memcached server is used for increase server performance and response time. Here we given the commands for installing memcached on centos.

how to install memcached on centos

I always need to install the memcached on my linux servers like fedora or centos. On fedora box installing the memcached is very easy through yum install. But Centos installing and using memcached is not so easy.

how to install memcached on centos
how to install memcached on centos

For my Ruby on Rails and PHP applications I always need to install the memcached on server. Here I am going to give you the steps for installing the memcached.

Very important note: you need to install the gcc compiler for memcached binary installation. Using the memcached with php installation you need the phpize and php-pecl-memcached installed. follow my steps and memcached binary installation.


# yum install gcc*
# cd /usr/src
# wget http://pecl.php.net/get/memcache-2.2.5.tgz
# tar zxvf memcache-2.2.5.tgz
# cd memcache-2.2.5
# phpize
# ./configure
# make
# make install

For checking the php.ini file path use following command.


php -i | grep php.ini

Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

or your php.ini file will be following location


# vim /etc/php.ini

Put following line in that file
extension = “memcache.so”
Restart the apache server

# /etc/init.d/httpd restart

To check is memcache extension loaded in php, execute following command.

#php -i | grep memcache

After restarting the machine memcache need to restart. For that us ( Use this step for only Admin Adserver Box)

# vi /etc/rc.local

Put following contect in to rc.local file (file location – /etc/rc.local)

# memcached -d -p 11211 -u nobody -c 1024 -m 1024

How to install imagemagick binary on CentOS

For many application we need to install the imagemagick on Centos linux server. Many Ruby on rails and PHP applications need the support of imagemagick for image resizing.

How to install imagemagick binary on CentOS

 

How to install imagemagick binary on CentOS
How to install imagemagick binary on CentOS

We all the very traditional way of installing the application on linux machine which is as follows:

# yum install imagemagick

This command will not install the imagemagick on Centos properly. So use following commands for installing the imagemagick on centos

#yum install gcc*

#cd /tmp

# wget ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.6.1-10.tar.gz

# tar xzf ImageMagick-6.6.1-10.tar.gz

# cd ImageMagick-6.6.1-10

# ./configure

# make

# make install

After using the above commands imagemagick will be installed the properly on CentOS machine.

If you have any trouble or issues during installation then get back to me.

how to find out cpu and disk usage in linux

When you are running any script on server or running any application you want to know how much memory or disk uses is happened by application.

how to find out cpu and disk usage in linux

how to find out cpu and disk usage in linux
how to find out cpu and disk usage in linux

When you are doing load testing this time this kind of applications are very useful to check the server status. Create file name CPU-Disk.sh and put following content in that.

#!/bin/sh

# Change this as needed

OUTPUT_FILE=file.txt

# Initially delete old output file if needed.

/bin/rm -f $OUTPUT_FILE

while [ 1 -eq 1 ]; do

date >> $OUTPUT_FILE

echo "------------------------" >> $OUTPUT_FILE

cat /proc/meminfo >> $OUTPUT_FILE

echo "------------------------" >> $OUTPUT_FILE

df -k >> $OUTPUT_FILE

echo "------------------------" >> $OUTPUT_FILE

top -b -i -n 1 >> $OUTPUT_FILE

# Record terminator. Add more === if needed :)

echo "========================" >> $OUTPUT_FILE

sleep 60

done

This command is useful to create the sh file executable in linux

#chmod +x /YOURPATH/CPU-Disk.sh

when you need to check the server status you need to run the this file using this command

#CPU-Disk