shengsoft

聆听代码的音符

导航

flv方面的资料

最近在研究flash视频方面的资料,想实现youtube的功能。发现了一些好文章,与感兴趣的朋友分享。


Collected links to Flash Video Encoding Tools & Related
这是我收集的一份列表,自认为比较完整,希望对大家有所帮助.
如果你知道更多,欢迎补充啦!
客户端编码工具(Client-Side-FLV-Encoding)
场景:拿到一个 MPG 或 AVI 文件,打算在个人电脑上转换成FLV.
1,Sorenson Squeeze (http://www.sorensontech.com/solutions/prod/mx_win.php)
2,Riva FLV Encoder (http://www.rivavx.com/index.php?encoder&L=3)
3,Turbine Video Encoder (http://www.blue-pacific.com/products/turbinevideo/default.htm)
4,Flix Exporter (http://www.on2.com/consumer/flix-exporter/)
5,SWiSH Video (http://www.swishzone.com/index.php?product=video)
6,Flash 自带的Flash Video Exporter (http://www.macromedia.com/devnet/flash/articles/flv_exporter_print.html)



服务器端转换工具(Server-Side-FLV-Conversion)
场景:想把 MPG 或 AVI 上传到你的服务器并自动转换成 FLV 吗?
1,FFmpeg (http://sourceforge.net/projects/ffmpeg) | 教程一 (http://soenkerohde.com/tutorials/ffmpeg) | 教程二 (http://klaus.geekserver.net/flash/streaming.html)(Google Video 使用的就是这个东东.)
2,Flix Engine (http://www.on2.com/developer/flix-engine-sdk) | 教程 (http://www.flexauthority.com/articlesIndex.cfm) | 范例 (http://www.flexauthority.com/Samples/FlixEngine/index.html)
3,Turbine Video Engine (http://www.blue-pacific.com/products/turbinevideosdk/default.htm)
4,Video to Flash Console (http://www.geovid.com/Video_to_Flash_Console)

录像/实时广播(Record/Broadcast)
场景:想制作一个语音视频Blog满足自恋的欲望吗?
1,RED5 (http://www.osflash.org/red5)
2,Flash Media Server (http://www.macromedia.com/go/fms)
在线编码,分享视频(Online Encode & Share)
场景:想不花钱就可以在线分享你的视频吗?
1,Google Video (http://video.google.com/)
2,You Tube (http://www.youtube.com/)
本地 FLV 文件播放器(FLV Player)
场景:拿到了 FLV 文件不知道怎么播放了.
1,martijndevisser FLV Player (http://www.martijndevisser.com/2005/10/flv_player_updated.html)
2,FlashGuru FLV Player (http://www.flashguru.co.uk/free-tool-flash-video-player)
3,FCZone FLV Player (http://fczone.com/2006/01/fms-media-player.cfm)
在线 FLV 文件播放器(Online FLV Player)
场景:知道一个在线FLV地址,又懒得下载和安装播放器.
1,Loadr (http://dengjie.com/loadr)
2,Google Player Generator (http://dengjie.com/loadr/r.swf?file=/temp/google_player.swf&clr=000FFF)
更多相关软件看这篇文章:Flash 网站的视频策略 (http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14571)
-------------------------------------------
Video and Audio Streaming with Flash and Open Source Tools

Flash has always been developed and used for multimedia purposes, but until version 6 the possibilities for audio streaming were limited and also there was no video support. With Version 6 and 7 Macromedia introduced video support and a new file format to support various ways of streaming. This article covers only a streaming variant called "progressive download" which does not need server support. True streaming support is available with Macromedia's non-free Flash Communication Server (FCS).
FLV Streams
Streaming is build upon a new file format called FLV, which separates the streamable content and the flash movie. The result is a very compact flash movie acting as a multimedia player and a storage for streamable content from which the flash movie loads a stream on demand.

A single FLV stream contains at most one audio stream and at most one video stream. Flash supports uncompressed sound and various compressed formats like MP3 and ADPCM as well as the proprietary Nellymoser audio codec. With flash version 6 Macromedia also introduced video support for flash. In version 6 only the Sorenson H.263 video codec was supported which is a slightly modified version of the open H.263 standard. The latest flash version 7 introduced a second video format "Screen Video", which is a simple, loss less video format, especially developed for screen capturing.

Converting and Creating Content
One method for creating FLV streams is converting existing audio and video content with FFmpeg [ffmpeg.sourceforge.net]. FFmpeg is a mature and very excellent software project for converting audio and video from and to various formats. Converting a video can be simply done with

ffmpeg -i infile.[avi|mpeg] stream.flv

FFmpeg uses the Sorenson H.263 video format for encoding video data. There is no support for the Screen Video format at this time. While the Screen Video format is mainly useful for screen capturing applications, Sorensons H.263 is multipurpose video codec with good compression rates, suitable especially for encoding motion pictures.

Another project dealing with FLV streams is called libflv [libflv.sourceforge.net]. While FFmpeg is a general audio and video converting suite, libflv is focused on working with FLV streams. The project is still in a very early stage, but is able encoding videos in the Screen Video format and allows simple FLV stream manipulations like (de-)multiplexing of audio and video streams. A simple GTK-based screen capturing application can be found in the example directory.

Building a Simple Multimedia Player
After having created some streamable content, a flash multimedia player is needed. One huge advantage of flash based players over other plug-in based multimedia-players is that there are no constraints about its look and how it is integrated in your sites design.

MING is an open source library which is able to create flash files with almost all recent flash features, including Action Script, sound and video support. The library also has language bindings for a bunch of script and programming languages. The examples presented in this article are written in PHP4. Porting the examples to other supported languages like C/C++, Java, Python or Perl should be trivial.

To run the following example a current CVS snapshot of MING is needed. It is available either via Sourceforges anonymous CVS service or pre-packaged at klaus.geekserver.net/ming/.

First we create a new move instance and set dimension and background color:

ming_useswfversion(7); $movie=new SWFMovie(7); $movie->setDimension($width, $height); $movie->Background($r,$g,$b);

The new flash move can now be filled with flash objects called characters. For the multimedia player example we create a video canvas object and add it to the movie. The add() method takes a character and inserts it to the current frame and returns a handle to the object. This can be used to move, rotate, resize or remove an object. If the object is going to be used with ActionScript, a name can be assigned to it.

$stream = new SWFVideoStream(); $stream->setDimension($width, $height); $item = $movie->add($stream); $item->moveTo($x, $y); $item->setname("video");

The SWFVideoStream() constructor can also take a FLV file as argument. In this case the video stream will be embedded to the flash file. However this approach has some drawbacks. First of all the resulting flash movie will get as least as big as the stream. But also the stream's frame rate must not exceed the flash movies frame rate and each flash file is limited to 16000 frames, which means that the embedded stream can contain at most 16000 frames.

A multimedia player application should be able to load and play streams dynamically. Therefore the SWFVideoStream() constructor is called with no arguments. Thus only an empty video canvas will be created, which will be controlled by the following ActionScript code:

connection = new NetConnection(); connection.connect(null); stream = new NetStream(connection); video.attachVideo(stream); stream.setBufferTime(10); stream.play('http://localhost/mystream.flv');

The ActionScript first creates a pseudo connection by passing null to the connect() method of the NetConnection object. In contrast, a real connection to a Macromedia streaming server can be made by passing a valid url to the method. Having a NetConnection instance a new NetStream object can be created and attached to the empty video canvas. This object handles streaming and provides methods for controlling the stream. The above example loads a FLV stream from the local web server with a downloadbuffer of 10 seconds. The ActionScript code can be compiled and added to the movie with:

$action = new SWFAction($action_string); $movie->add($action);

Until now the flash movie just loads and plays a certain FLV stream. To control its behavior, a simple user interface consisting of some buttons and a seek-slider is missing. Flash has its own compressed loss less bitmap format called DBL. MING provides a small utility png2dbl to convert PNG images to DBL. Such images are used for the player's control buttons:

$button = new SWFButton(); $flags = (SWFBUTTON_UP | SWFBUTTON_HIT | SWFBUTTON_OVER | SWFBUTTON_DOWN); $button->addShape(ImageShape("images/pause.dbl"), $flags); $action = new SWFAction("stream.pause();"); $button->addAction($action, SWFBUTTON_MOUSEDOWN); $button_ref = $movie->add($button); $button_ref->moveTo($x, $y);

The above example creates a pause button for the multimedia player. An interactive button is created in two steps. First its look has to be defined by adding shapes for certain mouse events. In flash a shape is the basic representation for graphic objects. For each mouse event a different shape object can be assigned to the button. In the above example the button looks always the same.
In the second step the buttons action can be defined by assigning ActionScript to a special event.

One drawback using progressive download streaming without server support is that there is no possibility to get the stream's total length. Therefore the seek-sliders functionality is limited to seeking within the already loaded parts of the stream.

The dragable part of the seek-slider is realized as a movie-clip object. A movie-clip is running as an independent movie in the flash movie. It has an independent time line, can handles scripts and handles external events itself.

$mc = new SWFSprite(); $shape = new SWFShape(); $shape->setLine(4,25,0,0,128); $shape->movePenTo(0, 5); $shape->drawLineTo(0, 10); $mc->add($shape); $mc->nextFrame(); $slider = $movie->add($mc); $slider->moveTo($xMin, $y);

A movie clip (SWFSprite) has similar methods like a movie object. The add() method inserts a flash object to the current frame, nextFrame() finishes the current frame and creates a new one. The movie clip is also a normal flash object which can be added to a movie and placed on the stage. The functionality of the seek-slider is defined by three small scripts. The first two actions make the movie-clip dragable:

$a = new SWFAction("startDrag(this, $xMin, $y, $xMax, $y, 1); drag = true;"); $slider->addAction($a, SWFACTION_MOUSEDOWN); $a = new SWFAction("stopDrag(); drag=flase;"); $slider->addAction($a, SWFACTION_MOUSEUP);

The third more lengthy script sets the stream position depending on sliders x-position if the slider is actually moved by the user or sets the sliders x-position depending on the streams current time:

// width in px width = xMax - xMin; paused = false; if(drag) { // pause stream while seeking _global.stream.pause(true); paused = true; x = _root._xmouse - xMin; seekTo = (_global.streamLen / width) * x; _global.stream.seek(seekTo); } else { pos = (_global.stream.time * (width / _global.streamLen)) + xMin; this._x = pos; this._y = y; } // restart paused stream if(paused) { _global.stream.pause(false); }

This script is assigned to the $slider-handle with the SWFACTION_ENTERFRAME event.

After having added all elements to the flash movie the first frame has to be closed with the nextFrame() call. Since we don not need another frame the movie can also be finished:

$movie->nextFrame(); $movie->save("FLVPlayer.swf");

The resulting multimedia player


Example Video: Copyright by Thilo Weigel, University of Freiburg
Conclusion
With flash it is easy to create a lightweight, fully customized, embedded video and audio player. There are powerful open source tools available for creating content and also creating flash movies. This article introduced the basic concepts of flash streaming and working with MING. The here presented mediaplayer provides only the most basic features and was only intended as a simple example. It can be extended in many ways, which is left to the reader.


posted on 2006-07-06 12:14  盛国军  阅读(2420)  评论(1编辑  收藏  举报