Log in

View Full Version : New experimental Lossless codec -- needs your help


TheRealMoh
5th April 2003, 22:25
Newest version is 004, download below

Note to moderators: I'm posting this here because the code is in need of your help. Although the current code works, it's not ready for wide release. If you feel this thread should be moved, please do so.

I've spent a bunch of time writing a new codec. It's based loosely on the LOCO-I algorithm.

Summary:
- Lossless file size if about 70% of Huffyuv
- lossy can decrease file size another 10-20% percent
- about 1/4 the speed of huffyuv :-<
- Stores YV12 natively
- GPL: (C) 2003 Mohammad Rezaei

TODO:
- Performance.
-- calcLoco can be vectorized. Part of comp_one_pel can be vectorized.
-- riceEncode can not be easily vectorized.
-- unlikely to be made more than 50% faster
- YV12:
-- conversion to YUY2 and RGB after decompression
- interlacing
-- is there a flag indicating interlacing in the incoming images? if so, store it.
-- a quick test showed that unless most of the video is highly combed, it does not make sense to compress fields separetely.

Essentially, I've hit a wall with the code as far as performance goes. You guys are the closest thing I can find to video related performance experts. I need your help in tuning this codec so it can be more useful. I'm not sure how much more time I can spend on this, so if someone wants to take this over, that's fine too.

The project was inspired by the YV12 codec thread in this forum. Feel free to test the codec, but please don't store anything important using this codec: the internals may change.

The code is based on huffyuv and is GPL, so please don't release binary only versions.

Your help is much appreciated.

Edit note: removed loco001.zip, added loco002.zip (small bug fix) down below.

Dali Lama
5th April 2003, 23:49
Hi Moh,

Edit: I guess you know about Marc FD's VBLE codec. Perhaps you can try to PM him or "-h"?

Take Care,

Dali

TheRealMoh
6th April 2003, 04:37
Here is a small bug fix.

Guest
6th April 2003, 05:35
Originally posted by TheRealMoh
Here is a small bug fix. Please describe the bug when posting bug fixes.

DDogg
6th April 2003, 05:53
Your readme indicates this is installable without a compile, however you did not include the DLL. Was this your intention?

TheRealMoh
6th April 2003, 06:32
@neuron2:
sorry. Changes to 002:
- GUI was not accepting "0" for max loss.
- When in lossless mode, it's slightly faster.

@DDogg:

Here is a binary release of 002.

sh0dan
6th April 2003, 09:23
(Copy/Paste from an earlier posts I made regarding ffvfw)

Regarding colorspaces, it would of course be a good idea to support all output formats. Any input format would also be optimal. XviD provides most conversion routines.

YV12 -> YUY2 - use AviSynth routines (if possible). These routines have better chroma upsampling, and optional interlaced handling.
There _must_ be an option to select interlaced conversion. Sort of: Use interlaced upsampling, if more than 'n' lines, would be best.
There would have to be special adaption if width is not mod-16, since AviSynth has larger pitch in these cases. I would be glad to help out here.

YV12 -> RGB - use XviD conversion routines. Unfortunately they are not qualitywise optimal, but they are fast and has support down to mod-8 width.
Interlaced upsampling is also a problem here.
A solution could be to use AviSynth YV12 -> YUY2 and also use AviSynth YUY2 -> RGB. This will be slower, but on the other hand it would be possible to properly support interlacing and have optimal chroma upsampling.

It is also possible to modify the existing AviSynth assembler RGB24->YUY2 to support 24bits.

So to conclude, you can find most conversion routines needed in AviSynth - the only problem is interlaced YV12 -> RGB.

Link to the latest convert_yv12.cpp (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/avisynth2/avisynth/convert_yv12.cpp?rev=1.10&only_with_tag=MAIN&sortby=date&content-type=text/vnd.viewcvs-markup).
There are MMX and ISSE YUY2 -> YV12 (interlaced and noninterlaced) and YUY2 -> YV12 (interlaced/non-interlaced).


Lastest XviD (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/avisynth2/avisynth/convert_xvid.cpp?rev=1.1&only_with_tag=MAIN&sortby=date&content-type=text/vnd.viewcvs-markup) conversion routines - adapted for MASM, if they are of any help. No interlaced handling, and sub-optimal chroma interpolation.

The best way for lococodec to handle this would probably to be able to pass through material, if possible, or use the simplest possible conversion - this does include much work though - but AviSynth has assembler routines for most of these.

