Openrtmfp/Cumulus development Note (5) Playing cumulus real-time video streams

Source: Internet
Author: User
Tags addchild

1. Define a window class:

Package

{

ImportFlash. display. Sprite;

Public class
LayerExtendsSprite

{

// Window layer

Protectedvar
_ Windowlayer: SPRITE;

Publicfunction
Layer ()

{

Init ();

}

Privatefunction
Init ():Void

{

_ Windowlayer =NewSprite ();

Addchild (_ windowlayer );

}

/**

* Window layer

*/

Publicfunction
Get
Windowlayer (): Sprite

{

Return_ Windowlayer;

}

}

}

2. Declare a container variable:

Private var_container: SPRITE;

3. assign a value to the container variable:

PublicfunctionSetcontainer (container: SPRITE ):Void{

_ Container = container;

}

4. Play a video:

PublicfunctionPlayvideo ():Void
{

Buf. resetvideo ();

VaRVideo: Video =New
Video ();

Video. attachnetstream (BUF. NS );

_ Container. addchild (video );

}

Note: Buf is a custom video processing class, which requires the relevant netstream member variable. It is processed when a frame-by-frame video data is received, usage method _ ns. appendbytes (videoframe. streamdata );

Play the received real-time video frame, and the video class is mainly used to display the video, that is, the method video. attachnetstream (BUF. NS); the video class is associated with the relevant netstream

5. generally, the received video frame data does not contain the FLV Header Format, while the video data in the FLV format needs to be played in ActionScript. Therefore, the FLV header information must be added to the video, as follows:

VaRFirsttag: bytearray =New
Bytearray ();

Firsttag. endian = endian. big_endian;

// Video

Firsttag. writebyte (0x09 );

Firsttag. Position = 11;

// 4 bits: type of frame 1 => key frame + 4 bits: codecid 7 => AVC

Firsttag. writebyte (0x17 );

// Avcpackettype 0 => AVC sequence Header

Firsttag. writebyte (0x00 );

// Composition time, 3 bytes 0 for the firsttag

Firsttag. writebyte (0x00 );

Firsttag. writebyte (0x00 );

Firsttag. writebyte (0x00 );

// Todofirsttag. writebytes (avccfg );

VaRFirsttaglen: uint = firsttag. length;

Firsttag. writeunsignedint (firsttaglen );

Firsttag. Position = 1;

// 3-byte datasize

Firsttag. writebyte (firsttaglen-11)> 16) & 0xff );

Firsttag. writebyte (firsttaglen-11)> 8) & 0xff );

Firsttag. writebyte (firsttaglen-11) & 0xff );

PS: I wrote an article at the beginning. Please forgive me. If you have any questions or communication, you can add your YY: 301558660

Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8165662

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.