Live JPEG Encoder 0.3 by Thibault Imbert

Application :

A Flash animation should have appeared here, but it seems that your browser has an older version of the Flash Player or it is not installed at all. Please, install the last release of the Flash Player now, then reload this page.

Here is an application i had to develop in Actionscript 3, it lets you capture any content into a JPEG file (JPEG Encoding corelib class) with quality settings and size infos, you can choose between two modes, that lets you save the file on the server or your hard-disk.

Updated on the 09/20/06 : added FLV playback features

Updated on the 10/04/06 : added video navigation bar

Sources : Download

New AMFPHP Version available here

Comments (71)

  1. wendel wrote::

    Hi, any chance to post code?

    Wednesday, September 13, 2006 at 1:44 am #
  2. thibault.imbert wrote::

    hi wendel,

    let me add some more goodies to the tool and i’ll post the source code, stay tuned :)

    Wednesday, September 13, 2006 at 1:46 am #
  3. flashm wrote::

    it’s not working ot Fire Fox :(
    but BRAVO – nice work :)

    Monday, September 18, 2006 at 12:18 am #
  4. panpan wrote::

    beau bouleau !
    et peut ont faire dialoguer cela avec de l’AS2 ?

    Tuesday, September 19, 2006 at 2:32 pm #
  5. thibault.imbert wrote::

    flashm >> It’s corrected ;)

    Friday, September 29, 2006 at 5:00 pm #
  6. jmcwill wrote::

    How are you posting this back to the server? Are you using base64 and a normal post, or are you using a remote object?

    Saturday, October 21, 2006 at 7:12 pm #
  7. thibault.imbert wrote::

    hi jmcwill,

    to send this to the server, no need to encode it as Base64, this would be needed for sending the image with SMTP, just add an extra header with the URLRequestHeader saying it’s application-octet stream data and you will receive the bytes on the server in $GLOBALS["HTTP_RAW_POST_DATA"] then just write it ;)

    regards,

    Thibault

    Sunday, October 22, 2006 at 2:50 am #
  8. jmcwill wrote::

    I see, thanks. That is the same header that is sent with the file reference upload by flash. I was going to try to change the URLRequestHeader to make it seem like a file upload so I could set a filename and “fake” a file upload like a browser would. This way Java or PHP could catch it in the FILES array instead of raw data. I don’t think we have that much control over the headers though, unfortunately. The raw post data stream I will try though.

    Thanks,
    Jason

    Monday, October 23, 2006 at 5:34 am #
  9. thibault.imbert wrote::

    hi,

    i’m glad you like the application, AS3 gives us real power with plenty of new player API’s, for this application the really cool thing is the getPixels() method which returns a bytearray containing pixels color from a particular rectangle in a BitmapData, that really rocks :)

    Tuesday, October 31, 2006 at 11:53 am #
  10. rcfr wrote::

    Hi,
    This is a fantastic tool. Any chance you can post the source code soon.

    Thanks!

    Tuesday, November 14, 2006 at 7:17 pm #
  11. paul wrote::

    Hello,

    Source would be wonderful! I played with the JPEGEncoder in Flash9 Alpha for a bit… *brain not computing* meaning, I just plain couldn’t get it to work.

    Fantastic job, keep it up!
    Paul

    Friday, November 17, 2006 at 6:55 am #
  12. buck wrote::

    Would love to see the source also. In particular I’m curious how you can offer to save the snapshot immediately as a download.

    Tuesday, November 21, 2006 at 3:26 am #
  13. stanilsav wrote::

    hey, great job with JPEG Encoder. I have question – do you used in this PHP code?

    Thursday, December 7, 2006 at 8:13 pm #
  14. thibault.imbert wrote::

    hi stanislav,

    yes PHP is needed in order to write the bytes on the server and to get the download window, the player can’t do that by itself

    cheers

    Thursday, December 7, 2006 at 9:47 pm #
  15. stanilsav wrote::

    OK. So you don’t use PHP, to save JPEG. Cool I can use that. When will you post source code… or planning to do that? Please contact me dfm@abv.bg, I have something in mind.

    Thursday, December 7, 2006 at 10:06 pm #
  16. thibault.imbert wrote::

    hi guys,

    sources available ;)

    Sunday, December 10, 2006 at 7:19 pm #
  17. Jon B wrote::

    Hey, this is cool – just trying to think of some places where I could really use this – is it possible to access byte data of a file (selected through the upload functionality) before the file is sent to the server? Imagine a cool web interface for uploading images directly to your site in which you can crop tweak and compress images before uploading them!

    Tuesday, December 12, 2006 at 2:36 am #
  18. thibault.imbert wrote::

    hi Jon,

    I have done some research about loading an image into the player and modify it (scale, crop, etc) before the file is sent to the server, but there is no way to access the bytes of the selected file with the FileReference class.

    What is possible is to select the file, upload it, load it again with Loader and display it, then work on the image then save the new version, but this is not really optimized.

    Tuesday, December 12, 2006 at 9:26 am #
  19. kiko wrote::

    My code don’t work.
    I download the source code, and open my flash (ver 8.0). Then I try to test the aplication and the flash lunch this messages.

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 1: Error de sintaxis.
    package asfiles.encoding

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 2: Los scripts de clase ActionScript 2.0 sólo pueden definir construcciones de clase o interfaz.
    {

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 7: Atributo utilizado fuera de una clase.
    public class BitString {

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 8: No se pudo cargar la clase o interfaz ‘int’.
    public var len:int = 0;

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 9: No se pudo cargar la clase o interfaz ‘int’.
    public var val:int = 0;

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 12: Atributo utilizado fuera de una clase.
    public class JPEGEncoder

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 13: La clase que se está compilando, ‘JPEGEncoder’, no coincide con la clase que se importó, ‘asfiles.encoding.JPEGEncoder’.
    {

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 33: No se pudo cargar la clase o interfaz ‘int’.
    private function initQuantTables(sf:int):void

    **Error** C:\Documents and Settings\KIKOCC\Escritorio\Flash\jpeg_encoder_source\asfiles\encoding\JPEGEncoder.as: Línea 45: No se pudo cargar la clase o interfaz ‘int’.
    for (var i:int = 0; i

    Wednesday, December 27, 2006 at 6:09 pm #
  20. kiko wrote::

    What can I do?

    I’m new on this themes

    Thank you

    Wednesday, December 27, 2006 at 6:11 pm #
  21. thibault.imbert wrote::

    hi kiko,

    you need to open and run the files under Flash 9 Alpha, it’s an AS3 project, you can download Flash 9 Alpha on the labs

    labs.adobe.com

    cheers,

    Thibault

    Thursday, December 28, 2006 at 7:05 pm #
  22. tannoy wrote::

    bonjour thibault,

    j’ai un souci d’utilisation de ta classe d’encodage JPEG.
    Lorsque je veux instancier un objet de type JPEGEncoder, j’ai ce message d’erreur :

    Type was not found or was not a compile-time constant: JPEGEncoder.
    var monEncodeur:JPEGEncoder = new JPEGEncoder(50);//on définit la qualité de l’encodage jpeg

    As-tu une idée ?

    merci d’avance

    Tuesday, January 16, 2007 at 6:42 pm #
  23. thibault.imbert wrote::

    salut tannoy,

    as tu bien vérifié que la classe est bien importée en début de script ?

    le compilateur ne semble pas trouver la classe, elle ne doit pas être importée,

    ;)

    Friday, January 19, 2007 at 8:29 pm #
  24. tannoy wrote::

    salut thibault

    la classe est bien importée sur la première ligne de script. Bizaremment, ça fonctionne bien si je mets la classe ainsi que mon fichier dans le dossier créé lors de la forma regart alors que si je copie ces fichiers dans un autre dossier, j’ai le message. bizarre non ?

    ;)

    Friday, January 26, 2007 at 2:00 pm #
  25. Migs wrote::

    Thank you so much! I’ve been looking for a solution to encode and export JPEGs for hours before I see your code and now it works!! thank you!!! :D

    Tuesday, February 6, 2007 at 1:02 am #
  26. sander wrote::

    Has anyone tried speeding up the algorithm yet? On my old PC it takes about 6 seconds to compress a 640×480 image. I’d love to get it down to about 1 sec.

    Looking at the algorithm, I see a lot of floating point calculations, so I wonder if some of them could be converted to integer operations, but I don’t know where to start. Any suggestions?

    Friday, February 9, 2007 at 3:29 pm #
  27. thibault.imbert wrote::

    hi sander,

    this is something that can be greatly optimized, I don’t have much time for this one right now, but send me an email and we’ll talk about it :)

    Friday, February 9, 2007 at 4:47 pm #
  28. Rezmason wrote::

    Hello,

    I’m working on an online repository for artistic tools implemented in AS3– exotic paintbrushes, image-warping tools, tools that convert sound and brush strokes into images, and so on- and I was wondering whether I can use your JPEG encoder, so that site visitors can download their artwork. I plan to make my source code available once I’ve got everything working, and just want to confirm that you’re cool with other people using this neat class of yours.

    Monday, February 12, 2007 at 2:17 am #
  29. thibault.imbert wrote::

    hi Rezmason,

    no problem, you can use it, just drop me an email when it’s online, so that I can see this great project ;)

    cheers

    Monday, February 12, 2007 at 2:41 pm #
  30. Kevin wrote::

    Hi, I’m taking a quick capture of a sprite, _tray and trying to save it, but I’m getting weird response. It opens the browser, but the URL reads:

    “http://www.kevinsweeneydesign.com/muse/create2.php?name=snapshot.jpg?%C3%BF%C3%98%C3%BF%C3%A0″

    and prints out the default error. Any ideas what’s going on? If I run your application from my server it works fine, so I’m probably just not inserting enough code or something:

    var bd:BitmapData = new BitmapData(400, 100);
    bd.draw(_tray);

    var myEncoder:JPEGEncoder = new JPEGEncoder( 75 );

    var myCapStream:ByteArray = myEncoder.encode ( bd );

    var header:URLRequestHeader = new URLRequestHeader (“Content-type”, “application/octet-stream”);

    var myRequest:URLRequest = new URLRequest ( “http://www.kevinsweeneydesign.com/muse/create2.php?name=snapshot.jpg” );
    myRequest.requestHeaders.push (header);
    myRequest.method = URLRequestMethod.POST;

    myRequest.data = myCapStream;

    navigateToURL ( myRequest, “_blank” )

    Sunday, February 25, 2007 at 6:01 pm #
  31. thibault.imbert wrote::

    hi Kevin,

    make sure you are not running your app in the Flash IDE, Flash uses GET when you run an app which uses POST buffer, that’s the reason why you get a bytearray stream description in the url,

    let me know ;)

    Sunday, February 25, 2007 at 9:20 pm #
  32. Kevin wrote::

    Doh! That was it. Thanks :)

    Sunday, February 25, 2007 at 11:28 pm #
  33. thibault.imbert wrote::

    great ;)

    Monday, February 26, 2007 at 12:26 am #
  34. christian.revest wrote::

    Bonjour, ce script permet il de faire de la capture de swf, flv et au delà, de capturer des zones entieres de l’ecran du player flash?

    Merci

    Monday, March 12, 2007 at 5:39 pm #
  35. Mete Tuneri wrote::

    Hi, this is brilliant and very fast script. Thank you for sharing.

    My question is, I don’t really understand any code in PHP. Is there someone who could lead me expressing the same server side functionality in ASP or ASP.NET?

    Wednesday, March 14, 2007 at 6:33 pm #
  36. Jim wrote::

    Very useful, thank you so much for spending your time making it even though it must have been too long to remember =D

    Saturday, March 24, 2007 at 2:07 am #
  37. Matt Poole wrote::

    Really cool!

    This got me inspired – heres an apollo app implementation saving a jpg to filesystem usiong JPEGEncode – heres the code:
    —————————————–

    ———————————————

    Where ‘some.jpg’ on the background of the VBox is a jpg of your chosing…

    try it – works a treat :)

    Thursday, April 12, 2007 at 4:16 pm #
  38. Matt Poole wrote::

    Sorry the code didnt come out heres a link to it instead:

    http://www.barncar.com/writejpg.mxml

    Cheers!

    Thursday, April 12, 2007 at 4:20 pm #
  39. Prakashan wrote::

    This is cool!

    Please where can I download the complete source file.

    It will be great If you allow to download.

    Thanks
    Prakashan.

    Wednesday, May 16, 2007 at 9:23 am #
  40. Thibault Imbert wrote::

    Hi Prakashan,

    sources are available here :

    http://www.bytearray.org/wp-content/uploads/2006/09/media_snapshot/jpeg_encoder_source_03.zip

    cheers

    Wednesday, May 16, 2007 at 10:57 am #
  41. felarca wrote::

    Thibault, this class is great. I’ve put it to good use with my Apollo webcam video app to save specific video frames as JPEG’s:

    http://www.zeropointnine.com/blog/webcam-dvr-for-apollo

    Lee Felarca

    Thursday, May 17, 2007 at 6:33 am #
  42. Prakashan wrote::

    Thanks Thibault Imbert.

    Thursday, May 17, 2007 at 8:33 am #
  43. Inder wrote::

    It is really that what exactly i was searching for. Thanks for this script. I agian want to apriciate the work done here.

    Thursday, May 17, 2007 at 11:51 pm #
  44. Inder wrote::

    hi Thibault Imbert

    Really You have excellent work done here. I ve downloaded its Source files. but I cant find create.php and create2.php files in the package. Well i am not much aware of php. So can u send me these php files . if u dont mind……

    Thanks

    Friday, May 18, 2007 at 9:49 pm #
  45. Thibault Imbert wrote::

    Hi Inder,

    You can download the sources again, I have included the php files, sorry about that :)

    cheers

    Saturday, May 19, 2007 at 12:55 pm #
  46. Inder wrote::

    Thank You so Much Thibault Imbert
    It is really great. it is working amazing.
    Thanks

    Tuesday, May 22, 2007 at 4:17 pm #
  47. can't make it work wrote::

    hi, no working, no movie show

    Monday, June 18, 2007 at 2:48 am #
  48. Jeff wrote::

    Although the current Flash implementation doesn’t allow client-side access to user-selected files, you guys might be interested to know that Silverlight *does* allow this. Google the silverlight project: “Fluxify” to see an example of this.

    Saturday, September 29, 2007 at 7:16 am #
  49. Jeff wrote::

    Is the source no longer available????

    Wednesday, December 5, 2007 at 9:47 pm #
  50. Thibault Imbert wrote::

    Hi Jeff,

    Just fixing a bug on the server, I will post them back tomorrow ;)

    kind regards

    Sunday, December 9, 2007 at 9:59 pm #
  51. Aaron Nicholson wrote::

    Hi there,
    I’d love to use the non-AMFPHP version of this, but can’t find a link to the code. Where can I find your code?
    Thanks a lot btw. This should make things a lot easier.
    A

    Friday, January 11, 2008 at 6:08 am #
  52. Aaron Nicholson wrote::

    Re: my last post. I see a link to the source in an earlier comment, but it gave me a 404.

    Friday, January 11, 2008 at 6:10 am #
  53. Hi,

    I have been looking for something like this. where can I get the source – the link doesn’t seem to work for me.

    Thanks
    Rich

    Monday, January 21, 2008 at 5:08 pm #
  54. Thibault Imbert wrote::

    Hi Richard,

    I will re-upload the sources tonight :)

    regards,

    Thibault

    Monday, January 21, 2008 at 5:14 pm #
  55. Thomas wrote::

    Hey ! nice class, but there is a solution to encode a JPG with 300 dpi instead of 72 dpi ?

    Where the modification to do it should be ? In JPG Encoder class or in the class witch use it ?

    thanks

    Thursday, May 15, 2008 at 4:11 pm #
  56. Thomas wrote::

    I found a solution, change in “writeAPP0″ function

    this :
    writeByte(0); // xyunits
    writeWord(1); // xdensity
    writeWord(1); // ydensity

    into this :

    writeByte(1); // xyunits
    writeWord(0x12c); // xdensity
    writeWord(0x12c); // ydensity

    Friday, May 16, 2008 at 1:22 pm #
  57. Thibault Imbert wrote::

    Hi everybody,

    I re-uploaded the sources :

    http://www.bytearray.org/wp-content/projects/postjpegencoder/standard_jpeg_encoder_source_03.zip

    cheers ;)

    Thibault

    Sunday, June 15, 2008 at 10:55 pm #
  58. Javier wrote::

    I wondering how i can capture one Movie Clip and not the video

    Thursday, September 4, 2008 at 2:55 am #
  59. Sam wrote::

    Brilliant. Found this really useful on a project i was working on.

    Tuesday, January 13, 2009 at 4:09 pm #
  60. kevin wrote::

    Wow, this is awesome! I have looked through the source and haven’t found anywhere if this holds a license or freely available for use by anyone. Is this possible to use on my website?

    Wednesday, September 2, 2009 at 10:45 pm #
  61. Robert Sumazinklle wrote::

    Hello mate, i have some problem when I’m going to save to server.
    I’m using this to the URLRequest
    var myRequest:URLRequest = new URLRequest ( _assets.bt_enviar.selected ? “http://localhost/sites/rba/deploy/Main.html?name=snapshot.jpg” : “http://localhost/sites/rba/src/php/create2.php?name=snapshot.jpg” );

    Is this the way to use it? Main.html?name=snapshot.jpg ?

    When I click at the save button the File Browser opens to save the image.

    Thursday, October 1, 2009 at 8:07 am #
  62. Robert Sumazinklle wrote::

    I got a error.

    Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

    I try to use the loader.dataFormat to VARIABLES but have no success.

    Could you help me?
    Thanks in advance!

    Thursday, October 1, 2009 at 8:12 am #
  63. James Anelay wrote::

    Hi, Greate Work. Is it possible to get a response from the php script once the file has uploaded. and then run another function depending on weather the response was a sucessful one?

    Thursday, September 9, 2010 at 1:07 pm #
  64. James Anelay wrote::

    Ignor that last message I completely missed the onImageComplete message.

    Thursday, September 9, 2010 at 1:10 pm #
  65. James Anelay wrote::

    Hi, I’m using your code, but I want to only allow one image to be taken per day, therefor it needs to be re-written, and I show it on the same page using jquery without reloading the page is there a way to stop that image being cached by broswers, so when I remove it and add it again with jquery it changes?

    Thursday, September 9, 2010 at 2:55 pm #
  66. guiguizmo wrote::

    Bonjour Thibault,

    J’ai un soucis avec la sauvegarde sur le serveur. J’ai mis en ligne ton appli mais quand je clic sur sauvegarder sur le serveur, j’ai le movieClip “loading” qui apparait et ne disparait pas … et l’image n’est pas sauvegardée. Y a t il des droits d’acces a regler ?

    Merci.

    Monday, September 20, 2010 at 9:46 am #
  67. Luis wrote::

    HI,
    Excellent example, I was wondering, Do you think that it is possible to save a piece a video (Binary possibly) and send it to a server? (more likely with php and Post)
    Regards,
    Luis.

    Friday, October 22, 2010 at 8:45 am #
  68. Aldo Marsilio wrote::

    Is there a way to track the progress of the data submitted by post method?

    Monday, November 1, 2010 at 4:59 pm #
  69. Chris Fulton wrote::

    Here is a much simpler video poster frame grabber inspired by Live JPEG Encoder and other examples.

    http://www.masonqm.com/articles/Poster-Frame-Generator-0-02-Released-125.html

    Wednesday, June 15, 2011 at 9:20 pm #
  70. paranoio wrote::

    this gave me the idea of creating a DVR functionality into any video or animation , by using bitmapdata and creating a frame history

    its limited by the memory but i guess its a good proof of concept

    http://blog.motion.com.mx/general/video-con-repeticion-instantanea-con-flash/

    Thursday, February 16, 2012 at 2:42 am #
  71. sam wrote::

    Hey Thibault,

    I’m trying to take a screenshot with this functionality on your SimpleStageVideo. But is unsuccessful in capturing it with BitmapData. any ideas why?

    Tuesday, June 26, 2012 at 6:07 pm #

Trackbacks/Pingbacks (10)

  1. CleVR » Blog » Blog Archive » Actionscript 3 JPEG encoder on Saturday, October 28, 2006 at 2:25 pm

    [...] While I was writing the CleVR viewer and hotspot editor I often found myself running up against limitations of Actionscript. One of the ones that bugged me the most was the inability to export jpegs from BitmapData. Luckily, it seems that some of these limitations will be addressed in Actionscript 3, and an excellent demo at ByteArray.org illustrates exactly the solution I was looking for. Bring on Flash 9! [...]

     
  2. links for 2006-12-19 at leron’s crib on Sunday, December 24, 2006 at 10:22 pm

    [...] Live JPEG Encoder 0.3 < ByteArray.org (tags: as3 actionscript jpeg) [...]

     
  3. [...] actionscript 3, as3, daily delicious, encoder, flash, flash video, frame capture, jpeg, jpg, link, rich media, try doing that with AJAX videoI stumbled upon a great actionscript blog and discovered a pretty amazing Actionscript 3 Flash application. Simply, it dynamically encodes a JPEG from a playing FLV (Flash video) file and allows you to either save it to the server or to your own computer. Have a look at the project page for more details. This is just one small yet very cool reason why Actionscript 3 is going to dramatically change what can be done on the web. I have begun to slowly delve into AS3 and I am pretty amazed at what can be done. [...]

     
  4. trasportatore macchina giardinaggio on Tuesday, May 8, 2007 at 6:30 pm

    trasportatore macchina giardinaggio…

    Live JPEG Encoder 0.3 [ by Thibault Imbert ]…

     
  5. [...] Live JPEG Encoder 0.3 [...]

     
  6. [...] Here’s how it works. There are some rather annoying, but necessary, limitations in flash that make it a little difficult to use as an editor for personal files. To load an image to  edit, it must first be uploaded by flash to the web server hosting the flash file, and then re-downloaded into the flash player. This part isn’t too tough. Then there’s the issue of the image generation. The user needs to be able to get to the image after it’s captioned. It is technically possible to encode jpegs in flash  but this puts more bandwidth strain on the server and the user, seeing as the result would then have to be uploaded to the server, and then re-downloaded by the user.. Blech! not to mention, these files can get BIG. So, I got to thinking that Flash can just send the server a representation of the caption, and then server side scripts can render the image, and then flash can pull that image back in, and throw it up onto the webpage for download with some DHTML goodness! [...]

     
  7. woszkowski.com » JPEGEncoder on Thursday, September 20, 2007 at 10:10 am

    [...] W AS3, dzięki klasie ByteArray, mamy możliwość operowania danymi binarnymi. Wykorzystując tą możliwość, powstało szereg przydatnych bibliotek, które umożliwiają bezpośrednio we flashu np. kompresję zip, jpg, png, etc. Mnie na razie najbardziej zainteresowała klasa JPEGEncoder. [...]

     
  8. [...] Visual Studio: http://www.fluorinefx.com/docs/fluorine/vswizardnet20.html • Live JPEG Encoder: http://www.bytearray.org/?p=26 • PNG Encoder in AS3: http://www.kaourantin.net/2005/10/png-encoder-in-as3.html • FlashDevelop: [...]

     
  9. [...] Save JPEG images from webcam (thanks to Thibault Imbert’s AS3 JPEG encoder) [...]

     
  10. Bringing Flash Video to HTML5 Canvas | Maschinenbordbuch on Monday, March 7, 2011 at 3:32 am

    [...] speeding things up by reducing the data transferred. I encoded the BitmapData in flash to JPEG with JPEGEncoder and then to a Base64 string what reduced the data enormously, but that would mean to decode it in [...]