Convert a Non-flash movie to FLVideo

24 Jan

In my last post about Flash Video I gave a gross idea. But now it seems too brief as some of my friends facing problem on the total process.

To convert a Non-Flash Movie file to flash generally we follow two steps. First we convert the file to flash video and then we optimize it to make it compatible for all flash players for good streaming. FFMpeg, MPlayer & MEncoder, Flix Engine are popular converter for Flash Video. I used Mplayer for one of my project. It is an open source LAMP based Project. You can download it from following links:

We use FLVTool2 to optimize the video. We can download it form here

Basically we execute some shell command with php to do all stuff. To convert the file to flash video we have to set Mncoder ( Available in Mpalyer Package )path, source media file and output media file( with .FLV extension). I compiled it with following code


// Media source path
$src = ‘video/src/abc.avi’;

// Flv file path
$des = ‘video/compiled/abc.flv’;

// This is the Mencoder Path
$midea_converter_path = ‘/home/mpleyer/mencoder’;

exec(“$midea_converter_path $src -o $des -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=9600:mbd=2:mv0:trell:v4mv:cbp:last_pred=0 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -srate 22050”);


After finishing the process we can generate a flv easily. After first compilation generally file size become larger and we faced some problem in streaming. We can optimize the file by Flvtool2. See the following code


$metainject_converter_path =’/home/mplayer/flvetool2

$flv_src1 =’video/compile/abc.flv’;

$flv_src2 =’video/archive/abc.flv’;

$s = exec(“$metainject_converter_path $flv_src1 $flv_src2”);


Now our flash video is ready to use. Then I like to do something more like generate thumbnails, video runtime etc. MPlayer can analyze video to get this information. See the following code to get runtime


//Mplayer path
$mplayer_path = ‘/home/mplayer/mplayer;

// Media source path
$src = ‘video/src/abc.avi’;

exec(“$mplayer_path -vo null -ao null -frames 0 -identify $src”, $p);


if($length=strstr($v,’ID_LENGTH=’)) break;


$data = explode(“=”,$length);

$duration = $data [1];


After executing this command we get several information in ‘$p’. Here I picked the duration of the video.

Generating thumbnails is another one interesting task. We can take snap after specific time duration. This segment of code generates tow thumbnails for each 10 different snaps.


//MPlayer Path
$mplayer_path = ‘/home/mplayer/mplayer;

// Temp directory to where mplayer create thumbnails ( .jpeg format)
$src_temp = ‘video/temp’;

// Media source path
$src = ‘video/src/abc.avi’;

$total_thumb = 10;

$frame_rate = floor($duration/$total_thumb);

for($i=1;$i<$ total_thumb;$i+=$frame_rate)

$cmd = “$mplayer_path $src -ss ” . $i . ” -nosound -vo jpeg:outdir=$src_temp” . ” -frames 2″;


I think you guys will understand the minimum process to convert a non-flash movie file to flash and will enjoy it. 🙂 🙂


16 Responses to “Convert a Non-flash movie to FLVideo”

  1. sumon January 24, 2008 at 10:43 am #

    Rubel vai, This is a good solution. I tried with this compilation precess solution and after compilation, I found .FLV files are much lighter in weight and loading and streaming is faster than previous one. Good job man!!!!

  2. uzzal January 24, 2008 at 10:46 am #

    great! very important thing for php programmers. 🙂

  3. Musa January 24, 2008 at 10:48 am #

    Its a really easy way to convert other movie to flash movie. One of my collegue used this tech and got a good result although he was facing problem with large size file. I think that problem would be solve if that site hosts on streaming server.

    Thanks, it will be very helpfull to all.

  4. Rubel January 24, 2008 at 10:51 am #

    @Musa Bhai,

    Thnx, If you want to get more fruitfull output even to put water mark in your video. You can use flix Engine. 🙂

    But this is paid.. 😦

  5. Jewel January 24, 2008 at 12:07 pm #

    Good job rubel bhaii. actually it’s help a lot those are working with video.keep up your good works. 😀

  6. Rubel January 24, 2008 at 12:13 pm #

    🙂 🙂

  7. junal January 24, 2008 at 12:31 pm #

    bookmarked !! will help me in future 🙂 – thanks lubel bhai …ooppss rubel bhai 🙂

  8. Jewel January 25, 2008 at 9:07 am #

    Rubel Bhai

    When i want to optimize the file size i got a message like This what it is?
    File size still same as before.
    Message is :’Powered’ is not recognized as an internal or external command,
    operable program or batch file.

  9. Rubel January 25, 2008 at 12:06 pm #

    @ Jewel,

    Optimization is so simple if you can install flvtool2 perfectly.. See the function i used in my project

    I sent $des in tow times because. I just want ok compile my flv and optimize it in same place..

    Just execute the code correctly. 🙂

  10. aman January 31, 2008 at 12:14 pm #

    This is very good information. Now suppose I want to add water marking to the video. How do I do that ?

  11. Rubel January 31, 2008 at 3:32 pm #

    @ Amran

    You can do it using flix engine…:)
    But it’s paid.. 😦

  12. jobo April 11, 2008 at 1:09 am #

    this seems like a really good way of converting to flv, allthough I still can’t get it working 😦

    $midea_converter_path = ‘/home/xx/xx/app/plugins/mplayer/mencoder’;
    exec(“$midea_converter_path $src -o $des -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=9600:mbd=2:mv0:trell:v4mv:cbp:last_pred=0 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -srate 22050”);

    the above code doesnt seem to make the $des file, and I get no errors… any ideas ?

  13. rubel April 11, 2008 at 5:13 am #

    You have to put exact location of $midea_converter_pat $src and $des.

    I will not show any error because this command will not generate any PHP error. If you want to see you can try on command line.

  14. Maye July 27, 2008 at 2:59 am #

    i do have a problem in installing the flvtool2 and having a problem with the command prompt. it shows that flvtool2 is is not recognized as an internal or external command,
    operable program or batch file. What shall i do about this to run it in my using vista and its not working very well. thank you in advance 🙂

  15. Rubel July 27, 2008 at 5:01 pm #

    Well… You need to compile the .flv file..

    Did you get the .flv output from MEncoder correctly…

  16. Lorenz February 8, 2010 at 1:47 pm #

    Hi, thanx a lot for this information. I’m working on a project dealing with video and really helps..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: