View Full Version : most convenient color format for DivX encoding


aiXGen
17th April 2004, 00:23
Hi everybody!

Which is the most convenient color format for DivX encoding: RGB, YUY2 or YV12?
I want to crop an odd number of pixels from every side of the footage and I suppose, this cannot be done without converting to RGB. Should I convert it to YU12 afterwards?
Does it matter, if the footage is B&W (aside using a Greyscale filter)?

I would be glad for every clarifying post, thx.

Soulhunter
17th April 2004, 19:08
Hint... (http://forum.doom9.org/showthread.php?s=&threadid=37276) ;)


Bye

aiXGen
20th April 2004, 02:47
Thank you for your hint, soulhunter,
I have read Wilbert's YV12 FAQ before I started this thread. But I'm not quite sure, if YV12 is the generic colorspace for DivX and other MPEG4 encoders. Although sh0dan assured that it is (I hope he don't mind my question!), I would be more sure, if other people corroborate what he wrote.

Soulhunter
20th April 2004, 17:18
Yes, YV12 is the standardized norm colorpace for all* MPEG codecs !!!

EDIT: * Except some MPEG2 studio profiles n' such stuff...


Bye

aiXGen
21st April 2004, 14:24
Hi Soulhunter,

you are referring to the MPEG stream, right?
TMPEG (produces MPEG 1/2 stream) e. g. requires natively RGB input.
Does DivX support YV12 input natively or must a YV12 decompressor be installed?

CU

Soulhunter
21st April 2004, 17:32
Originally posted by aiXGen
Does DivX support YV12 input natively or must a YV12 decompressor be installed? AFAIK such stuff (YV12 decompressor) should be already included in Windows or DirectShow... :confused:


Bye

Wilbert
22nd April 2004, 15:03
TMPEG (produces MPEG 1/2 stream) e. g. requires natively RGB input.
Yes, but it converts it to YV12 (after post processing).

Does DivX support YV12 input natively or must a YV12 decompressor be installed?
What do you mean? DivX is a coDEC, its internal color format is YV12 and it outputs YV12. It can also decode it.

Only DivX3 outputs RGB (although it is internally stored at YV12).

SeeMoreDigital
22nd April 2004, 18:42
Can someone check and comment on the colour output of these (http://homepage.ntlworld.com/seemoredigital/XviD_Colour_Tests.zip) two XviD encodes please (total zip size 5.95MB)?

Cheers

Soulhunter
22nd April 2004, 19:33
VDub puts wrong color info into the avi via full processing mode!


So, both are YV12...

The one that shows up 12bit, was encoded with fast recompress...

The one that shows up 24bit, was encoded with full processing mode !!!


Bye

SeeMoreDigital
22nd April 2004, 20:30
Originally posted by Soulhunter
So, both are YV12 (12bit) !!! I have to admit. I don't know for certain!

Both were encoded using MPEGmediator, however, there is a setting in the application that lets you un-check "Export frames in YV12". When I do this with XviD I get 24bit colour!

If there are some people out there who can take the encodes apart and analyse the differences between them I would not mind knowing what they are please.

Cheers

Soulhunter
22nd April 2004, 20:52
Originally posted by SeeMoreDigital
Both were encoded using MPEGmediator, however, there is a setting in the application that lets you un-check "Export frames in YV12". When I do this with XviD I get 24bit colour!
So, this option in MPEGmediator does the same as the VDub one I talked about! It feeds the codec with YV12 (fast processing) or RGB (full processing) colorspace... But the DivX/XviD etc. encoder itself will always transform it into YV12 colorspace! Only the input colorspace info is stored in the AVI, not the one the video really has...


Bye

aiXGen
22nd April 2004, 21:36
Originally posted by Soulhunter
AFAIK thus stuff (YV12 decompressor) should be already included in Windows or DirectShow... :confused:
Originally posted by Wilbert
Yes, but it converts it to YV12 (after post processing).


What do you mean? DivX is a coDEC, its internal color format is YV12 and it outputs YV12. It can also decode it.

Only DivX3 outputs RGB (although it is internally stored at YV12).

My focus is on the encoder input stream. Since I have to convert the footage to RGB for cropping, I'd like to know which the supportetd input format(s) of DivX is(are) to avoid unnecessary colorspace conversions. Considering your posts and the YV12 FAQ, I assume DivX supports at least YV12 input.
I confess, it would be more understandable if I had written: Does DivX support YV12 input? :D

Wilbert
22nd April 2004, 21:44
My focus is on the encoder input stream. Since I have to convert the footage to RGB for cropping, I'd like to know which the supportetd input format(s) of DivX is(are) to avoid unnecessary colorspace conversions.
Like I said, the video is always stored as YV12 in DivX/XviD. You can pass a YUY2/RGB stream to the encoder, but then the encoder will convert it to YV12. I hope it's clear now :)

Soulhunter
22nd April 2004, 21:45
Btw, with AviSynth you dont have to convert -> RGB for cropping... ;)


Bye

aiXGen
23rd April 2004, 00:03
@ Wilbert:
OK, I resume: DivX accepts YV12/YUY2/RGB colorspace. Since YV12 is standard for MPEG, this colorspace will not be converted and is therefore the most convenient for DivX encoding.

@ Soulhunter:
Originally posted by Soulhunter
Btw, with AviSynth you dont have converting to RGB for cropping... ;)

Oh, how do you do that?
Given a footage with YV12/YUY2 it isn't possibel to crop an odd number of pixels on each side (e.g. 5 on the left, 7 on the right). And I have little hope that resize will do the job (crop and resize) without converting to RGB.
Any idea?


Thank you guys very much for your help :)

