2 Replies Latest reply on Sep 30, 2009 11:37 PM by Poobeard

    How can I grab a frame from the NetStream?


      I need to snapshot my video but my player size is smaller than the source. I need to grab a frame from the netstream itself. Can this be done?

        • 1. Re: How can I grab a frame from the NetStream?

          As far as I know, there is no way to get a screen grab directly from a NetStream .  The normal method would be to create a BitmapData object, and use the BitmapData.draw() method to copy the pixels from the DisplayObject thatis rendering the video stream.  You can only use BitmapData.draw() on DisplayObjects or other BitmapData objects.


          I've played around with a similar task and have a couple suggestions worth trying:


          1) You can resize the Video object to the full size of the stream, draw the screen grab, and then restore the size of the Video object all within a single function call.  This usually means that all three operations will happen before the screen is redrawn.  That means that the user never sees the Video resizing, because it is resized and then restored before the next frame renders.  I think that this would be the best approach for you.


          2) You can actually switch NetStreams between Video objects on the fly.  So you can have your normal, small Video (we'll call this Video1) playing the NetStream, and separately create in advance a full size Video object (we'll call this Video2) with no NetStream attached.  When you want to do a screen grab, pass the NetStream into Video2.attachNetStream(), capture a screen shot of Video2, then pass the NetStream back to Video1.attachNetStream().  This results in a noticeable stutter in video playback as the stream is being switched between Video objects, but it gets around needing to resize the Video object.  You don't even have to put Video2 on the display list, so it doesn't ever need to be visible to the user.


          Hope that helps.

          • 2. Re: How can I grab a frame from the NetStream?
            Poobeard Level 1

            Thanks for this great advice. I actually ended up working out your 

            first suggestion and it worked a treat. You may want to blog this for 

            someone else.