Log in

View Full Version : Avisynth Colour Tests


wiseant
23rd June 2007, 23:50
RE Avisynth Colour Tests

I am pretty new here so I hope I have put this in the right category - please let me know

I recently started using ffdshow's Huffyuv codec for Video Capture using some Avisynth Filters

I was getting some unusual bitrates using this codec so I decided to do some tests using VirtualDub MPEG-2: using 480x480 capture size with VDub built-in crop so Image Size is 472 x 464

1. set "CustomFormat" to 32bit RGB
2. set "CustomFormat" to 24bit RGB - should be .75x kbps of 32bit
3. set "CustomFormat" to 16bit RGB - should be .50x kbps of 32 bit
4. set "CustomFormat" to YUY2 - should be same as 16bitRGB
5. set "CustomFormat" to YV12 - should be ??

Results:
The RGB32 kbps is 213143; the RGB24 kbps is 161198; the RGB16 kbps is 108943; the YUY2 kbps is 108023;

this DOES make sense based on
24bit/32bit * 213143 = 159857.25 (close enough)
16bit/32bit * 213143 = 106571.5 (close enough)
YUY2 should be the same bitrate as 16bitRGB (close enough)

Now, the only two ways I could get YV12 clips is use
1. lagarith Codec in YV12 format (a minor drawback because both height and width have to be mutiples of 16 - so i can't do my standard cropping)
2. ffdshow huffyuv with avisynth script enabled: ConvertToYV12(interlaced=true)

Now both of these YV12 captures did work but have very different bitrates:
Lagarith - even though the image size was larger (480x480 vs. 464x472) the kbps was 35538 which seems to make it close to "6bit" (6/32 * 213143 = 39964.3125) - actually less than 6bit because of the image size difference.

And the ffdshow huffyuv converttoYV12 was 45849 - which seems to make it close to "7bit" (7/32 * 213143) = 46625

(By the way, when I set the Custom Format to YV12 none of the Captures worked and I tried using DivX6.6.1, XviD, uncompressed and also tried different decompressors: DivX6.6.1 YV12, xvid.dll, xvidvfw.dll)

Ultimately my question is: what should the bitrate of a YV12 Capture be? and what should be its pixeldepth? 12? 8? 6? ?? and what is ConverttoYV12(interlaced=true) actuall doing to my YUY2 capture?

And, finally . . .
I can't open ffdshow huffyuv clips in VirtualDub1.6.19, VirtualDubMod, or VirtualDub MPEG-2 - obviously Windows Mplayer, MPlayerClassic and MPlayer GUI all open it (because it is directshow not vfw) - the only way I can open these in any VirtualDub version is by using an .avs file - but when I do this even when my "CustomFormat" was YUY2 and I didn't use ConverttoYV12 in my script - I am informed that these clips are YV12 not YUY2. The same thing happens if I open them in AvsP using either .info() or TMonitor it still shows YV12! when it should be YUY2.

Any comments or suggestions would be appreciated. TIA

(By the way I have read and studied the YV12 FAQ as well as lots of other colour space info)

Wilbert
24th June 2007, 00:32
(By the way, when I set the Custom Format to YV12 none of the Captures worked and I tried using DivX6.6.1, XviD, uncompressed and also tried different decompressors: DivX6.6.1 YV12, xvid.dll, xvidvfw.dll)
Your capture card/driver needs to support it.

I advice you to avoid capping in YV12. The reason is that if you capture interlaced stuff and you forgot to set the interlaced option when capping, your capture is screwed.

Ultimately my question is: what should the bitrate of a YV12 Capture be?
This can be anything. This has nothing to do with the color format, but depends on the codec settings.

and what should be its pixeldepth? 12? 8? 6? ??
YV12 is 12 bit. 6 bytes for 4 pixels (4 luma values, 1 U value and 1 V value) => 1 pixel = 1.5 bytes = 12 bits

ConverttoYV12(interlaced=true) actuall doing to my YUY2 capture?
If your capture is interlaced you should use that. It gives better quality. Of course your codec (end format) also needs to support that, otherwise you need to deinterlace.

I can't open ffdshow huffyuv clips in VirtualDub1.6.19, VirtualDubMod, or VirtualDub MPEG-2 - obviously Windows Mplayer, MPlayerClassic and MPlayer GUI all open it (because it is directshow not vfw) - the only way I can open these in any VirtualDub version is by using an .avs file - but when I do this even when my "CustomFormat" was YUY2 and I didn't use ConverttoYV12 in my script - I am informed that these clips are YV12 not YUY2.
The question is always how does the decoder output the stream. Does it leave the color format as it is, or does it convert it to some other format. I'm pretty sure that ffdshow huffyuv clips won't be converted in AviSynth. Is it really true that:

DirectShowSource("ffdshow huffyuv clip")
Info()


returns YUY2? Have you set ffdshow to output YUY2 instead of YV12?

wiseant
24th June 2007, 01:16
Thanks for the quick response Wilbert!

The reason that I am capturing in YV12 is so I can use Deen("c3d",1,9,12) on my Video Tape captures using ffdshow huffyuv avisynth script - it seems to work real nice - the clips are clean, the codec is lossless and the bitrate is quite manageable - and no dropped or inserted frames - makes it easy to encode to x264, XviD, or MPEG-2 without using any additional filters - I just add borders and do a BilinearResize to 720x480 or 704x480 or 640x480 . . . and get up to 50 fps encoding speed . . . and I always keep the interlacing . . .

RE Avisynth Info() and/or TMonitor()
Yes -I have tested several clips that I captured using ffdshow huffyuv using YUY2 format and they are all deemed to be YV12! - and I have not set the ffdshow output to YV12! So it must be a bug when Avisynth uses DirectShowSource - I noticed the same thing when I opened .avs files in the VirtualDub versions I use

And finally - I realized my computations using Lagarith and ffdshow huffyuv were incorrect because these are not uncompressed formats - but there still is quite a difference in bitrates between these two YV12 formats . . .

foxyshadis
24th June 2007, 06:02
What if you use DirectShowSource("...",pixel_type="YUY2") on an obvious interlaced capture source? If it comes back as YV12 or YV12->YUY2 conversion the chroma should be very badly blended. If it's native YUY2 everything should be okay. I'm guessing that something in the chain is signalling that it's YV12 or that YV12 is the first-choice output format when it isn't. If you have YV12 checked in ffdshow's output settings at all, it will always signal YV12 as the first-choice format, in that case not a bug of DSS. Maybe this needs a rethinking.

You can save uncompressed YUY2 and YV12 in virtualdub as well as RGB. Just make sure it's in fast processing mode.

The difference in bitrate and speed, btw, is the difference between huffman coding and arithmetic coding, mostly, and to a lesser degree their respective predictive modes.

Wilbert
24th June 2007, 13:19
RE Avisynth Info() and/or TMonitor()
Yes -I have tested several clips that I captured using ffdshow huffyuv using YUY2 format and they are all deemed to be YV12!
That's strange. Apparently for some reason ffdshow huffyuv converts internally to YV12 before outputting it to AviSynth. I will look at this. Like foxyshadis says, use DirectShowSource("...",pixel_type="YUY2") in the mean time.

The reason that I am capturing in YV12 is so I can use Deen("c3d",1,9,12)
As far as i know Deen doesn't support interlaced stuff. So, if you cap is interlaced, your video will be messed up. The best is to cap at YUY2 and use the script:

DirectShowSource(..., pixel_type="YUY2")
ConvertToYV12(interlaced=true)
AssumeTFF() # (or AssumeBFF) set the correct field order!
Bob() # or use any other bobbing deinterlacer you like
Deen("c3d",1,9,12)
AssumeTFF() # set the field order again (the same as above!)
SeparateFields().SelectEvery(4,0,3).Weave()

Or if the content is progressive:

DirectShowSource(..., pixel_type="YUY2")
ConvertToYV12()
Deen("c3d",1,9,12)


I recommend that you use PeachSmoother as denoiser. It's one of my favourite denoisers for analog caps.

scharfis_brain
24th June 2007, 13:23
ffdshow always puts out YV12 if it is checked in the output dialogue.

Even is "select nearest colorspace" is enabled it will still convert to yv12 instead of putting out the native colorspace of the video.

that's why I always visit the output dialogue before decoding something with ffdshow/ffvfw.

wiseant
24th June 2007, 17:00
Thanks foxyshadis, Wilbert and scharfis_brain !
I am going to look into this some more and digest your information . . .

wiseant
24th June 2007, 18:37
Hi All: I just did the following tests

Test 1 VirtualDub MPEG-2 Capture
A. Set CustomFormat to 480x480 YUY2
B. Set up ffdshow huffyuv:
Input
Force input colorspace (No)
Assume interlaced if height > 240 (Yes)
Flip picture (No)
Enable image processing (Yes)
C. Avisynth dialog boxes
Process whole image (Yes)
Avisynth (Yes)
Add ffdshow video source (Yes)
Input colorspaces YV12 (No) YUY2 (Yes) RGB24 (No) RGB32 (No)

In Test 1, although I checked Avisynth, there was no script to implement - I checked it so I could set YUY2 as the only Input colorspace

I opened up my capture in AvsP

with
DirectShowSource("D:\NewColourTests\yuy2-ff-hfyu.avi").info

ColorSpace: YV12
Video Pitch: 480 bytes
the actual width is 464 pixels

with
DirectShowSource("D:\NewColourTests\yuy2-ff-hfyu.avi", pixel_type="YUY2").info

ColorSpace: YUY2
Video Pitch: 928 bytes
(928 / 2 = 464) which is the actual width of the clip


I sent this script
DirectShowSource("D:\NewColourTests\yuy2-ff-hfyu.avi", pixel_type="YUY2").info

to:
VirtualDub1.6.19 - Decompressor YCbCr 4:2:2 (YUY2)
VDub MPEG-2 - Decompressor YCbCr 4:2:2 (YUY2)
VDubMod1.6.0.0 - FourCC: (YUY2) YUV 4:2:2, Decompressor: YUV 4:2:2(YUY2)

These two clips look exactly the same:
"If it's native YUY2 everything should be okay. I'm guessing that something in the chain is signalling that it's YV12 or that YV12 is the first-choice output format when it isn't."

So the next thing I tested was whether or not Deen would work with these clips:

clip1
DirectShowSource("D:\NewColourTests\yuy2-ff-hfyu.avi").info
LoadPlugin("C:\AviSynth 2.5\plugins\Deen.dll")
deen("c3d",[<"area", 1, 4, 1>],[<"luma", 0, 50, 9>],[<"chroma", 0, 50, 12>]) # sliders

ColorSpace: YV12
Video pitch: 480 bytes


clip2
DirectShowSource("D:\NewColourTests\yuy2-ff-hfyu.avi", pixel_type="YUY2").info
LoadPlugin("C:\AviSynth 2.5\plugins\Deen.dll")
deen("c3d",[<"area", 1, 4, 1>],[<"luma", 0, 50, 9>],[<"chroma", 0, 50, 12>])

"deen need a YV12 input"

Now, I went through the info re DirectShowSource:
"Note the graph builder may add a format converter to satisfy your request, so make sure the codec in use can actually decode to your chosen format."

Does this means that the original source in my case was YV12 and pixel_type="YUY2" ended up using a "format converter" to convert to YUY2?

Re Deen -
"As far as i know Deen doesn't support interlaced stuff. So, if you cap is interlaced, your video will be messed up."

using the display in AvsP which seems to show interlacing - when I use Deen on this clip - it looks exactly like the clip w/o Deen except that some noise has been eliminated - the interlacing looks fine - and all the captures that I have done using Deen and encoded to MPEG-2, XviD, and H264 look fine as well

any thoughts? TIA

wiseant
24th June 2007, 23:20
Just wanted to add this: Silly me, I forgot to look at the complete ffdshow dialog box - there is a "Generic" setting:
Colorspace: YUY2 or YV12
Predictor: Left, Plane, or Median (I use Median)
and a checkbox for Adaptive huffman tables (which I uncheck)

When YV12 is selected this way DirectShowSource() indicates YV12 and will not use AviSource()

When YUY2 is selected this way DirectShowSource() indicates YV12 BUT AviSource() works and indicates YUY2

(Without realizing it I was using the YV12 setting)

When I set it to YUY2 and then used my Deen script, the bitrate is higher, as mentioned AviSource() works, and I can open the clip in VirtualDub

When I closely compare the quality using 200% or 300% I can notice a subtle improvement in the colour with the YUY2 setting.

So, even though my Deen script uses ConvertToYV12(interlaced=true) the clip seems to end up as YUY2 and Deen, which only works in YV12 does indeed work

Confusing but it works!