how to convert video to flv using php

Tutorial for how to convert video to flv using php. Most of video upload sites are using the ffmpeg and php for uploading and converting the video files.  For converting you need to install the ffmpeg on your server. you can download and install ffmpeg from following location.

how to convert video to flv using php

how to convert video to flv using php
how to convert video to flv using php

http://www.ffmpeg.org/download.html

For installting the ffmpeg on linux box I found following article very helpful

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

After installing the ffmpeg on your system you can use following commands for converting the video files to flv format.

avi to flv convert through ffmpeg

ffmpeg -i 00138.avi  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv final.flv

For creating the thumbnail the from video file you can use the folowing command.

create thubnail from movie file
ffmpeg -y -i moviefile.avi -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110×90 new.png

In PHP you can use the following code easily.


$video_file = '/pathtovideo/test.avi';

$flvfile ='/pathtoflv/test.flv';

$png_path ='/pathtopng/test.png';

exec("ffmpeg -i ".$video_file."  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv ".$flvfile.");

//for thumbnail

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

Above code with convert the video file to flv format but my suggestion is convertion of video files will take so much bandwidth on server so use cronjob for converting the video files in night time.

deleting one day old files from folder using php

We given php  code for Checking directory and deleting one day old files from folder using php, from folder in windows or linux through php language. For deleting the files from folder in any system (windows or linux). I created the PHP script for deleting the old files from system.

Earlier I created the script for deleting files from folder but that was for only linux. Then I created script which will work independently. Following script will work in mac or windows or linux.

deleting one day old files from folder using php

 /***************** Delete one day old files ****************/
 $dir = "C://Inetpub/vhosts/yourdomain/tmpfiles";

 if (is_dir($dir)) {
 if ($dh = opendir($dir)) {
 while ($file = readdir($dh)) {
 if(!is_dir($dir.$file)) {
 if (filemtime($dir.DIRECTORY_SEPARATOR.$file) <     strtotime('-1 days')) { //if 1 days old, delete
<div id=":1o">echo "Deleting $dir.$file (old)\n";
 unlink($dir.$file);
 }
 }
 }
 } else {
echo "ERROR. Could not open directory: $dir\n";
 }
 } else {
 echo "ERROR. Specified path is not a directory: $dir\n";
 }
 closedir($dh);

// Above script is platform independent.</div>

How to install ec2-api-tools for fedora

When we want to connect to amazon server instance through linux terminal then you need to install ec2-api-tools for fedora. We given full detailed information.

How to install ec2-api-tools for fedora

For installing the ec2-api-tools in linux box follow the steps.

You will find the rpm package in following URL:

http://www.rpmfind.net/linux/rpm2html/search.php?query=ec2-api-tools&submit=Search+…&system=&arch=

Use following commands for installing the api-tools.
[root@localhost www]# cd /tmp/
[root@localhost tmp]# wget ftp://195.220.108.108/linux/rpmfusion/nonfree/fedora/releases/12/Everything/i386/os/ec2-api-tools-1.3.36506-1.fc12.noarch.rpm
After this when I started to connect my amazon server instance then I got following error message.

Permissions 0755 for ‘ec2-project.pem’ are too open.

It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: ec2-project.pem

For solving the issue you need to change the key file permission to 700. For that use following command

[root@localhost EC2key]$ chmod 700 -R ec2-project.pem
[root@localhost EC2key]$ ssh -i ec2-project.pem root@ec2-59-16-79-85.compute-1.amazonaws.com
Last login: Mon Jan 10 01:08:27 2011 from 158.162.131.50
[root@domU-18-33-35-0B-D5-02 ~]#

 

How to install ec2-api-tools for fedora
How to install ec2-api-tools for fedora

If you are still facing issue then write to me.

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.

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

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