JPGEncoder and JPG Markers

Hi, I’m hoping someone can help me. I’m trying to use the as3corelib JPGEncoder to save a frame of a FLV to a JPG. Everything seemed to be working fine until I checked the JPG files that the script was creating. None of them show up in Windows Picture and Fax Viewer. So I opened them in Photoshop CS3 and I get the error: “Could not complete your request because a JPEG marker segment length is too short (the file me be truncated or incomplete)”.

I’m not sure what’s going on as I followed a tutorial (with a few minor changes). I’ve looked through Google and pretty much every tutorial is just like what I have, but theirs work. I couldn’t find an exact example for saving JPGs of a FLV.

Any ideas?

My document class:


package com
{

    import flash.display.MovieClip;
    import flash.display.Graphics;
    import flash.display.Stage;
    import flash.display.BitmapData;
    import flash.display.Bitmap;

    import fl.video.FLVPlayback;

    import flash.events.*;
    import flash.ui.Keyboard;

    import flash.utils.ByteArray;

    import flash.net.navigateToURL;
    import flash.net.URLRequestHeader;
    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.net.URLRequestMethod;

    import com.adobe.images.JPGEncoder;

    public class safari extends MovieClip {

        private var serverPath:String = "";

        public function safari():void {
            stage.addEventListener(KeyboardEvent.KEY_DOWN, this.reportKeyDown);
        }

        private function reportKeyDown(evt:KeyboardEvent):void {
            if (evt.keyCode == 32) {
                var c = canvas;
                this.createJPG(c, "an_image");
            }
        }

        private function createJPG(c:FLVPlayback, fileName:String)
        {
            c.stop();
            var bmd:BitmapData = new BitmapData(c.width, c.height);
            bmd.draw(c);
            var jpgEncoder:JPGEncoder = new JPGEncoder(100);
            var jpgStream:String = Base64.encodeByteArray(jpgEncoder.encode(bmd));
            var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
            var jpgURLRequest:URLRequest = new URLRequest("encoder.php?name=" + fileName + ".jpg");
            jpgURLRequest.requestHeaders.push(header);
            jpgURLRequest.method = URLRequestMethod.POST;
            jpgURLRequest.data = jpgStream;
            var loader:URLLoader = new URLLoader();
            navigateToURL(jpgURLRequest, "_blank");
            c.play();
        }
    }
}