AS3 Video Encoding at runtime with high compression (H.264?) - apache-flex

I need to compress video image data (lets say a display object) in AS3 to a Byte Array with high compression at runtime. Framerate only needs to be around 5 but 1024x768 video needs to go to < 40 Kilobyte per Second without the quality beeing tooo bad. I wrote a custom encoder and got it to around 80-100 Kilobyte per Second for 1024*768 which still is too much and i dont see a lot of improvements to be mad to my encoder.
Using JPG or PNG Encoder gives way higher KB/s. Is there any open source way to to decode and encode video in as3 at runtime ? E.g. a H.264 as3 encoder and decoder ? Or other codecs ?
Or maybe a C# source code of h.264 encoder and decoder ? I think i could port it to as3...
EDIT: Doesnt need to be h.264, just something with good quality when running at 5 Frames/Sec and 40 Kilobyte...

Flash Player 11 (beta) has H.264 encoding:
H.264/AVC SW Encoding — Encode higher quality video locally using H.264 video.
Edit: Flash Player 11 is no longer beta

ffmpeg is the only open source encoder/decoder I know of. I don't think it is C#. Due to licensing and patent issues around H.264, I'd be very surprised if an open source encoder didn't get sued into oblivion. this is why, for example, Firefox doesn't support H.264 in their HTML5 initiative.

Related

Full HD realtime encoding filter for DirectShow

I want to capture 1080p video from a webcam and mix it in a muxer with sound. Full HD-Videos take 17,4Gb/min which is too much for me. Is there a good (free) filter to encode this in realtime?
x264 will handle it, free with licensing restrictions, you also will need to find/make DirectShow wrapper
Windows Media Video will handle the feed on decent hardware
Theora is something to possibly look at as well
Motion JPEG is also applicable: inferior in terms of compression rates, still simple, decently fast and well known format; there are well optimized encoders out there and there is also certain compatibility through devices to support this encoding

QT, convert raw image to jpg using Hardware acceleration (gpu)

I need to convert an Raw image buffer into a jpg image buffer.
At the moment, I do this operation in the following way:
QImage tmpImage
= QImage(rawImgBuffer, img_width, img_height, image.format ); //image.format=RGB888
QBuffer bufferJpeg(&ba);
bufferJpeg.open(QIODevice::WriteOnly);
tmpImage.save(&bufferJpeg, "JPG");
QByteArray finalJpgBuffer = bufferJpeg.data();
It works fine but the cpu load is too high (I have a lot of threads that do this operation a lot of time each second).
Reading the Qt documentation I found this article: Hardware Acceleration &amp Embedded Platforms.
If i understood, I can use the QPainter class to execute gpu operations...
Is it possible to do this convertion (from raw to jpg) using this class? (or another similar Qt class that use hardware acceleration (gpu))!!
My application need to be platform indipendent.
Thanx at all.
I don't think QImage uses the GPU to generate a jpeg.
This probably wouldn't help (except on very limited CPUs) since the transfer time of getting the data back out of the GPU would normally dominate. The reason for using hardware acceleration for display is that the result is then already in the GPU ready for display.
As far as I know decoding of image formats (jpeg in this case) is not handled by QPainter. It is done by Qt using libjpeg, which is controlled by Qt using a plugin. You can find the plugin in qt_source_tree/src/plugins/imageformats/jpeg. That is simply using the library you have available on your system (libjpeg.so in Linux). If it is hardware accelerated or not, it is up to your system.
I had a case in which hardware decoding required to use a specific library. In that case I had to create a specific Qt plugin to handle that.

qr code decoding on uC

