Fun with code (since 2006)

AMFPHP Live JPEG Encoder 0.4

04.15.07 Posted in Actionscript 3, ByteArray by

Now that AMFPHP 1.9 supports ByteArray transfer, I updated the "Live JPEG Encoder" so that it uses Flash Remoting technology with AMFPHP and FileReference.

We now have a 0.4 version which gives better performance and simpler code. JPEG encoding class has been also updated concerning the "Duplicate variable definition" warnings.

New version in action here

Update 05/07/05 :
WebCam version available here

Update 03/09/09 :
Sources have been updated to handle Flash Player 10 security restriction concerning the method.

Download sources : Live JPEG Encoder 0.4 Sources

133 Responses to “AMFPHP Live JPEG Encoder 0.4”

  1. tukinu says:

    this is realy a great tool and it just works. one question i have. how can i send with the data an individual jpg name? thanks a lot

  2. batchas says:

    hi Tukinu, I guess Thibault is very busy… So here is how I would do… in Flash:
    St te image name as you wish to.
    var sImage:String = “myImage.jpg”;
    Pass this vr with your streamObject:
    var streamObject:Object = {jpegstream : myCapStream, imageName : this.sImage };

    and in PHP…
    Catch the var from Flash:
    $myImage = $pInfos["imageName"];
    and if you keep the $idimage var:
    $idimage = $myImage;

    Hope it helps. batchas

  3. Thibault Imbert says:

    Hi batchas,

    Thank you for helping, your code is perfect :)

  4. sitron says:

    just to add another “THANK YOU” on the list!

  5. Anil Mathew says:

    Hi in flash 10 player there is a security error for local dik writing
    Error: Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.
    at media_snapshot_webcam_fla::MainTimeline/onHDSuccess()

  6. Thibault Imbert says:

    Hi Anil,

    Yes, for security reasons we can not call browse or download outside mouse events or keyboard events. This is really sad news, I will modify the application so that it works smoothly.



  7. dazfunkyman says:

    Je souhaiterai utiliser ton encoder avant de faire un upload via filereference afin d’alléger au maximum le poids des transferts clients/serveur mais je n’y arrive pas puisque apparemment filereference ne dispose pas de lien vers le fichier sélectionné via le bouton parcourir mais juste le nom du fichier choisi.
    Connais-tu une astuce pour palier à ce problème? et j’ai essayé de voir le code de la classe filereference pour voir s’il est possible de l’étendre mais je n’ai pas trouvé son package. Peux tu également me l’indiquer. Merci d’avance

  8. mike says:

    Hello Thibault,
    First of all, fantastic work! :D
    I would just like to know if you tried loading a jpeg snapshot you created from amfphp to be passed back to the swfapplication like in this way…

    return new ByteArray( file_put_contents(“../../../pictures/”.$idimage, $imageData));

    Is there a way to convert this data back into a bitmapdata? I tried almost every possible combination i can find but still i might be missing something…

  9. mike says:

    What i meant to say about my previous post was
    return new ByteArray( file_get_contents(”../../../pictures/”.$idimage);

  10. Devinder Pruthi says:

    i am doing one project in flex cs3. i am using bledgeDS. i am using webservice. i am getting bytearray for a xml file. i want to know how i decode this bytearray and find content of that xml file. please help

  11. rob says:

    I’m using your software succesful on my website, everything works just fine.

    The only thing I like to change is the filesize of the captured images. Every image is 800×600 and uses almost 500kb space on my server.

    How can I reduce the resolution of the images and how can I reduce the jpeg qualtity?

    In the example it works very easy with the slider but I don’t know how and where I will have to put the variables in the code.

    I hope someone has a tip for me, thx in advance.

  12. Randall says:

    The player doesn’t seem to be able to support a stream from a flash media server?

    rtmp:// versus http://

    I’ll look into it – but any ready-made solution?

  13. batchas says:

    Hi Rob,

    >>> About the compression level:

    If you open the FLA which comes wth the source code, you see how Thibault is setting every variable.

    To set the quality, Thibault sets a variable called “qualityValue”:

    var qualityValue:Number = mySlider.value;

    So as you are not using the slider, you just need to give a value to the qualityValue variable like this:

    // you just replace “mySlider.value” with the amount of compression you desire
    // if the compression level is 70%:

    var qualityValue:Number = 70;

    // create the encoder with the appropriate quality
    var myEncoder:JPEGEncoder = new JPEGEncoder( qualityValue );

    The other shorter way is to write directly the value in the JPEG Encoder:

    var myEncoder:JPEGEncoder = new JPEGEncoder( 70 );

    >>> About the filesize:

    I cannot answer here because I do use the Matrix and the Rectangle for the bitmpaData…
    I do not know how you get a screenshot with these dimensions (800×600) but the dimensions should normaly be defined in these code lines:

    var myBitmapSource:BitmapData = new BitmapData ( myWidth, myHeight );

    myWidth and myHeight being the bitmap size you wish to get as final dimensions.

    Hope it helps!

  14. Ludovic says:


    Super classe, c’est exactement ce que je cherchais…

    Cependant, j’eprouve des difficultés avec les grandes images (largeur supérieur à 1500 voire 2000) : Flash plante sur une erreur “1502″ délai d’execution dépassé (15 secondes).

    Je pense que la boucle de compression est trop longue à son gout.

    Comment peut on lui dire que tout est normal, et qu’il doit attendre sagement que la compression soit terminée ?

    J’ai essayé d’ajouter des DispatchEvent, mais ca n’a pas l’effet escompté !?

    Merci :)

  15. Rockntrek says:

    Même problème que Ludovic…

  16. Todd says:

    I’m desparate: when I go to publish the fla file, I get the following error:

    the intrinsic attribute is no longer supported

    using flash cs3. What am I doing wrong??

  17. [...] blog: Flash 上で Bitmap を JPEG 画像に変換 AMFPHP Live JPEG Encoder 0.4 <font size=’1′>[ by Thibault Imbert ]</font> &l… FICC LABS | Flashから画像ファイルを保存する [...]

  18. John15942 says:

    Salut Thibault,

    Super script !
    Pourrais-tu me dire comment je pourrais prendre le jpg sur le serveur et l’envoyer directement par email, tout cela apres avoir clicke sur “capture” ?
    J’ai du mal a comprendre comment lier le Flash > PHP > JPG > Email :-(

    Merci par avance

  19. Benoit says:

    That’s too bad the files apparently don’t work with CS3… Could you please save them as they are backward compatible please? That’d be VERY nice from you!

  20. Reinier says:

    I’m also wondering how to make a progress bar on this method of uploading jpg’s with amfphp..

  21. Gertschi says:

    Hi! what does :Waiting: new Waiting(); in the source Code?

    Best Regards

  22. [...]  ya da webcam uygulamasından görüntü yakalamak, kaydetmek için gerekli olan  kodları burada bulabileceksiniz. Video görüntüleri için demoyu buradan,  webcam için demoyu buradan [...]

  23. aaa says:

    i dont want amfphp

  24. [...] AMFPHP Live JPEG Encoder 0.4 [ by Thibault Imbert ] [...]

  25. [...] ich mir hier die neuste Version der JPEGEncoder Klasse gezogen: AMFPHP Live JPEG Encoder 0.4 <font size='1'>[ by Thibault Imbert ]</font> – ByteArray.or… Das ist ein Zip mit einer Beispiel Anwendung. Daraus hab ich mir die JPEGEncoder Klasse geholt [...]

  26. rainssong says:

    it’s amazine :)

  27. João Zonta says:

    Someone managed to implement a progressbar in sending the ByteArray to the server?
    Just got back when the file has just been sent, I can not sending a progress.

    Alguém conseguiu implementar a progressbar no envio do bytearray para o servidor?
    Só tenho retorno quando o arquivo acaba de ser enviado, não consigo um progress do envio.

  28. duman says:

    thanks for this class..

    but I dont execute my example..

    I m drag-drop image upload with air in myMc.myuloader its succesfuly.. But When I upload image

    my uploadded image is created but is empty..(border black and inside white)..why my image dont upload with original photo or img..

    thanks for your answers..

  29. duman says:

    I M drag-drop image in air ..
    in myMc.MyUloader..

    But When I Was Upload with Jpegencoder-amfphp ..My İmage is Created But its emty..(blask stroke and white background)..

    how I Upload My static image with amfphp with jpegencoder..

    thanks for your ansvers..

  30. Parada1280 says:

    Hello Thibault im using amfphp, double checked the folder permissions they are ok, i call the Method: saveToServer in the browser amfphp and get a result 0, it work when i leave the paths to bytearray, but when i change the gateway and folders to my server (local and www) it keeps saying Please Wait… what can it be, i just checked the others post but none say anithing about this problems, really thanks for your help

  31. Matth says:


    Pour ceux que ça intéressent, j’ai effectuer une traduction en français de cet article avec un exemple :

    A bientôt,

  32. العاب says:

    hello every one,
    can i use it to captuor flash games?

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh
Fun with code since 2006.