2

I'm streaming data from a server and passing it into a net stream in data generation mode. I'm successfully wrapping H264 and PCMU to be played back through NetStream, however I need to be able to capture this output from the video display it's on and store it in an image. When using an RTMP server, I'd configure it to send an RtmpSampleAccess command, with true,true for audio and video access allowed. When using RTMFP I'd do the same, send() a RtmpSampleAccess true,true from the peer to allow access.

I believe I need to send in an FLV tag for a script data object to represent the RtmpSampleAccess command, however I can't find any information on what the format of that tag needs to be. I've tried using the OSMF FLVTagScriptDataObject with the objects set to the following combinations:

["|RtmpSampleAccess", true, true];
["|RtmpSampleAccess", [true, true]];

And various attempts at guessing the naming for object parameters (though looking at the protocol docs, I'm not sure there is one).

Could someone out there help me here, would be much appreciated.

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
  • So you are able to make audio and video tags and append them to play the video, fine? All you need is how to draw the video container? Just trying to visualise where `RtmpSampleAccess` comes into play with `appendBytes` method. – VC.One Mar 02 '16 at 07:36
  • Yep the video is rendering to a Video element, but I want to copy that to a BitmapData, and can't because the videoSampleAccess is false. In other cases I'd send this "special" message to enable that sample access. – Kevin Glass Mar 02 '16 at 07:43
  • Try my answer. That's one of two methods I know to draw `appendBytes` video without error. Infact, it cancels all security errors!! Let me know if it works since this is shorter & less limited (than possible second option). – VC.One Mar 02 '16 at 08:40

1 Answers1

1

Where you put your Netstream into Data Generation mode you add a second Play command. The second one simply plays "a blank" and for some reason this overrides the security error.

ns.play(null);
ns.play(""); //works to avoid all security errors
ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);

Then to draw just setup a button to run the draw_VideoFrame function when clicked, or try real-time drawing with something like below (using enterFrame):

vid_Obj.addEventListener(Event.ENTER_FRAME, draw_VideoFrame);

and then create a function like this example.

function draw_VideoFrame (e:Event) : void
{
    vid_BMD.draw( vid_Obj ); //draw into a BitMapData variable
}
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • Might be worth adding the other way if you have time, just for completeness for future readers. Again thank you so much. – Kevin Glass Mar 02 '16 at 08:46
  • Glad it worked. I will add the other method in a later edit. I prefer shown method because it cuts out all security errors (eg: you could add a `computeSprectrum` visualisation for video's sound, normally not allowed even with **[second method](http://gamespoweredby.com/blog/2014/11/netstream-playnull-bitmapdata-workaround/)** since that only draws the pixels). – VC.One Mar 02 '16 at 09:01