Archive | video & PHP RSS feed for this section

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:

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. 🙂 🙂

Process video with php – my experience and some advice for you!

9 Aug
images3.jpg Why youtube is so popular!!! Every body will agree with me if I say “They make video available for people”.Actually what youtube does? They were successful to render video quickly because they convert a video file (mpeg, mov, avi) to flash movie (flv) file.
I was really excited when I developed some youtube clones. Till now those project are the finest project in my archive. Editing video with php was an interesting job.I used Mpleyer, Mencoder and Flvtool2 as a 3rd party tool.http://www.mplayerhq.hu is providing mplayer and mencoder freeware. This is linux based project on video editing. And very useful for video encoding. windows base version is also available there.I used mencoder to convert video files to flv and generate thumbnail. Creating Thumbnail was a great exciting moment for me indeed!Mpleyer follows linux based path system. When a programmer start working with it in windows platform should keep in mind if he starts path parameter with slash (/) the output will generate in root directory( commonly C:/ or some time in windows folder). To get the stress out form you head it’s better to use full path of the media files.Now the task is to get the duration of the video. I used Mplayer to finish this event. This is very easy but I was in stress because I forgot to turn off the CPU sound. So you guys should include ” –nosound ” this simple text with the command string.I thought my work was done there. But my site owner was not satisfied with the quality. Because the size of the files was bigger than he expected. Then I used Flvtool2 to increase the quality. Actually Flvtool2 is a manipulation tool for Macromedia Flash Video files (FLV).

Success always put smiles on ur face automatically. This is what happened to my end result 🙂 it felt great when my site owner became happy like me. I hope guys who will try will always enjoy this kind of moment.
🙂