3

I want to convert Writablebitmap to Jpeg stream, and it looks like there is no platform support as well as I can see a bunch of opensource Encoder libraries on web, I want to get your opinion on which is the recommended one in terms of performance and reliability.

Jobi Joy
  • 49,102
  • 20
  • 108
  • 119

3 Answers3

5

I made good experience with FJCore. I also blogged about it a while ago http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html

Rene Schulte
  • 2,962
  • 1
  • 19
  • 26
5

I've spent quite a bit of time with both FJCore and LibJpeg.Net. FJCore is easier to use, since it was ported over from Java, and has an object model that vaguely resembles what you'd expect to see in C#. However, LibJpeg.NET is by far the more complete library (it's based on the informally canonical libjpeg), and it's significantly faster as well. To give one example, FJCore uses a naive implementation of an inverse discrete cosine transform that involves something like 1024 multiplications and an additional 1024 additions for each 8x8 block. In contrast, LibJpeg.NET uses the high performance AAN algorithm which only takes 144 multiplications and 464 additions (see http://datasheets.chipdb.org/Intel/x86/MMX/MMX/AP528.HTM#AAN Algorithm). In addition, FJCore is fairly inefficient in how it uses memory, constantly recreating objects that could easily be re-used. At the same time, because FJCore has fewer optimizations, it's significantly easier to hack.

For my current project (which involves writing a video codec for Silverlight), I used FJCore as a starting point, fixed a whole bunch of its inefficiencies, replaced its IDCT algorithm with the one from LibJpeg.NET, and ended up with something that gave me about 10x the original performance.

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • Hi Ken, can you share your updated code to FJCore source? Also in your own experience in both libraries in terms of quality and compression, which do you think is better? – cubski May 13 '11 at 00:04
  • When I used the term "hack" in my answer above, I wasn't kidding. While I tried not to break anything in the original FJCore library, my primary concern was modifying it to work in my particular Motion JPEG style video codec, not making it easy to use for other folks or in other situations. That said, see this answer (http://stackoverflow.com/questions/1773330/streaming-a-webcam-from-silverlight-4-beta) for a link to a somewhat earlier version of my modified code. – Ken Smith May 13 '11 at 16:15
  • Hi Ken, I'm currently taking 10 fps from my webcam application and I'm using FJcore for encoding. I'm not sure how to put together the encoded frames to mjpeg video. I tried to sequentially add the bytes from the encoded frames to a stream to save it on disk, to no avail. Could you point me to the right track? Thanks. – cubski May 13 '11 at 22:17
  • 1
    I've never actually tried to get an official MJPEG file format working, so I'm afraid I can't help you. (In my app, I'm controlling both recording and playback.) My suspicion is that there's more than just laying the frames, one after another, onto a filestream, but I'm not really sure. See the Wikipedia MJPEG article (http://en.wikipedia.org/wiki/Motion_JPEG) and the MS definition for storing it in an AVI container here (http://www.fileformat.info/format/bmp/spec/b7c72ebab8064da48ae5ed0c053c67a4/view.htm). Hope this helps. – Ken Smith May 14 '11 at 00:41
  • I'm trying to use the encoded "JPEG to JPEG AVI File Format" which is found in you links and also here http://msdn.microsoft.com/en-us/library/dd318189(v=vs.85).aspx. I'm also testing out LibJpeg.Net but having trouble with it, could you give me some advice. Thanks! – cubski May 14 '11 at 12:04
0

Ken why don't you submit your updated code to the FJCore source?

http://code.google.com/p/fjcore/

AndyBufNY
  • 238
  • 2
  • 11
  • Sorry, just now spotted this. I may yet do this, but most of my modifications were in the direction of integrating with my overall solution, not in the direction of generally helpful and generally applicable changes. It would probably take me several days to back-port the generally applicable changes to the FJCore library. It's something I'd like to do, but my current startup is keeping me pretty busy :-). – Ken Smith May 13 '11 at 16:18