Tuesday, June 30, 2009

Publish Video Online from Samsung Digimax A503 MJPEG

The Samsung DIGIMAX A503 offers macro shooting as close as 20 cm. Using its macro shooting capability, you can create a vivid and clear image even for a small subject in a long range. Using its special macro capability, you can create clear, vivid shots even of small subjects at close range.

The DIGIMAX A503 supports the high-compression MJPEG format for enhanced video capability. It also lets you shoot a movie clip in VGA at 24 fps and play it on your TV without any degradation of image quality. You can choose the number of frames between 24 and 15 fps as desired. When a 512 MB memory card is used, up to 42 minutes of video recording is allowed.

The output video of Samsung DIGIMAX A503 is AVI (MJPEG), but it is inconvenient for sharing online. Convert MJPEG to FLV and upload file via the control panel, or use the HTML code to embed Flash video to web page.

Wednesday, June 24, 2009

View MJPEG Stream in Flex

I get to find a useful article about viewing MJPEG streams in Flex. Keep on reading if you are interested.

So, I'm learning Flex at long last. The reason for me finally taking up this challenge is that I finally found a project I believed it well suited to. You see, my family has lots of digital photos. About 9000 at last count. We keep these stored on a NAS in my office. All of our computers are set to show these photos as our screen savers. However, I've wanted a nice wireless digital picture frame that would randomly pull from this pool of images. Well, to make a long story short, I was unable to find a single wireless picture frame that could read from a Samba share. (And trust me, I've tried a lot of things.)

So, finally I became frustrated enough to take this into my own hands. I plan make my own ideal digital picture frame. I'm currently working on an Air application that will run in full screen and provide access to a range of picture frame components. Obviously, a part of this will display pictures. Other components will display weather information, stats on Alagad, and pretty much anything else I want to wire into my picture frame. Eventually, I'll buy a nice, thin, touch screen tablet PC, configure it to run my air app on load, get it professionally framed and hang it on the wall.

Now, one of the components I want this picture frame to show is a video stream from my daughters baby monitor camera. Actually, it's not really a baby monitor camera it's a more-or-less generic wireless surveillance camera. I don't have the model information any more and it's not branded at all. But, from research I've done there are a lot of these cameras which run the same software.

The camera runs a basic web server so I can pull up the camera and see either a still photo or a video stream in a Java Applet or ActiveX Control. I did a little playing around with the camera and discovered that the still photo is returned from a file called "image.jpg". Any time you request this file you get the latest image from the camera. So, my first attempt a hooking into the video camera was simply to request this photo over and over again and use that as the source for an Image object. This worked to an extent, but the Image object wouldn't refresh quickly enough and would as a result flicker. Beyond that, I had to make a complete HTTP request for each frame of the video and it had a very slow refresh rate. I was able to solve the flickering problem by having two images on my canvas and alternate setting the source of each image and hiding the other image.

I was happy to have accomplished that, but it just wasn't very nice. So I decided to do a little more research. The Java Applet on the camera was called xplug.class. Googling that revealed a few people who had decompiled the class and used that to discover that the camera actually streams video from a file named mjpeg.cgi. If you access this file directly you'll simply get a long stream of binary data which makes up the video feed from the camera. Obviously the Java Applet and Active X Control could read this stream and use it to display the video feed.

A little more research revealed that, sadly, mjpeg is not a standard but more of a technique. Mjpeg really is just a concatenated stream of jpeg images, one after another. I'm familiar with the JPEG format (at least to some degree) from my work on the Image Component. At least, I knew enough to know the first few bytes that mark a JPEG image (FF D8). So, I figured I'd look at the data in the video stream to see if I could figure it out. I captured a few seconds of the video to disk using Curl and opened it up in a hex editor. The first thing I noticed was that each frame of the video was denoted by an ascii string "--video boundary--". Looking a bit further into the file I discovered that I could find the markers that start an image. I tested cutting the bytes from the beginning of where I thought the JPEG would start to the last byte before the video boundary into a new file and saved it as a jpeg, which I was subsequently able to read!

I knew that if I could read the feed by simply starting at the top of the feed, find the start of an image and the end, cutting out that image, displaying it and repeating the process forever.

Simeon Bateman filled in the last little piece of data I needed to know to make this work. Namely, that you can simply provide binary data to the source property of an Image object and Flex will display the image.

So, after figuring out how to make a socket connection from Flex I was able to parse the video feed and display the video feed! I did still have the flickering problem but I solved it in a similar manner.

Attached to this blog entry is a final Flex Component which connects to the camera by URL and streams the feed. Anyone who has a use or it may use it, assuming your video feed is the same format as mine. This is my first real bit of AS3/Flex development though so don't be offended if I'm not doing things in the best way possible.

Here's an example usage of the component:

<webcam:webcamImage left="0" top="0" right="0" bottom="0" host="mycamera.com" port="80" />

You can also supply username and password properties to access password protected cameras.

If you have the MJPEG on hand, you can also convert MJPEG to Flash quickly. It allows simple editing and custom players.

Source: http://www.alagad.com/go/blog-entry/viewing-mjpeg-streams-in-flex

Wednesday, June 17, 2009

Pros, Cons and Tips for MJPEG

Photo-JPEG, MJPEG-A and MJPEG-B are the three JPEG-based codecs built into QuickTime. MJPEG stands for Motion JPEG. It is identical to Photo-JPEG except that the MJPEG codecs have translators built-in to support the different capture cards.

MJPEG is not the same as MPEG, although the names are confusingly similar. The primary difference is that MPEG provides temporal compression, while MJPEG only provides spatial compression.

Pros
MJPEG codecs are often used as storage formats for large files that need to be archived with good quality. It is a lossy codec, but at 100% quality, the image degradation is minimal.
At WWW data rates (5-20K), JPEG may produce better results than Cinepak.

Cons
All the JPEG codecs require significant amounts of CPU power and are not well suited to video playback at CD-ROM or higher data rates, except when assisted by a hardware capture card.
Large image and/or high frame rate movies usually don't play smoothly.

Tips
Avoid saving the same file multiple times with any JPEG codec, as the JPEG artifacts may build up and become objectionable.
To share the good quality video online, it is recommended to convert MJPEG to FLV with H.264 codec, which is also called as HD FLV.

Ideal source material: Video
Supported bit depths: 24-bit color, 8-bit greyscale
Compression time: Asymmetrical
Temporal compression: No
Special features: Supports Media Cleaner Pro 2.0's advanced data rate limiting
Encoder requirements: Any MacOS or Windows
Decoder requirements: Any MacOS or Windows
Encoder availability Built into QuickTime 2.5
Decoder availability: Built into QuickTime 2.5
Algorithm: Discrete Cosine Transform (DCT)
Manufacturer: Apple

Sunday, June 14, 2009

What is M-JPEG?

M-JPEG is also known as Motion JPEG. M-JPEG is a video format that uses JPEG picture compression in each frame of the video. Each video frame or interlaced field of a digital video sequence is separately compressed as a JPEG image. Frames of the video don't interact with each other in any way (like they do in MPEG-1, MPEG-2, etc..) which results in much bigger filesize, but in other hand, it makes the video editing easier because each of the frames has all of the information they need stored in them. It is often used in mobile appliances such as digital cameras.

M-JPEG is used in very high quality video captures -- normally as the raw data format which is edited and compressed into another format after the editing process is completed. M-JPEG is frequently used in non-linear video editing systems. Reproduction of this format at full speed requires fast JPEG decoding capability.

How to play MJPEG on browser?

Mozilla based browsers, such as Netscape and Firefox, have native support for viewing M-JPEG streams. Other browsers, such as Internet Explorer and Opera can display M-JPEG streams with the help of external plugins. Cambozola is an applet that can show M-JPEG streams in Java-enabled browsers.