BSD license FREE

The BSD license is an
open-source license.
Read full license

You need to log-in or create an account
  • Create an account
  • Log-in
  • Please use your real name.
  • Account activation link will be sent to this address.
  • Minimum 8 characters

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

Price: FREE

View Pricing 14 days money-back guarantee

FLV Parser

Read, Write, Parse, Stream and manipulate meta tags in FLV Containers on the fly

Share and win up to $15k in prizes each month!Learn more

Share

Description

The FLV Parser makes use of the NetStream.appendBytesAction and NetStream.appendBytes methods to pass the parsed FLV tags from the ByteStream.

When a NetStream object enters "Data Generation Mode" you can write your own video / audio / meta tags to the stream.

The FLV class makes it possible by providing several methods for manipulating meta tags:

UpdateBuffer(buffer:IDataInput)
WriteHeader(flags:int=0)
WriteMetaTag(object:Object, event:String='onMetaData')
WriteTag(type:int, body:ByteArray, timestamp:uint=0, timestampExt:uint=0, streamId:uint=0)
Seek(time:Number)
GetTagsOnTime(time:Number) : Array
MergeFLV() : ByteArray

In addition the FLV class takes care of all the usual NetStatus events, so you can use the constructed NetStream object as any other.

Back to top

Documentation

FLV Class

Properties:

isComplete - indicates the buffer, if full = true, else = false clearBufferOnComplete - clears the flv buffer when parsed header - ByteArray tags - Array of FLVTag objects

Methods:

Seek(time:Number) : void

Seeks the buffer to the specific time in seconds

GetTagsOnTime(time:Number) : Array

Returns an array of tags after a specific time (use for seeking)

UpdateBuffer(buffer:IDataInput) : Array

Updates the FLV buffer and returns the parsed tags (use for progressive streaming)

WriteHeader(flags:int=0) : ByteArray

Writes the FLV header bytes and returns a FLVHeader object

WriteMetaTag(object:object, event:String='onMetaData') : ByteArray

Writes a meta data tag to the stream and returns a FLVTag object

WriteTag(type:int, body:ByteArray, timestamp:uint=0, timestampExt:uint=0, streamId:uint=0) : ByteArray

Writes a FLV tag to the stream and returns a FLVTag object

MergeFLV() : ByteArray

Returns a merged version of all FLV tags as 1 ByteArray

Complete() : void

Call this method when progressive streaming is finished

Back to top

Example

import com.ivoyankulovski.FLV.FLV;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.net.URLStream;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.media.Video;
import flash.utils.setTimeout;

/*
* Remote FLV Streaming
* Uses 1 ByteArray to parse and construct two different NetStream objects
*/

function CreateFLV() : Object
{
    /*
    * Enter Data Generation Mode
    */

    var connection:NetConnection=new NetConnection();
    connection.connect(null);
    var netStream:NetStream=new NetStream(connection);
    netStream.play(null);

    /*
    * Config NetStream
    */

    netStream.client={
        onMetaData:function(data:Object) : void{

        }
    }

    /*
    * Create the FLV Instance
    */
    var flv:FLV=new FLV(netStream);

    /*
    * Create a video object to render the video
    */

    var video:Video=new Video();
    addChild(video);
    video.attachNetStream(netStream);

    return {flv:flv, video:video, netStream:netStream};
}

var container1:Object=CreateFLV();
var container2:Object=CreateFLV();
container2.video.x=400;

var delay:Number=1000;

/*
* Create a URLStream object to parse as ByteArray
*/

var urlStream:URLStream=new URLStream();
urlStream.addEventListener(ProgressEvent.PROGRESS, onStreamProgress);
urlStream.addEventListener(Event.COMPLETE, onStreamComplete);
urlStream.load(new URLRequest('sample.flv'));

function onStreamProgress(event:ProgressEvent) : void
{
    var tags:Array = container1.flv.UpdateBuffer(urlStream);
    setTimeout(function () : void{
        var tag:ByteArray;
        var l:int=tags.length;
        var remoteTag:ByteArray;
        for(var i:int=0;i

Questions & Comments

Leave a comment

You must be logged-in to leave a comment.
Log-in now or register for a free account.
No comments have been posted yet.
You must be logged-in to vote. Log-in to your account or register now.

User Reviews

No reviews have been submitted yet.

Price: FREE

View Pricing 14 days money-back guarantee