ByteArray Access to NetStream in Flash Player 10.1

There are moments like this, when you read the documentation of the Flash Player and you discover and nice new API that you have been waiting for such a long time. Do you see what I mean ? Yes, you read it right, ByteArray access to NetStream class is coming and it works beautifully in Flash Player 10.1. As many of you, I was also waiting for this API when working on my FLV editing library and this day has come.

The API is called appendBytes on the NetStream class used in conjunction with the NetStreamAppendBytesAction class. It allows you to inject a ByteArray to the NetStream object and play the video. This API was designed originally for HTTP streaming, allowing forward seeking into HTTP delivered-video, but if you just load a ByteArray locally  through the FileReference API, voilà, you got local preview of video files without server round trip. If you read the documentation you'll notice that the API only works for now with FLV header-based files, but all codecs are supported (Sorenson, H.264, On2 VP6 and even AAC audio).

Here is a little demo which illustrates the API in the Flash Player 10.1 (make sure you are using the Flash Player 10.1 RC4 available on :

A Flash animation should have appeared here, but it seems that your browser has an older version of the Flash Player or it is not installed at all. Please, install the last release of the Flash Player now, then reload this page.

The API is really simple :

// retrieve the FLV stream
var bytes:ByteArray =;
// put the NetStream class into Data Generation mode; 
// before appending new bytes, reset the position to the beginning 
// append the FLV video bytes

This will allow new kind of apps and remove one more limitation that we had in the past ;)