i am working on a project that uses qr code to check in guest at an event. i intended to implement it as a mobile app on android but my professor require a hardware element to the project. so my question s are
can i do decoding of a qr-code image on a microcontroller with a CMOS camera and which one is recommended?
if not, is it possible to use a cmos camera with a microcontroller to take the picture and send it to a pc to do the decoding and which microcontroller is recommended?
any other suggestion will be appreciated
I wouldn't try to decode QR Code with something less powerful than ARM.
Ad 1.
Of course you can, but, as I said, I wouldn't try on something less powerful than ARM (unless you're a C ninja and you can fit into, say, AVR for this task).
Decoding QR code itself isn't that hard and I you'll be able to write it by yourself (or use existing library).
Ad 2.
You'll need some connectivity to do that. There are many Bluetooth, Ethernet and WLAN boards around (in my experience, best choice may be Bluetooth, you may get away without implementing network stack).
Useful link.
Decoding QR codes is relatively easy as barcodes go. You can use source code from the ZXing library, running on the server side (it's primarily Java) to do the decoding. Decoding is "fast"; on the original Android (ARM7) devices it would still decode in about 100ms.
But I think your question is about image quality. I am not familiar with the output of CMOS sensors, but for QR codes, you don't need color data and you don't need much resolution (240x240 works for most QR codes). If anything the issue is focus.

DiVX Decoder for AIR

I am building a video player using Flex for my desktop. With AIR, is it possible to write a decoder to play AVI and .MOV on my system or do such solutions exist?
what i did to my project is i convert uploaded avi to flv, remove the avi after conversion and play the flv. just look for avi to flv converter
It is definitely possible, but I doubt such an approach is trivial. And you will not be able to make use of hardware acceleration. A big complaint about lack of performance in The Flash Player is lack of hardware acceleration when playing video.
If it is important to play AVI / MOV files, I would strongly suggest you look into players that already do this (Quicktime and/or Windows Media PLayer) which are already set up to handle issues like the numerous codecs an AVI file can be encoded in and use of hardware acceleration as appropriate.
If you're still desire to make this all in the Flash Platform, converting the files to FLV is going to be a lot easier on you in terms of development time than writing your on codecs. Camtasia is one software that you can use to convert, but you have to do so in real time, recording the screen. I have found it to be like a swiss army knife of video conversion.
Free conversion tools I have tried balloon file size up astronomically.

Actionscript PNGEncoder performance and UI blocking

I'm trying to use PNGEncoder to encode a bitmapData object into a png ByteArray so I can send the data to the server. Everything would be peachy except the bitmapData is 4000x4000px and when I run the PNGEncoder.encode function on it the whole app stops (UI is blocked) for 5-8 seconds while it runs. Does anybody have any suggestions on how to not make it block so bad, I read about chunking up the process (since you can't multithread in AS3) but can't find any sample code on chunking up the process.
Thanks,
Sam
In addition to Arthur's comment, you could also write it in C/C++ for Alchemy, since alchemy supports green threads. Like PixelBender, Alchemy also requires Flash 10.
There are mainly two ways to do this.
a) Use pixel bender:
You can off load the work to pixel bender (a shade like language in as3). This has the advantage of using the gpu on some cases, but it also is assynchronous and non blocking (runs on another thread). But it does require player 10+. I haven't seen a pixel bender png encoder, and to be honest, it may not be possible (I am not familiar enough with png encoding to tell), but it might be an option. This is, performance wise, the best you can get. More info here
b) Use chuncking. Basically, you rewrite the encoder to encode blocks (lines, columns or a smaller area), and hook that to an enter frame event, each frame you'd call next on your encoder, until there is no more encoding to do. Zeh has a neat LWZ chunked encoder with source code that might give you insights into the details.
Cheers
Arthur
Another shameless plug!
You can use my recently completed PNGEncoder2 library (also requires Flash 10+), which handily supports gigantic images. It does proper asynchronous encoding, with no single compression step at the end. Additionally, it's really fast ;-)
Grab it from GitHub (README), and check out the benchmark comparing it with other encoders on my blog post.
It's highly tuned for speed, and uses the Alchemy opcodes and domain memory to speed it up (thanks to Haxe), so it should be comparable to anything you compile using Alchemy.
You could encode multiple PNG files separately and send them to the server. Once on the server you can reconstruct the larger image.
It's for JPEG encoding, but should be useful - look a this post http://segfaultlabs.com/blog/post/asynchronous-jpeg-encoding/
As Arthur Debert said, you can use chunking. I'd suggest that instead of encoding once/frame, you try a setTimeout( chunkingFunction, 0 ); approach. A timeout with a 0 ms delay will happen as soon as possible, allowing the chunking to process quickly but without crushing the UI.

Resources