6 Replies Latest reply on May 12, 2009 4:01 PM by k-hexa

    Access Video (FLV) Data




      I want to play FLV video in a flash video player, and at the end of the buffering I want to access the data (video data, or buffered file) so I can manipulate it. For exemple in a ByteArray format so I can save it to local disk...

      With the NetStream and NetConnection I can play the video without problem, but I can't find a way to access the data.

      using the URLStream, I can download the video file (url : http://mysite/myvideo.flv), and I can access the data I want but I can't play it?


      Is there a way to play the URLStream, or to get data from the NetStream?


      Or may be, I can access the cache of the browser to get the bufferd data played by NetStream?


      Thank you

        • 1. Re: Access Video (FLV) Data
          sneakyimp Level 2

          I'm not at all certain, but I think you might find onImageData event helpful.  There's an example here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#event:o nImageData

          • 2. Re: Access Video (FLV) Data
            k-hexa Level 1

            Thank you

            The onImageData seams to get image metadata saved in an flv file, like onTextData and onMetaData. it's not returning the bytes in the flv file?

            • 3. Re: Access Video (FLV) Data
              sneakyimp Level 2

              OK sorry there.  I should have read a little closer.


              The only other ways I can think of are to try and cast the data of the movie as a ByteArray.  This post suggests that you can use URLLoader to load the FLV's bytes, but says that there's no way to render those into some viewable video:



              If you know how to parse the bytes, you would probably have some luck, but it would be fairly involved.  You might have to read ffmpeg's source code, for instance.  I have not tried it, but my research suggest you'd need to set the URLLoader.dataFormat property to URLLoaderDataFormat.BINARY.  Then something like this:


              private function onComplete(e:Event):void
                      var byteArr:ByteArray = loader.data as ByteArray;
                    // ...


              I personally have been able to attach a video camera to a Video instance:

              var cam:Camera = Camera.getCamera();
              cam.setMode(320, 240, 12);
              var vid:Video = new Video(cam.width, cam.height);
              trace('camera:' + cam.width + 'w X ' + cam.height + 'h');


              I then create a destination bitmap on my movie:

               // default color is green
              var outgoingBitmapData:BitmapData = new BitmapData(cam.width, cam.height, false, 0x00ff00);
              var outgoingImage:Bitmap=new Bitmap(outgoingBitmapData);


              Then I had a button listener which called a function which would grab a frame from the camera and turn it into a ByteArray:

              myButton.addEventListener(MouseEvent.CLICK, foo1);
              function foo1(e:Event) {
                   var bounds:Rectangle = new Rectangle(0, 0, outgoingBitmapData.width, outgoingBitmapData.height);
                   var bmp:ByteArray = outgoingBitmapData.getPixels(bounds);
                   trace('byteArray length:' + bmp.length);


              Maybe something like this would work?  Instead of listening for a button click, you could listen for an enterFrame event or perhaps some kind of VideoEvent?

              • 4. Re: Access Video (FLV) Data
                k-hexa Level 1



                I already tried to download the file with URLLoader, URLStream... but there is no way to play it...


                My final aim is to get the sound data from the flv file, so if I get the total data of the video I can get the sound data?


                I see that the flv file is always cached on the disk, if I can find a method to get the path to this file, I can read it after the download finished?


                Thank you

                • 5. Re: Access Video (FLV) Data
                  sneakyimp Level 2

                  Sounds like you are stealing someone's audio.  Shame on you!


                  If all you want to do is save their FLV file to your hard drive, then use Firefox with the Firebug plugin installed.  With it, you can see all the file requests that are made by your browser when you visit a given page.  You'll be able to see the FLV requests that have been made and you can right-click the URL and do a "save as..."

                  • 6. Re: Access Video (FLV) Data
                    k-hexa Level 1



                    """Sounds like you are stealing someone's audio.  Shame on you!"""

                    You're wrong on this, if I want to do that I can google FLVTOMP3 and I find hundreds of software doing it, and as you said in firefox I can download any flv on the web (youtube...). on the other side FLV on youtube and other website are public....


                    My problem is a development problem, and as I said to you before, using URLLoader with the url let me download the file...


                    Thank you for trying to help