# JPEG compression

This topic is 2867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know most of you would resist this urge, but I'm writing a very basic customized video container file (not a codec, no audio) for my own personal projects. The only real use I plan on using this for is for things such as ingame videos that can be easy to read and are platform independent (meaning I don't have to worry about what APIs to use if I'm porting to Xbox, and what not). I really don't want/need to use any pre-existing file formats and want to keep my code portable to make it really straight forward for recording videos in my games and other projects. My video container works fine atm, but now I need to compress the frames (with preferably a lossy format) to prevent the video files from getting so massive. RLE won't suffice and LZW is good, but not good enough. Therefore I'd like to use JPEG compression for frames.

For example: A 10 second video at 320x240x32 at 30fps while skipping every 3 frames is still 24mb (approximately). That's partly because each frame would be 300kb. I know that using 32-bit colour is indeed major overkill, but that's the first bit depth I tested it with. So, is there a way to compress a buffer using the JPEG compression method? I did look at IJG but from what I can see it only allows me to save and load JPEG files, but I probably overlooked one of the APIs. Any ideas? Thanks.

Btw, I'm sure people are going to implore that I use a pre-existing format, but chances are no one is going to sway my desire to complete this project.

##### Share on other sites
The IJG library provides hooks for input and output. You can do in-memory compression just fine, for example. The documentation supplied with the library explains the extension points and how to use them.

I have a C++ wrapper, if you're interested, even if only to borrow the I/O customization code

##### Share on other sites
MJPEG has been available since forever.

So, is there a way to compress a buffer using the JPEG compression method? I did look at IJG but from what I can see it only allows me to save and load JPEG files,[/quote]

Any JPEG library will do it. Just choose the one you want. It should be part of standard library with many languages.

Otherwise there's always libjpeg.

One problem with JPEG compression are artefacts. Lack of temporal compensation and sub-pixel deblocking and motion compensation adds considerable noise, especially if using such low resolutions, where pixels are scaled up. Other problem might be performance. Bitblt is relatively fast, but fast path isn't important anymore with UIs moving to hardware accelerated surfaces. So popular decoders use custom hardware and special driver support to drastically reduce CPU load. Something like this is especially important for mobile devices which simply lack the power to do real-time decoding on CPU or where it's impractical.

##### Share on other sites
In addition to lossy compression, you could try using interframes. You take a keyframe which is just a normal JPEG compressed frame, then for each frame after that you take the difference and encode that as a JPEG frame. If there is a lot of temporal continuity, you will save a lot of space.

##### Share on other sites
Have you considered using DXT instead of JPEG? DXT1 should suffice for this purpose, giving you frames one-eighth the size of uncompressed data, together with the bonus that if you're sending the data to the 3D hardware as a texture it can go directly without needing any intermediate software steps.

##### Share on other sites
If you just want to apply the jpeg compression method to your image buffers but keeping your own file format, you should first know how the process is performed, its not as simple as calling a function to compress a bunch of data.

Once you have learned the entire process, Im sure you will find a good library to perform the tasks you need or, if you want to create one yourself, works either way. Good luck!

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 44