Lossless video compression - Now with less bytes!

Locked
User avatar
Sir_Lagsalot
Joined: Mon Jun 23, 2003 6:42 pm
Org Profile

Lossless video compression - Now with less bytes!

Post by Sir_Lagsalot » Sat Apr 17, 2004 12:25 pm

Lagarith is a lossless video codec I've been working on: http://lags.leetcode.net/codec.html
It compresses better than Huffyuv (and other lossless codecs I've come across) in every situation I've seen. The trade-off is speed naturally, it tends to encode at about half the speed Huffyuv does, and the decode speed is bit slower than the encode speed in most cases. More info and some numerical comparisons to Huffyuv can be found on the site.

Reasons I would recommend this codec:
Size matters and video will not be used often (archived lossless master copy, or if you have to send a lossless file to someone else)
The video is very compressable - Lagarith will absolutely mop the floor with Huffman for things like credits.
The video is very uncompressable - Lagarith can compress scenes that Huffyuv would expand, and purely random video was only expanded 0.25 percent in Lagarith; the same video crashed Huffman.

This was primarly tested with Virtualdub, so thats what I would recommend using. If you come across any errors in the codec, let me know.

User avatar
Zarxrax
Joined: Sun Apr 01, 2001 6:37 pm
Contact:
Org Profile

Post by Zarxrax » Sat Apr 17, 2004 12:32 pm

If it compresses "Manga Maniac AMV" at 59.2% the size of Huffyuv, then it must be good!

User avatar
AbsoluteDestiny
Joined: Wed Aug 15, 2001 1:56 pm
Location: Oxford, UK
Contact:
Org Profile

Post by AbsoluteDestiny » Sat Apr 17, 2004 12:37 pm

Excellent work!

Any plans for YUV colorspace support? YV12 would be particularly wonderful.

User avatar
Zarxrax
Joined: Sun Apr 01, 2001 6:37 pm
Contact:
Org Profile

Post by Zarxrax » Sat Apr 17, 2004 12:39 pm

And RGB32.

User avatar
Sir_Lagsalot
Joined: Mon Jun 23, 2003 6:42 pm
Org Profile

Post by Sir_Lagsalot » Sat Apr 17, 2004 1:36 pm

I considered YUV, but have decided against it for the time begin due to the issue with converting to RGB for programs that can't handle YUV. Basicly, there are different methods for converting to and from YUV, and thus my implementation would likely not match what the encoder would have used; that is a program like Avisynth's YUV to RGB would produce different output than my codecs conversion from YUV to RGB, so you would get diffent video depending on where the conversion was done.

User avatar
jonmartensen
Joined: Sat Aug 31, 2002 11:50 pm
Location: Gimmickville USA
Org Profile

Post by jonmartensen » Sat Apr 17, 2004 1:43 pm

I'm not in full understanding of the details, but the numbers speak for themselves.

Cool
Image

User avatar
Kalium
Sir Bugsalot
Joined: Fri Oct 03, 2003 11:17 pm
Location: Plymouth, Michigan
Org Profile

Post by Kalium » Sat Apr 17, 2004 1:44 pm

Can we see source? If so, some of us (not neccesserily me) might be able to help improve efficiency.

User avatar
Tab.
Joined: Tue May 13, 2003 10:36 pm
Status: SLP
Location: gayville
Org Profile

Post by Tab. » Sat Apr 17, 2004 2:12 pm

Very nice. The only thing I'd be concerned about are the heavy patents on arithmetic coding, though I think ffv1 makes use of it, so I wouldn't worry unless you see ffmpeg go down :p

The gain is impressive. 70% of huffyuv, and according to my calculations, on my test sequence, only 120% larger than ffv1 if in yv12 colorspace. That's something for a one man project. I wonder if more of the gain comes from the arithmetic coding or the selective RLE. Good ideas.

Minor bug, it crashes dshow.
I considered YUV, but have decided against it for the time begin due to the issue with converting to RGB for programs that can't handle YUV. Basicly, there are different methods for converting to and from YUV, and thus my implementation would likely not match what the encoder would have used; that is a program like Avisynth's YUV to RGB would produce different output than my codecs conversion from YUV to RGB, so you would get diffent video depending on where the conversion was done.
There's a lot of confusion in the area, but the correct matrices seem to be (assuming unsigned RGB -> signed YUV and back)

Code: Select all

Y =     0.299R +   0.587G +   0.114B - 128
Cr = -0.16874R - 0.33126G +   0.500B
Cb =    0.500R - 0.41869G - 0.08131B
for encoding and

Code: Select all

R = Y +                1.402Cb + 128
G = Y - 0.34414Cr  - 0.71414Cb + 128
B = Y +   1.772Cr              + 128
for decoding.

That's what I've settled on after going through a lot of papers that agree/disagree.
The only question is whether to use CCIR 601 or not.
Furthermore, AFAIK avisynth uses different numbers. For the sake of compliance, you could just stick to whatever vdub and avisynth use.

User avatar
Brad
Joined: Wed Dec 20, 2000 9:32 am
Location: Chicago, IL
Contact:
Org Profile

Post by Brad » Sat Apr 17, 2004 3:44 pm

Okay. I am hardly any kind of expert at all on video and compression and whatnot, so my tests and opinions probably won't really amount to a whole lot, but I figured I'd post my findings anyway.

I made a short movie in flash that had just animated text and gradients, with a lot of different colors. I wanted to do it like this so I could confirm for sure that there is nothing lossy going on. Had I tried it with like DVD video, there's still a bit of compression already there, so it'd be hard to tell where it was coming from. Anyways, the movie was about 8.6 seconds long, 246 frames, at 30fps. I exported the movie at 720x480.

Well, the first time around, I forgot that when Flash exports to AVI, any symbol that is labeled as a Movie Clip, doesn't play. So all I got was 246 frames of black video. But the file sizes were pretty interesting to see anyways:

Flash Movie Export Test 1 - Black Video
720x480 - 30fps - 8.6 seconds - 246 frames

Uncompressed - 249,085kb
Huffyuv 2.2.1 - 62,278kb
Lagarith - 8kb

Hehehe. So, that showed me that Lagarith handles solid colors (or at least black) much better than Huffyuv.

So I went back and changed the Movie Clips to Graphics so they'd play when exported to AVI, and re-rendered, and got this.

Flash Movie Export Test 2 - Animated Text, Colors, and Gradients
720x480 - 30fps - 8.6 seconds - 246 frames

Uncompressed - 249,085kb (duh)
Huffyuv 2.2.1 - 70,997kb
Lagarith - 24,837kb

NICE :) Quite impressive! Zoomed in on the Lagarith video and didn't see any signs of quality loss.

