Monday, June 22, 2009

How to use FFMPEG

FFMPEG is a very power full tool for video manipulation. Mostly developers use the different command to convert video from one format to another e.g ( avi to flv ) . Mostly developers search different type of command via search engines e.g google.com . Exert of FFMPEG use the different parameters for different scenarios. The purpose of this blog to write down common command that will be very useful while developing video sites.

1- Live Stream Conversion

In Window

ffmpeg.exe -i http://serveraddress/streamvideo.asf -target ntsc-dvd -aspect 1.3333 -s 176x108 yourvideo.flv

In Linux

exec('/user/bin/ffmpeg -i http://serveraddress/streamvideo.asf -target ntsc-dvd -aspect 1.3333 -s 176x108 yourvideo.flv');

2- Creat Movie from Images

Note: Your folder contain images with discrete unique name e.g image1, image2, image3.....
In Window

ffmpeg.exe -r 2 -i images/image%d.jpg -ar 22050 -s 320x240 -aspect 4:3 -f flv ' yourflvname.flv

In Linux

exec('/usr/local/bin/ffmpeg -r 2 -i images/image%d.jpg -ar 22050 -s 320x240 -aspect 4:3 -yourflvname. flv '.$movie_Store_Path,$output,$return);

3- Get the single Frame of Specific movie Time

$curFrameTime = "00:00:05";
exec('/usr/local/bin/ffmpeg -i yourfile.flv -an -ss '.$curFrameTime.' -an -r 1 -vframes 1 images/img%d.jpg');

4- Get multiple frames from movie
exec('/usr/local/bin/ffmpeg -i ./yourfile.wmv -an -ss 00:00:01 -t 00:01:31 -r 10 -s 550x450 -aspect 5:3 ./img/%d.png',$output,$result);

4- Avi to flv Conversion

exec('/usr/local/bin/ffmpeg -i ./youravifile.avi -pass 2 -s 448x336 -ab 56k -ar 22050 -ac 1 -vcodec flv -b 500k -g 160 -cmp 3 -subcmp 3 -mbd 2 -flags aic+cbp+mv0+mv4+trell -y yourfilename.flv',$output,$result);

5-Remove the Audio Stream

Let's say you have recorded a video that has a lot of background noise and undesired commentary, so you decide to remove the audio component of the video completely. To accomplish this, all you have to do is add the -an option to the command line, and FFmpeg automatically removes all audio from the output. Keep in mind that using this option negates any other option that affects the audio stream.

So, in our example, to remove the audio component, we would run the following command:

exec('/usr/local/bin/ffmpeg -i InputFile.mpg -an -b 1200 OutputFile.avi');


5-Remove the Video Stream

Let's say you downloaded a news video from the Net that you want to listen to on your iPod on the way to work, but in order to do that, you have to remove the video component from the output file. FFmpeg allows you to remove the video component of the file completely by adding the -vn option to the command line. Using this option negates any other option that affects the video stream.

So, in our example, to remove the video component and save the audio as a 256kbps MP3 file, we would run the following command:

exec('/usr/local/bin/ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3');

6-Extracting sound from a video, and save it as Mp3
This is very easy command to extract audio from video file .

ffmpeg -i inputVideo.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 outputFile.mp3

Mencoder:

7.Combine two flv using mencoder
A very simple command to combine two flv.
mencoder.exe -fps 29.97 1.flv -fps 29.97 2.flv -o combine.flv -of lavf -ovc copy -oac copy

8-Remove the video from file.
In order to remove video from file; ffmpeg allow to remove video component completely by
adding -vn in command line.

ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3


9- How to get Movie Time using FFMPEG

Following is very useful PHP function to get the movie duration.


function duration($videofile)
{
ob_start();
passthru("ffmpeg.exe -i \"". $videofile . "\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();
preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];
return($duration);
}

Wednesday, April 1, 2009

how to use flash with php

So you want dynamic content on your Flash movie. Sounds simple, right? Well let me tell you that it is, and well, it isn't. This tutorial assumes a basic knowledge of Actionscript, PHP and MySQL. If you have that, it's time to move on. Otherwise, I recommend you do some reading on the subjects...

Setting Up your SWF


Loading external data into an SWF is a fairly simple task. Although the external text file method is probably the most widely known, it is by far the clumsiest way to get data into your SWF. Of course, this may be your only option if your server doesn't support MySQL/PHP! But for those of us who are fortunate to have these privileges, let me show you how Flash can get external data without having to create additional text files.

Dynamic text fields

In order for Flash to get data from an external source, you need to make use of dynamic text fields. Simply place a blank dynamic text field on the stage and make sure you give it a variable name (NB: dynamic text fields have both an instance AND a variable names. In this case we want to focus on the variable name). Note the name you give to the field's variable name, as we'll need it when we write our PHP script.

Once you have a text field setup, convert it to a movie clip symbol. Attach the following code to the resulting movie clip

onClipEvent (load) {
//assuming you have a personal web server and PHP installed locally
loadVariables("http://localhost/test.php", this, "GET");
}

Ok, that's probably the easiest part of all. Now on to the PHP.

Writing the PHP script that will pass variables to your SWF
To pass a variable between PHP and you SWF, it is imperative that you know the name of the variable you want to populate within your SWF. Again, when I say variable name, I'm talking about a dynamic text field's variable, not instance, name. As long as you keep that in mind, you should be alright.

The PHP script we'll write is actually quite simple. All you need to do is use the print() function, whose output will be automatically passed to your SWF. As simple as this may seem, be warned that Flash needs to know which variable to populate with the data output from our script. In other words, we need to print the name of the variable attached to the dynamic text field we created earlier. This is a crucial step but is very simple to achieve. I've included an example below on how we would code this in PHP:



Like I said, simple concept but easy to forget.

If you've ever tried getting external data into your SWF from a text file, you'll notice that the two methods are very similar. PHP has a great advantage though in that you can use things like arrays, loops and even functions with which you can access information from within a database. The last of which will be the focus for the rest of the tutorial