Wed 29 Nov 2006
How to Create a Streaming Flash Video Player Using Ming PHP or Ruby
Posted by carson under php , ruby , utilitiesI mentioned in creating Flash videos using FFMpeg that you could use Ming to create your own Flash video player. I've added a patch to the ruby -ming extension for video streaming so now it is possible to create a streaming player with both PHP and Ruby using their Ming extensions. The following examples show you how.
First a little background. You can read about playing back external FLV files dynamically with actionscript at the Macromedia website. It includes references to the NetConnect class and NetStream class that together let you stream a FLV file. The main thing Ming does for you in the following simple examples is give you a SWF with a video player in it and let you attach some action script to it.
Here is how you do it in PHP:
Ming_setScale(10.0000000);
ming_useswfversion(7);
$movie = new SWFMovie(7);
$movie->setDimension(320,240);
$movie->setBackground(0×33,0×33,0×33);
$movie->setRate(8);
$strAction = "
stop();
netConn=new NetConnection();
netConn.connect(null);
vStream=new NetStream(netConn);
video1.attachVideo(vStream);
vStream.setBufferTime(10);
vStream.play('http://localhost/test.flv');
";
$stream = new SWFVideoStream();
$item=$movie->add($stream);
$item->setname("video1");
$movie->add(new SWFAction($strAction));
$movie->nextFrame();
$movie->save("videostream.swf");
?>
And here is how you do it with Ruby:
require 'ming/ming'
include Ming
Ming::set_scale(10.0000000)
movie = SWFMovie.new(7)
movie.set_background(0xff, 0xff, 0xff)
movie.set_dimension(320, 240)
movie.set_rate(8)
strAction = '
stop();
netConn=new NetConnection();
netConn.connect(null);
vStream=new NetStream(netConn);
video1.attachVideo(vStream);
vStream.setBufferTime(10);
vStream.play(\'http://localhost/test.flv\');
'
vstream = SWFVideoStream.new
item = movie.add(vstream)
item.set_name("video1")
movie.add(SWFAction.new(strAction))
movie.next_frame()
movie.save("videostream.swf")
Here is the result of the above examples:


















December 9th, 2006 at 3:58 pm
[...] Now that you can create a streaming Flash video player with PHP or Ruby and you know add metadata for cuepoints to Flash videos you are ready for something else. The following code will show you how to create a video player with PHP that will watch for metadata events and display annotations contained inside the metadata either over the video itself or in a div on the same page as the movie. [...]