So anyways, I wanted to go ahead and see how well it worked with actual video (in this case, rendered CG, not anime). So I went ahead and recompressed my FF8 Iron Chef video from a few days ago. Keep in mind this was edited in, and exported in FF8's native video settings of 320x224 and 15fps (suck)

CG Video Test - Final Fantasy 8 Iron Chef Video
320x224 - 15fps - 01:18 - 1148 frames - No Audio

Huffyuv 2.2.1 - 89,116kb
Lagarith - 58,530kb

Once again, quite nice! As seen it's not as big a ratio as before, but it's a different kind of video so thats to be expected. So, right on :D The Lagarith did encode at about 60% the speed as the Huffyuv. It's also a bit slower at scrubbing/seeking than Huffyuv (which was explained in the original post). What it seems to boil down to is, if you need the space, go with Lagarith. If you need the speed, go with Huffyuv. Which... has already been said.. So I'm saying it again.. What? Ya wanna fight about it?!

So all in all, great new addition to the video codec arsenal :) I'm sure I'll be using this for stuff eventually.
Image
Ask Brad an After Effects Question! - Forum - Site

User avatar
Kalium
Sir Bugsalot
Joined: Fri Oct 03, 2003 11:17 pm
Location: Plymouth, Michigan
Org Profile

Post by Kalium » Sat Apr 17, 2004 4:43 pm

Am I the only one who thinks this should be added to the AMVapp? It would certainly be handy for those with hard drive space issues (not that I have any - >100 GB free).

Locked

Return to “Video & Audio Help”