|YUY2 -> RGB32 (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/avisynth2/avisynth/convert_yuy2.cpp?rev=1.1&only_with_tag=MAIN&content-type=text/vnd.viewcvs-markup)| - |MMX RGB32 -> RGB24 (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/avisynth2/avisynth/convert.cpp?rev=1.16&only_with_tag=MAIN&content-type=text/vnd.viewcvs-markup)| - |MMX YUY2 -> RGB24/34 (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/avisynth2/avisynth/convert_a.asm?rev=1.4&only_with_tag=MAIN&content-type=text/vnd.viewcvs-markup)|


IMO any VFW codec should be able to output in (interlaced/progresive) YV12, YUY2 and RGB24/32.

ominte
8th April 2003, 16:18
pardon my ignoranance TheRealMoh but i can't view any material encoded with loco002. Any help would be appreciated :).

Otherwise nice job on the compression my tests show loco002 lossless reduces file size by 8% when compared to VBLE. Also I am getting encoding speeds of around 20 fps on an AMD +1600, nice.

terwin
8th April 2003, 19:05
The same problem here, I can't decode the Loco-movies. But the encoder works fine for me. :D

cu terwin

TheRealMoh
9th April 2003, 05:04
@terwin & ominte

How you view the output depends on the color space (right now). If you compress YUY2 or RGB, you should be able to play it (but you need a very fast computer). Better yet, you should open it in virtualdub.

If you compress YV12, the only way to view the video is to create a small avs script:

video=avisource("C:\temp\yv12test.avi")
video.ConvertToYUY2()

You can then load the avs as normal.

The automatic conversion of YV12 is on the todo list, but I'm concentrating on performance right now.

terwin
9th April 2003, 07:57
Ok, thanks for the quick answer. The problem was YV12.:rolleyes:

cu terwin

ominte
9th April 2003, 10:22
Thanks for your help, everything is working fine now :) . Any planned support for YV12 in the future?

sh0dan
9th April 2003, 11:34
@TheRealMoh: YV12 support is quite important, as all YV12 <-> YUY2 is lossy. Also YV12 should give additional compression, due to the chroma information.

TheRealMoh
10th April 2003, 00:09
@omnite

I'll code YV12 -> YUY2 conversion during decoding right after I'm done with performance stuff. I'm leaving on vacation soon for about 10 days, so probably 3 weeks.

@sh0dan

I'm not sure YUY2->YV12 is necessary. This is a lossless codec afterall. It would be nice, but I don't think anyone would use it. The way I see it, a lossless codec has two uses:

1) Capture. This requires real time encoding. That's why I'm concentrating on performance right now. I'm not sure conversion to YV12 would slow things down or speed things up. All captures cards I know are YUY2 natively.
2) Intermediate step where quality is important. In this situation, I doubt people would choose to lose 1/2 of UV planes.

Again, I'm not saying it's a bad idea, just not one high on the priority list.

Maybe you know the answer to this question: is there anything in the avi api's that deals with interlacing? I need to know if the source is interlaced so I can do the YUY2->YV12 conversion correctly.

ErMaC
10th April 2003, 00:26
Unfortunately there is nothing in the AVI standard to flag interlaced or non interlaced. The way Huffyuv deals with this is it assumes anything over a certain verical resolution is interlaced (288 vertical resolution by default). Then what it does is splits the frame into the two fields and encodes them separately for supposedly better compression.
Doing this in YV12 colorspace causes a problem because the chroma sampling varies between interlaced and progressive footage. The only way you could properly handle this, in my opinion, is to add a checkbox in your codec's configuration screen for interlaced encoding.

MrTibs
11th April 2003, 18:29
Personally, I appreciate the work. I'd like to get an addional 30% compression over Huffy during capture if possible. With the CPU's increasing at present rate, we could even use "slow" codecs for live capture. For now, however, sometimes I run my Huffy captures through Avisysnth with filtering and resizing and save back into huffy. This technique allows me to reduce my Huffy files by 80-90% before I convert to Mpeg1 (KVCD). I do this for three reasons:

1) Lossy (Mpeg] conversion requires much fiddling to get it perfect.
2) Lossy encoding is MUCH faster since Avisynth filters are not invovled.
3) Filtering through Avisynth is much faster then Mpeg conversion so I can make room on my HD for another TV capture very quickly.

TheRealMoh
11th April 2003, 23:29
I spent some time optimizing (vectorizing) the code for P4's. This requires a P4, so there are now two binaries P4 and non-P4.