DigitAl56K
23rd April 2004, 02:18
Remember that DivX Pro has a built in Crop/Resize, so there is no need to do YV12->RGB->YV12 for crop.

Soulhunter
23rd April 2004, 19:25
Originally posted by aiXGen
Oh, how do you do that?
Given a footage with YV12/YUY2 it isn't possibel to crop an odd number of pixels on each side (e.g. 5 on the left, 7 on the right). And I have little hope that resize will do the job (crop and resize) without converting to RGB.You are confusing me... :confused:

Could you give a example of what you like to so ???


Like this:

Input resolution -> crop values -> output resolution...


Note: Your final resolution should be at least a multiple of 4, even better 16 !!!


Bye

SeeMoreDigital
23rd April 2004, 19:33
Just to try and get down to the 'heart of the matter' are some of you guys having problems cropping and resizing your Mpeg4 (DivX) encodes?

RadicalEd
23rd April 2004, 23:48
Soulhunter: what he means is this - you can't crop by odd values to even values with yv12. For instance, crop(7,0,-9,-0) instead of crop(8,0,-8,-0). Converting to rgb solves that problem.

Soulhunter
24th April 2004, 17:17
Ok, got it now... ;)

In this case it wouldn't make much sense to convert back to YV12...

But why not cropping one pixel more or less as RadicalEd alraedy suggested?


Bye

Jeffster
25th April 2004, 05:43
Originally posted by aiXGen
Originally posted by Soulhunter
Btw, with AviSynth you dont have converting to RGB for cropping...

Oh, how do you do that?
Given a footage with YV12/YUY2 it isn't possibel to crop an odd number of pixels on each side (e.g. 5 on the left, 7 on the right). And I have little hope that resize will do the job (crop and resize) without converting to RGB.
Any idea?


You can use an AviSynth script to crop an odd number of pixels in the following way (even in YV12, and therefore avoid using other filters and that require RGB):

Example.

Crop(5,0,710,480).LancozResize(640,352)
is the same as
LanczosResize(640,352,5,0,710,480)

The first line will throw an error because you are trying to crop odd values, but the second line will work because AviSynth crops and then resizes in the one operation.


Jeff

lordadmira
17th September 2004, 18:58
Originally posted by Jeffster
LanczosResize(640,352,5,0,710,480)

The first line will throw an error because you are trying to crop odd values, but the second line will work because AviSynth crops and then resizes in the one operation. This works because the original YV12 samples are destroyed within the resize engine and then recreated in the resized output. That's why this is properly called "resampling" rather than "resizing".

A hackish way of odd-cropping while keeping the same resolution/aspect and staying in YV12 space would be a Resize(636,480,3,0,636,480) line. ;)

LA

lordadmira
17th September 2004, 19:02
Originally posted by RadicalEd
Soulhunter: what he means is this - you can't crop by odd values to even values with yv12. For instance, crop(7,0,-9,-0) instead of crop(8,0,-8,-0). Converting to rgb solves that problem. Actually converting to 4:4:4 space would be the best way to handle this. Or use my null resize hack.

LA

PS sorry for resurrecting such an old thread but I just had to. :cool:

RadicalEd
17th September 2004, 20:05
Originally posted by lordadmira
Actually converting to 4:4:4 space would be the best way to handle this.

Avisynth doesn't handle 4:4:4 YUV :|

aiXGen
19th September 2004, 00:10
@lordadmira:
I am glad that you have resurrected this thead. The information you have provided is exactly what I'm looking for.

What is your 'null resize hack', this: Resize(636,480,3,0,636,480)?

I also would like to thank everyone, who has contributed to this thead. I have considered every information here. Unfortunately I was forced to abandon this topic due to other tasks, but I will get back to it as soon as possible.:)

aixgen

lordadmira
19th September 2004, 01:46
It's a resize operation that doesn't actually resize. It just crops. That line means to crop out a 636x480 frame and resize it to 636x480. i.e. nothing. U can use this to use the resize's cropping ability to odd crop at each edge. The total crop must be even.

LA