Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

JPEG compression

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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, it`s not as simple as calling a function to compress a bunch of data.

Once you have learned the entire process, I`m 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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!