It seems the vector operations on a P4 are not alot faster than the interger ones (probably because of the dual, dual-speed ALUs). The P4 code is about 10% faster now.

I'm going on a vacation for about 10 days, so this the last release for a while. Next on the todo list is the color space conversions.

The attachment has the source plus 2 binaries.

mf
12th April 2003, 10:10
Originally posted by TheRealMoh
2) Intermediate step where quality is important. In this situation, I doubt people would choose to lose 1/2 of UV planes.
That intermediate step is most likely to be converted to MPEG1/2/4 or other YV12 codecs. So why not convert to YV12 directly (or, in the case of an MPEG source and AVS 2.5 processing, don't convert it at all) and save the space.

cweb
22nd April 2003, 16:26
Perhaps updating it to use YV12 would also speed it up.

I experimented with both Marc's new yv12 huffy codec and with yours.
Marc's seems faster and has no frame drops, unlike yours.

I found your codec interesting, I hope you will continue developing it.

TheRealMoh
27th April 2003, 23:35
I'm back from vacation and here is a new version:

Changes:

- Lossy compression is improved (compression wise).
- YV12->YUY2->RGB is implemented during decompression.
- replaced the field threshold with a simple check box: check it if the source is interlaced. The setting is only used during compression.

If you have a YV12 interlaced avi that was encoded prior to this release, it won't be properly decoded to YUY2/RGB. You can re-encode the clip with the "source interlaced" checkbox checked.

@cweb & mf
Thanks for the comments. I still haven't decided if/how I'll implement YUY2->YV12 during compression.

jorel
28th April 2003, 02:20
@TheRealMoh

new version?
where is it please?

thanks in advance.

TheRealMoh
28th April 2003, 03:06
@jorel

Just gotta wait for the mods to approve the attachment :)

Guest
28th April 2003, 04:23
@TheRealMoh

> replaced the field threshold with a simple check box:
> check it if the source is interlaced. The setting is
> only used during compression.

I assume your upsampling during decompression to YUY2/RGB will be able to follow the setting used during compression. Please confirm.

TheRealMoh
28th April 2003, 04:46
@neuron2

yub, the setting is saved and used during decompression. The upsampling right now is very simple (repeated pixels, no averaging). Eventually, I'll replace it with an average.

sh0dan
29th April 2003, 20:39
(Thread was taken over by hostile moderators) :)

- Thread split into YV12 chroma placement (http://forum.doom9.org/showthread.php?s=&threadid=52151)

HarryM
2nd May 2003, 17:30
Originally posted by TheRealMoh
I'm back from vacation and here is a new version:

Changes:

- Lossy compression is improved (compression wise).
- YV12->YUY2->RGB is implemented during decompression.
- replaced the field threshold with a simple check box: check it if the source is interlaced. The setting is only used during compression.

If you have a YV12 interlaced avi that was encoded prior to this release, it won't be properly decoded to YUY2/RGB. You can re-encode the clip with the "source interlaced" checkbox checked.

@cweb & mf
Thanks for the comments. I still haven't decided if/how I'll implement YUY2->YV12 during compression.

I can't install lococodec on Win98SE.

Filename 'lococodec.dll' has 9 chars.
Windows refuse this simple instalation procedure ("can't find file lococodec.dll", etc.).

It must be max 8 chars filename for instalation via *.inf, please.

TheRealMoh
3rd May 2003, 00:43
@HarryM

Thanks for the bug report. I'll rename the dll in the next release. For now, please rename the dll to lococode.dll and change all references in the .inf file. I think that should allow you to install it.

MfA
4th May 2003, 02:35
TheRealMoh (and Marc FD if he is reading this) :

Dont know if you are aware of these articles (http://www.ieeta.pt/~ap/journals.html), the top 2, ran across them while glancing through recent IEEE journals and they are pretty interesting. They describe a method of improving the performance of lossless coders for images with sparse histograms ... it might work well for animation.

TheRealMoh
6th May 2003, 05:27
@MfA

Thanks for links. Looks quite interesting. I'll try to hack some code to look at the sparsness of video.

zettai
11th July 2003, 10:56
Hmmm.... I was just going to try out this codec until I noticed that all the attachements have now disappeared :(

Does anyone know if this codec is available anywhere else?

zettai
11th July 2003, 11:00
Ah apologies, I found it reattached in the following thread:

http://forum.doom9.org/showthread.php?s=&threadid=53305