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:
http://www.mplayerhq.hu/design7/news.html
http://www.mplayerhq.hu/design7/dload.html
We use FLVTool2 to optimize the video. We can download it form here
https://rubyforge.org/projects/flvtool2/
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
<?php
// 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
<?php
$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
<?php
//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);
while(list($k,$v)=each($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.
<?php
//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″;
exec($cmd);
}?>
I think you guys will understand the minimum process to convert a non-flash movie file to flash and will enjoy it.
Mentors Award Q3 2008
Top Website Coder