Comments (42)

  1. Very exciting! However, I’m getting an error when trying out the example:

    ReferenceError: Error #1069: Property appendBytesAction not found on and there is no default value.
    at TestAppend/onComplete()

    Wednesday, May 12, 2010 at 10:08 am #
  2. Hey Thibault, some days ago I tried that new api. I wanted to use the bytearray access for broadcasting audio files(like aac or mp3) in Air to a RED5 server and than the red5 server would send it to its clients(also in air). But I failed to do this with the appendbytes. Do you know if this is possible with the appendbytes method? Big thanks, Maxim Gladines

    Wednesday, May 12, 2010 at 10:09 am #
  3. Dude, this is fucking amazing… My mind is buzzing with the possibilities this opens up!!
    Thanks :)

    Wednesday, May 12, 2010 at 10:16 am #
  4. why wrote:

    it really sucks that you cant use this with different headers than flv. It’s a very nice feature anyway.

    Wednesday, May 12, 2010 at 10:22 am #
  5. Drew wrote:

    Thanks for posting Thibault!

    I have a situation where I need to read from huge files starting at varying points and until user hits stop, however the files aren’t streamed in the normal way so everything tries to download.

    I wanted to use a bytearray to control the download and feed an Sound object in streaming mode, building up a buffer of a few seconds (since feeding blocks via SampleDataEvent.SAMPLE_DATA seems to often give crackly results). Any idea whether bytearrays can now be fed to Sound?

    Wednesday, May 12, 2010 at 11:51 am #
  6. This is very exiting, in fact we have been discussing this matter the last week and I was about to write my own NetStream class to make it work. This is the best news for some time (alot of good news has been pumping out from adobe lately so… :))

    @Simon, you must run 10.1 rc4 to make it work. I made a similar demo to the one Thibault posted and it works great!

    Wednesday, May 12, 2010 at 2:45 pm #
  7. Thibault Imbert wrote:

    Hi Maxim,

    Not at the moment, but this is something we are considering maybe for a future enhancement of this feature.

    Hi Drew,

    Unfortunately a Sound.loadBytes() API is not there yet. This one is also on my list and we know it would be a really valuable API. Please spread the word about this feature request and keep voting :

    It is the best way to make it happen ;)



    Wednesday, May 12, 2010 at 6:24 pm #
  8. Florian wrote:

    Thanks. I’ve posted an example with source code here:

    Thursday, May 13, 2010 at 12:03 am #
  9. Thibault Imbert wrote:

    Hi Florian,

    Sweet! It’s better with code you are right.

    Actually I just added a little code sample. You do not have to recreate the NetConnection object you can reset the pointer by calling the appendBytesAction APi and reset the parser.



    Thursday, May 13, 2010 at 12:24 am #
  10. Hi Thibault,
    What do you say by “You do not have to recreate the NetConnection object you can reset the pointer by calling the appendBytesAction APi and reset the parser” ?
    Can you show us a complete code
    Thanks a lot

    Thursday, May 13, 2010 at 7:19 am #
  11. Thibault Imbert wrote:

    Hi jeanphilippe,

    Florian’s code is complete. It’s just that it is not necessary to recreate the NetConnection and NetStream objects over and over. Just create those once, and reset the NetStream object by using the NetStreamAppendBytesAction API.



    Thursday, May 13, 2010 at 8:13 am #
  12. Benny wrote:

    Hi Thibault,

    first of all, thanks! This was exactly what i’ve been looking for!
    I do have an non-documented issue though.

    I am splitting the bitearray before reassembling and pushing it to the netstream, however, the appendbytes() (in a loop) breaks there.

    The ‘packs’ we send seem to only result in playback when the packs are at least half the size of the original file.

    So when we take a 1MB video file, split it into 2 byte arrays that we append in a foreach loop, it works. As soon as the byte arrays are less than half the video file, it does nothing…
    any idea if is this is a built in restriction, a bug or some faulty logic on our side?


    Saturday, May 15, 2010 at 6:36 pm #
  13. Ole jak wrote:

    So now we (for what ever reson we have) finaly can get speex encoded data from microphone when using P2P connection to for example save speex encoded audio file?

    Sunday, May 16, 2010 at 1:37 pm #
  14. charlierun wrote:

    Hi guys great news with this flash10.1 beta player Im trying to get my hands dirty on it. Im experiencing trouble calling netStream seek my video freezes,Im calling on Seek.Notify _ns.appendBytesAction(“resetSeek”) but its not working any ideas???

    Monday, May 24, 2010 at 4:05 pm #
  15. Bhanuprakash wrote:

    Hi Thibault Imbert,
    The new API appendBytes method on NetStream Object working fine for strictly FLV encoded files, When I use H.264 encoded ByteArray stream with FLV Header base file using appendBytes method on NetStream with Play(null), It’s neither giving any error message nor dispalying any video frame.
    Please give me suggession to solve my problem.
    and I already tracking a bug on Adobe.


    Tuesday, May 25, 2010 at 8:14 am #
  16. Bhanuprakash wrote:

    Hi Thibault Imbert,

    Is there any API( in ActionScript code ) embedding H.264 stream into FLV header base file (.flv)?. Because AppendByte mehtod of NetStream class works only for FLV header files.


    Wednesday, May 26, 2010 at 9:13 am #
  17. Laurent wrote:

    Hey Thibault,

    Is it possible to publish a netstream, to a rtmfp server that is created with this technique? Don’t seem to get that working.

    Friday, June 4, 2010 at 1:53 pm #
  18. JesusYamato wrote:

    Thanks to this post, i knew right away what i had to do : Make a MKV loader for Flash and now it’s done :

    Source is here :

    The source is way more advanced than the demo page, i haven’t updated it with the lastest svn yet :)

    Sunday, August 15, 2010 at 1:36 am #
  19. Jonas Nyström wrote:

    Does this make it (theoretically) possible to dynamically add/manipulate flv sound channels?

    Saturday, September 18, 2010 at 6:56 pm #
  20. Goabonga wrote:

    Merci :)

    package {
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;

    * @author BECKER Christophe
    public class Main extends Sprite {
    public var vid : Video;
    public var cam : Camera;
    public var bt : Sprite;
    public var txt : TextField ;
    public var boucle : int;
    public var flv_writer : FlvWriter;
    public var nc : NetConnection;
    public var responder : Responder;

    public function Main() {
    cam = Camera.getCamera();
    cam.setMode(640, 480, 15);

    bt = new Sprite();

    var sh : Shape = new Shape();×000000);, 0, 640, 20);;

    var txtFormat : TextFormat = new TextFormat();
    txtFormat.color = 0xffffff;

    txt = new TextField();
    txt.defaultTextFormat = txtFormat;
    txt.text = ‘click me for start video recorer’;
    txt.autoSize = TextFieldAutoSize.LEFT;
    txt.selectable = false;
    txt.x = (sh.width / 2) – (txt.width / 2);
    bt.y = 0;
    bt.addEventListener(MouseEvent.CLICK, run);
    vid = new Video(cam.width, cam.height);
    vid.y = 30;

    private function run(e : MouseEvent) : void {
    flv_writer = FlvWriter.getInstance();
    flv_writer.createFile(cam.width, cam.height, 5);
    bt.removeEventListener(MouseEvent.CLICK, run);
    txt.text = ‘recording’;
    txt.x = (bt.width / 2) – (txt.width / 2);
    this.addEventListener(Event.ENTER_FRAME, add_image);

    private function add_image(e : Event) : void {
    if (!cam.muted) {
    if (boucle == 25) {
    this.removeEventListener(Event.ENTER_FRAME, add_image);
    nc = new NetConnection();

    var ns : NetStream = new NetStream(nc);

    ns = new NetStream(nc);
    ns.client = {};
    ns.client.onMetaData = metaDataHandler;
    } else {

    private function metaDataHandler(meta : Object) : void {
    if (vid) {
    vid.width = meta.width;
    vid.height = meta.height;

    public function add_picture() : void {
    var img : BitmapData = new BitmapData(cam.width, cam.height);
    flv_writer.image = img;
    import flash.display.BitmapData;
    import flash.utils.ByteArray;
    Lee Felarca

    Singleton class to create uncompressed FLV files.
    Does not handle audio. Feel free to extend.

    Source code licensed under a Creative Commons Attribution 3.0 License.
    Some Rights Reserved.


    var myWriter:SimpleFlvWriter = SimpleFlvWriter.getInstance();
    myWriter.createFile(myFile, 320,240, 30, 120);
    myWriter.saveFrame( myBitmapData1 );
    myWriter.saveFrame( myBitmapData2 );
    myWriter.saveFrame( myBitmapData3 ); // etc.
    class FlvWriter {
    static private var _instance : FlvWriter;
    private var frameWidth : int = 320;
    private var frameHeight : int = 240;
    private var frameRate : Number = 15;
    private var duration : Number = 10;
    private const blockWidth : int = 32;
    private const blockHeight : int = 32;
    private var previousTagSize : uint = 0;
    private var iteration : int = 0;
    private var bmp : BitmapData;
    private var out : ByteArray;

    public static function getInstance() : FlvWriter {
    if (FlvWriter._instance == null)
    FlvWriter._instance = new FlvWriter(new SingletonEnforcer());
    return FlvWriter._instance;

    public function FlvWriter(singletonEnforcer : SingletonEnforcer) {
    out = new ByteArray();

    public function createFile(pWidth : int, pHeight : int, pFramesPerSecond : Number, pDurationInSeconds : Number = 0) : void {
    frameWidth = pWidth;
    frameHeight = pHeight;
    frameRate = pFramesPerSecond;
    duration = pDurationInSeconds;


    // create metadata tag

    public function set image(pBitmapData : BitmapData) : void {
    // bitmap dimensions should of course match parameters passed to createFile()
    bmp = pBitmapData;

    public function get byte() : ByteArray {
    return out;

    private function header() : ByteArray {
    var ba : ByteArray = new ByteArray();
    // ‘F’
    // ‘L’
    // ‘V’
    // Version 1
    // misc flags – video stream only
    // header length
    return ba;

    private function flvTagVideo() : ByteArray {
    var tag : ByteArray = new ByteArray();
    var dat : ByteArray = videoData();
    var timeStamp : uint = uint(1000 / frameRate * iteration++);

    // tag ‘header’
    // tagType = video
    writeUI24(tag, dat.length);
    // data size
    writeUI24(tag, timeStamp);
    // timestamp in ms
    // timestamp extended, not using ***
    writeUI24(tag, 0);
    // streamID always 0

    // videodata

    previousTagSize = tag.length;
    return tag;

    private function videoData() : ByteArray {
    var v : ByteArray = new ByteArray;

    // VIDEODATA ‘header’
    // frametype (1) + codecid (3)

    // blockwidth/16-1 (4bits) + imagewidth (12bits)
    writeUI4_12(v, int(blockWidth / 16) – 1, frameWidth);
    // blockheight/16-1 (4bits) + imageheight (12bits)
    writeUI4_12(v, int(blockHeight / 16) – 1, frameHeight);


    var yMax : int = int(frameHeight / blockHeight);
    var yRemainder : int = frameHeight % blockHeight;
    if (yRemainder > 0) yMax += 1;

    var xMax : int = int(frameWidth / blockWidth);
    var xRemainder : int = frameWidth % blockWidth;
    if (xRemainder > 0) xMax += 1;

    for (var y1 : int = 0;y1 < yMax; y1++) {
    for (var x1 : int = 0;x1 0 && y1 + 1 == yMax) yLimit = yRemainder;

    for (var y2 : int = 0;y2 0 && x1 + 1 == xMax) xLimit = xRemainder;

    for (var x2 : int = 0;x2 > 8 & 0xff);
    // green
    block.writeByte(p >> 16);
    // red

    writeUI16(v, block.length);
    // write block length (UI16)
    // write block
    return v;

    private function flvTagOnMetaData() : ByteArray {
    var tag : ByteArray = new ByteArray();
    var dat : ByteArray = metaData();

    // tag ‘header’
    // tagType = script data
    writeUI24(tag, dat.length);
    // data size
    writeUI24(tag, 0);
    // timestamp should be 0 for onMetaData tag
    // timestamp extended
    writeUI24(tag, 0);
    // streamID always 0

    // data tag

    previousTagSize = tag.length;
    return tag;

    private function metaData() : ByteArray {
    // onMetaData info goes in a ScriptDataObject of data type ‘ECMA Array’

    var b : ByteArray = new ByteArray();

    // ObjectNameType (always 2)

    // ObjectName (type SCRIPTDATASTRING):
    writeUI16(b, “onMetaData”.length);
    // StringLength
    // StringData

    // ObjectData (type SCRIPTDATAVALUE):

    // Type (ECMA array = 8)
    // // Elements in array


    if (duration > 0) {
    writeUI16(b, “duration”.length);

    writeUI16(b, “width”.length);

    writeUI16(b, “height”.length);

    writeUI16(b, “framerate”.length);

    writeUI16(b, “videocodecid”.length);
    // ‘Screen Video’ = 3

    writeUI16(b, “canSeekToEnd”.length);

    var mdc : String = “ v0.8”;
    writeUI16(b, “metadatacreator”.length);
    writeUI16(b, mdc.length);

    // VariableEndMarker1 (type UI24 – always 9)
    writeUI24(b, 9);

    return b;

    private function writeUI24(stream : *, p : uint) : void {
    var byte1 : int = p >> 16;
    var byte2 : int = p >> 8 & 0xff;
    var byte3 : int = p & 0xff;

    private function writeUI16(stream : *, p : uint) : void {
    stream.writeByte(p >> 8);
    stream.writeByte(p & 0xff);

    private function writeUI4_12(stream : *, p1 : uint, p2 : uint) : void {
    // writes a 4-bit value followed by a 12-bit value in two sequential bytes

    var byte1a : int = p1 <> 8;
    var byte1 : int = byte1a + byte1b;
    var byte2 : int = p2 & 0xff;

    class SingletonEnforcer {

    FLV structure summary:



    FLV file format:


    last tag size

    data [VIDEODATA]:
    videodata [SCREENVIDEOPACKET]:
    blockwidth ub[4]
    imagewidth ub[12]
    blockheight ub[4]
    imageheight ub[12]
    imageblocks [IMAGEBLOCKS[]]:
    datasize ub[16]

    last tag size



    Wednesday, October 6, 2010 at 11:56 pm #
  21. Naresh Khokhaneshiya wrote:


    You mentioned that “This API was designed originally for HTTP streaming, allowing forward seeking into HTTP delivered-video”, I was searching Internet how to do this but could not find something useful. Could you please give idea of this (specifically about forward seeking)? Thanks.

    Wednesday, October 13, 2010 at 1:07 pm #
  22. Rajdeep Rath wrote:

    Can netstream be filled with byte array data from a flv and published to rtmp ?

    Is it possible ?

    Thursday, October 28, 2010 at 10:45 pm #
  23. daslicht wrote:

    Could that alaos work to play f4m(segmented flv) files ?

    How about streaming audio trought zendAMF?

    Thursday, November 4, 2010 at 8:39 pm #
  24. janino wrote:

    Any example how to play a ICY stream with this method ?

    Thursday, November 11, 2010 at 2:13 pm #
  25. scott wrote:

    Has anyone been able to use this technique to append two video clips together? It seems that this method is used to enable HTTP Dynamic Streaming ( I’d like to be able to emulate, but when I call appendBytes the second time on the same stream, it doesn’t seem to work. Any thoughts on ‘stitching’ to videos together real time like this?

    Friday, December 3, 2010 at 11:05 pm #
  26. Diego wrote:

    Why it’s not possible to appendBytes() directly to Flash Media Server? Wouldn’t be better and more usefull than working just locally?

    Tuesday, March 8, 2011 at 1:05 am #
  27. jccrosby wrote:

    I have a sample working that plays the video from a ByteArray and works with a .flv file, but not a .f4v file.

    Would you be able to tell me if an F4V file is an FLV header-based file?

    I’ve read through the file spec for F4V/FLV (, and it looks like no. Do you think one could maybe ‘fake’ the header an still use the F4V video content?

    Thanks in advance!

    Wednesday, March 23, 2011 at 11:15 pm #
  28. fernando wrote:

    hi, this method: NetStream.appendBytes(“ByteArray”); don’t exists, how play a video “.flv , .f4v” from a bytearray? when I print this bytearray data it show a video file head description…. but, how I get this video and put in netstream or other thing??? please help me!!!

    Thursday, March 31, 2011 at 9:31 pm #
  29. fernando wrote:

    sorry, I tried use flex4.1, but this function exists only in 4.5 version….
    a problem with .f4v file format, it’s don’t play… but with a simple netstream“file.f4v”) it works…..

    Friday, April 1, 2011 at 7:52 pm #
  30. Smithy wrote:

    Is it possible to use BitmapData.draw when using appendBytes?
    I would like to do something like bitmapData.draw(video) but I get a security sandbox violation when trying:
    Error #2123: Security sandbox violation: cannot access null. No policy files granted access.

    Do I need to put a policy file somewhere?

    Saturday, April 9, 2011 at 12:14 am #
  31. nunja wrote:


    I post because I have serious issue while using the new NetStream.appendBytes API.
    It’s seems that, with the simple operation of a video playback (FLV / AVC / AAC, x264 in FLV), the netstream correctly plays the video, but stops two seconds before the end.

    It did not happened with FLV/VP6 video.

    The strange thing is that when i trace the _ns.bufferLength (buffer time sec to 3s), The buffer do not flush as usual when reaching the last 3 secs:

    It says Buffer.Empty brutally:


    No flush so far.

    The same behavior occurs with the example of this page.

    Did somebody experienced the same behavior ? (I absolutely need to use appendBytes anyway) ?

    Thursday, May 5, 2011 at 4:20 pm #
  32. Anupam wrote:

    I think if we use appendBytes with NetStream we will never be able to get the snapshot of the video playing, as you call play with null and flash player tries to get the crossdomain policy file from null.
    @Thibault, is there any workaround for this in FP 10.1, I am working on a fairly large scale live streaming solution using API and would like to use http streaming (OSMF with Zeri) and grabbing a thumbnail is very important feature for us.

    Thursday, May 19, 2011 at 2:57 pm #
  33. Gauth wrote:

    Hi there,

    It’s great to stream FLV’s byte but is it possible to draw the video?

    I get a Security Sandbox error like Smithy said.

    As Anupam said, i don’t find how it is possible to give to Flash a crossdomain.xml when the reference is play(null)…

    Have you an idea?


    Wednesday, June 1, 2011 at 3:04 pm #
  34. Hi there,

    i’ve a solution to get rid of the sandbox error when trying to draw a netstream.appendByte() content.

    The SWF retrieves a sandbox because he is looking for a crossdomain file at the address specified by you : He’s looking for something that doesnt exist.

    Well, the solution is to play a fake video url, like “” with a genuine crossdomain file on it, and after that, you just have to load the video you want thanks to the appendBytes function.

    The SWF is fooled!

    As strange as it sounds, it work for me :-)

    Wednesday, June 1, 2011 at 4:04 pm #
  35. polaco wrote:

    Hi Thibault,
    Is there any way to stream a video from a flashplayer to another flashplayer using netgroup and netstream. Something similar to camera streaming but instead of streaming camera input I want to stream a local file video.

    Wednesday, June 22, 2011 at 6:53 pm #
  36. aditya wrote:

    hi. i d been experimenting with API and find it quite interesting. however, i am stuck in a situation to which i cannot find a soluiton. suppose we make chunks of some video and send them across to somebody for playing a video( by appending it onto a netstream) and in this process some chunks are not delivered. will the appenBytes function still play this video simply ignoring the chunks not delivered and skipping to the available chunks? if so, then how? as i ran into this situation once and havent found a workaround yet…im looking forward to your guidance on this. thanks

    Tuesday, August 2, 2011 at 11:44 pm #
  37. JeanPaul wrote:

    The possibility to play video from byteArrays, even if narrow to the coding flv, makes me happy because I memorize all files, video too, on MySql.
    Together video I also memorize the miniature of one of the first frames,
    and there is no problem to extract the bitmapdata from video played with, while with and ns.appendBytes(bytes), the statement bmp.draw(video) give ‘SecurityError: Error #2123′
    do you have an idea to overcome this error?
    thanks in advance

    Sunday, October 23, 2011 at 12:40 pm #
  38. JeanPaul wrote:

    …..Pixel Expander: I tested your suggestion, but give an error with append, have u an example?

    Monday, October 24, 2011 at 5:39 am #
  39. Please how can I queue multiple byteArray and it will not pause before playing the next added byteArray appended to the NetStream

    Thursday, March 15, 2012 at 1:09 pm #
  40. coder777 wrote:

    How to perform seek function in this data generation mode for flv video?? i have tried lot of ways,But video is getting paused after seeking…. Please help…..

    Monday, August 27, 2012 at 8:16 am #
  41. M.USAMA wrote:

    it’ll be very appreciated if some one answer the question posted on that link


    Thursday, September 6, 2012 at 11:47 pm #
  42. lebobas wrote:

    Has anyone been able to use this technique to append two video clips together? Is it posible?

    Friday, February 22, 2013 at 11:30 am #

Trackbacks/Pingbacks (5)

  1. [...] ByteArray Access to NetStream in Flash Player 10.1 [ by Thibault Imbert ] [...]

  2. Summer AIR Mobile Contest 2010 CZ/SK — on Wednesday, July 7, 2010 at 6:55 pm

    [...] Twitter, GPS, maps, with latest AIR 2.0 features such as multi-touch, accelerometer, audio/video NetStream appendBytes access and so on. Important: The app must be built originally for this contest, but we surely [...]

  3. [...] Viewing the video Flash Player 10.1 added new NetStream function called appendBytes, which enables you to pass ByteArray containing FLV bytes to a NetStream and then display it. This was originally added for HTTP streaming, but we can leverage it nicely as well. You can read more about it here. [...]

  4. [...] added the ability to add bytes into the NetStream object via the appendBytes method (described here The main reason for this addition is that Adobe is finally supporting HTTP streaming of video. [...]

  5. [...] The current limitation right now with the Flash Player is that you cannot inject the new generated FLV in the NetStream class you have to send it to a server and load it again, damn, do you remember a similar story ? This is now possible with Flash Player 10.1 (NetStream.appendBytes). [...]