# Advice on avisynth filters

1. Im pretty new with avisynth and virtualdub, Just been messing around with it and trying to learn it much better.
I want to try to clean up this movie and I attached a sample below. Im not really sure, what filters that I need
to clean up this film much better. So far I can see De noising, any suggestions on filters or codes to enter I would really appreciate it.

AVCSource("C:\Users\Angel\Desktop\TESTFILE.dga")
TFM()
TDecimate(mode=2)
Crop(4,6,-0,-0)
LanczosResize(1280,720)
http://www.sendspace.com/file/ddh40o
2. Originally Posted by angelroj7
...I attached a sample below.
You sure about that?
3. Originally Posted by manono
Originally Posted by angelroj7
...I attached a sample below.
You sure about that?
Sorry thought I did, I uploaded it now.
4. Interesting clip. The bitrate is quite high, but some block noise, fuzzy and soft, almost out of focus in some places.

Could probably do with a Levels adjustment - looks a little "flat" contrast-wise.

What is the source? Off-air recording ?
5. Originally Posted by davexnet
Interesting clip. The bitrate is quite high, but some block noise, fuzzy and soft, almost out of focus in some places.

Could probably do with a Levels adjustment - looks a little "flat" contrast-wise.

What is the source? Off-air recording ?
From HBO
6. Originally Posted by angelroj7
From HBO
Doesn't HBO broadcast in 1080i? And isn't 720p always 59.94fps? So you downloaded this and it's already been encoded (badly) since being broadcast?

Anyway, you don't need TFM as it's already progressive. You just need to pull out the dupe frames. When using TDecimate(Mode=2) you're supposed to name a final framerate and its decimation routine is different from one-in-five which is what you want. So, 'TDecimate()' is enough.

I agree with davexnet that it looks 'dull'. I'd boost the contrast and probably use YLevels on it to 'brighten' it up. And the colors are a bit off also. The greens and blues need boosting. I like film grain myself and wouldn't denoise it at all.
7. A good general denoiser for AviSynth is McTemporalDenoise(). It has several presets and lots of variables you can fine tune. It's very slow though (because it's motion compensated).

Why is there audio only on the left channel? You need to fix your recording setup.
8. The "right" levels and color for this sample clip depend on which frame you're watching. Color balance changes every few shots, along with hair color and complexions. The beginning shots have lower contrast and saturation than the end. There are crushed darks everywhere, especially in the fight scenes. I'd have a problem watching this with pumped contrast: it was shot in early fall in soft, subdued overcast (if anyone sees hard sun-induced shadows in this sequence, do point them out to the rest of us). I think the producer wanted this effect; you can see the Wratten soft-focus filters at work sometimes. Must be the same producer who's been making films with this cuddly-warm "look" forever. Degrain and oversharpen, and you get clay-face, banding, and a little closer to anime. It does need some mild smoothing of clumpy grain at times (a closeup of a young gal who has what looks like 5 o'clock shadow seems inappropriate, even if HBO does go kinky a lot). The clip lacks some dynamic range from crushing and clipping via previous processing; there's only so much "sparkle" you can get from something that seems to have been around the block a few times and looks over processed. Some compression noise from the telecast, best left as-is rather than chew away at what's left.

When you first look at the sample's YUV histogram, luma is precisely inside the 16-240 corridor, but RGB chroma starts banging at the side doors. So pedaling contrast won't work so well. One would need RGB to work this. Likely better to use something like ColorFinesse ($$). I used ColorMill (free). Or you can try to fix it exclusively in YUV (send us a card when you get what you want). I left the audio as-is. The mkv is NTSC 1280x720p 23.972 fps. I've seen much worse off my cable box with an HD PVR. Cable HD ain't what it was cracked up to be. Code: #[after loading the video any way you want...] LoadVirtualDubPlugin(vdpath+"ColorMill.vdf","ColorMill",1) ColorMatrix(mode="Rec.709->Rec.601") ColorYUV(cont_y=-25,off_y=-4,cont_v=-50,cont_u=-20) SmoothLevels(16, 1.0, 255, 16, 255, chroma=200,limiter=0,tvrange=true,dither=100,protect=6) TDecimate() DeBlock_QED() LSFmod(strength=50) GradFun2DBmod(mask=false) ConvertToRGB32(matrix="Rec601",interlaced=false) ColorMill(26209, 22116, 27490, 25438, 25959, 30337, 27756, 22892, 23386, 25700, 25188, 24942, 25700, 1124, 2053) ConvertToYV12(interlaced=false) ColorMatrix(mode="Rec.601->Rec.709") return last Original-vs-after: Attachment 23358 (click for full size) Attachment 23359 (click for full size) 9. Originally Posted by sanlyn The "right" levels and color for this sample clip depend on which frame you're watching. Color balance changes every few shots, along with hair color and complexions. The beginning shots have lower contrast and saturation than the end. There are crushed darks everywhere, especially in the fight scenes. I'd have a problem watching this with pumped contrast: it was shot in early fall in soft, subdued overcast (if anyone sees hard sun-induced shadows in this sequence, do point them out to the rest of us). I think the producer wanted this effect; you can see the Wratten soft-focus filters at work sometimes. Must be the same producer who's been making films with this cuddly-warm "look" forever. Degrain and oversharpen, and you get clay-face, banding, and a little closer to anime. It does need some mild smoothing of clumpy grain at times (a closeup of a young gal who has what looks like 5 o'clock shadow seems inappropriate, even if HBO does go kinky a lot). The clip lacks some dynamic range from crushing and clipping via previous processing; there's only so much "sparkle" you can get from something that seems to have been around the block a few times and looks over processed. Some compression noise from the telecast and the O.P.'s encoder, best left as-is rather than chew away at what's left. When you first look at the sample's YUV histogram, luma is well inside the 16-240 corridor, but RGB chroma starts banging at the side doors. So pedaling contrast won't work so well. One would need RGB to work this. Likely better to use something like ColorFinesse ($$\$). I used ColorMill (free). Or you can try to fix it exclusively in YUV (send us a card when you get what you want). I left the audio as-is. The mkv is NTSC 1280x720p 23.976 FPS.

I've seen much worse off my cable box with an HD PVR. Cable HD ain't what it was cracked up to be.

Code:
#[after loading the video any way you want...]

TDecimate()
ColorMatrix(mode="Rec.709->Rec.601")
ColorYUV(cont_y=-25,off_y=-4,cont_v=-50,cont_u=-20)
SmoothLevels(16, 1.0, 255, 16, 255, chroma=200,limiter=0,tvrange=true,dither=100,protect=6)

DeBlock_QED()
LSFmod(strength=50)
ConvertToRGB32(matrix="Rec601",interlaced=false)
ColorMill(26209, 22116, 27490, 25438, 25959, 30337, 27756, 22892, 23386, 25700, 25188, 24942, 25700, 1124, 2053)
ConvertToYV12(interlaced=false)
ColorMatrix(mode="Rec.601->Rec.709")
return last
Original-vs-after:

Attachment 23358 (click for full size)

Attachment 23359 (click for full size)
Thanks alot for your help! Really appreciate it
When I use your script I get the following error

SmoothAdjust: Colorspace must be YUV Planar!
10. Your original sample was typical AVCHD/BluRay program stream style, which would be a YV12 colorspace (i.e, "planar"). If what you are working with on your end doesn't start out as YV12, something is amiss with your workflow. A great many Avisynth plugins work only with YV12, a lot of them will work with YV12 or YUY2, a small few will work with YV12, YUY2, and RGB, and some are even YUY2 only. There are good and not-so-good ways of making those conversions when required, but it's better to avoid them when possible (and it ain't always possible).

If your original working source isn't YV12, you have a problem somewhere. But you can make it YV12 as shown in blue, here:

Code:
#[after loading the video any way you want...]

TDecimate()
ColorMatrix(mode="Rec.709->Rec.601")
ColorYUV(cont_y=-25,off_y=-4,cont_v=-50,cont_u=-20)
ConvertToYV12(interlaced=false)
SmoothLevels(16, 1.0, 255, 16, 255, chroma=200,limiter=0,tvrange=true,dither=100,protect=6)

DeBlock_QED()
LSFmod(strength=50)
ConvertToRGB32(matrix="Rec601",interlaced=false)
ColorMill(26209, 22116, 27490, 25438, 25959, 30337, 27756, 22892, 23386, 25700, 25188, 24942, 25700, 1124, 2053)
ConvertToYV12(interlaced=false)
ColorMatrix(mode="Rec.601->Rec.709")
return last
The idea behind this script is to do as little "processing" as you can, because the source is already rather soft. Whether this was the result of your own processing to get the sample, or whether it was simply broadcast that way (which is often the case), it won't take a lot of strong filtering without damage...and I don't think it requires it.

The idea behind the levels and color correction was in two stages. ColorYUV is used to reduce overall contrast a bit and try to rescue a little crushed dark detail, to reduce the obvious red overcast, and to keep the brightest blue details from burning away in later camera shots. The other filters soften grain rather than trying to remove it so you won't have banding and pasty looking faces.

The RGB ColorMill filter attempted two things: slightly lower the "center point" of a histogram a little below RGB 128 by lowering the mid-point and lowering gamma in ColorMill, at the same time raising brightness values in the lower midtones, midtones, and brights. ColorMill's second task was to add blue, control green a little better, and make blacks look black instead of red or green.

How this filter setup might work with your original, un-reprocessed sample is questionable. If you want to see how the ColorMill filter was set up in actual use, I have attached a copy of the VirtualDub .vcf file that saves the filters and settings I used. A .vcf file is produced by saving processing settings in Virtualdub; it is a simple text file that can be opened and examined in Notepad. You load the .vcf and the filters in Virtualdub by using "File..." -> "Load processing settings...", navigate to the vcf location, and select it.

Loading up a vcf works only if you have the named filters in your VirtualDub plugins folder. The two filters I used were ColorMill.vdf (http://fdump.narod.ru/rgb.htm) and ColorTools 1.2 (http://trevlac.us/colorCorrection/colorTools.html). ColorTools can be used as an RGB histogram, vectorscope, or waveform monitor.

In the attached .zip I included the .vcf file and the two plugins. Copy the two .vdf plugins and the .txt file into your VirtualDub plugins folder. Copy the vcf file into a different place, such as the folder containing your project videos. Do not load the vcf and run the script with the RGB settings at the same time: it would result in running the same filters twice.
11. I played for a while with a secondary VirtualDub filter, the built-in "Levels" control (below):

Attachment 23390 (click for full size)

It's similar to levels filters in Adobe Pro apps including Photoshop, Premiere, AFterEffects, etc., and (I think) Vegas Pro. While each version is more or less complex than others, VDub's is functional enough and works similarly to the big guys. You can use Levels to tweak images -- in this case, to add a little more punch. I did so, at the risk of losing just a tad of dark detail and another tad of highlights just on the edge of flaring out. The settings I used are in the image above. I added this filter in VirtualDub while viewing the output of the posted Avisynth script.

The control has two sets of 3 arrows, one set across the middle and another just below it. The two sets work differently. Most of the time you can safely ignore the bottom set. It's the 3 arrows in the middle that do what you want here. The arrow at the left-hand side controls dark density. If you move that left-hand arrow toward the right (i.e, toward the middle), it "pulls down" some of the darks into the left-hand (darker) area. If you move the right-hand arrow toward the left (i.e., toward the middle), it "pulls up" the brights and some of the midtones into the right-hand bright area.

The middle of the 3 arrows controls overall gamma (midtones). Usually it makes its own adjustments when you play with the other two arrows. Mainly, if you move it to the right it darkens midtones; to the left, it brightens midtones.

Unfortunately you can't load this in Avisynth (it's part of VirtualDub's internal coding, not a separate filter). But you can always view the output of an Avisynth script, load the filter to process that output, then save the AVI with the colorspace and compression you want. Many prefer controls like Levels, ColorMill, gradation curves, color wheels, etc., instead of the usual "Brightness" and "Contrast" controls which are less precise and more difficult to manage. AVisynth has several versions of "Levels" functions. Naturally, they are more difficult to use and most are limited to working only on luma, not chroma. The big guys like Adobe Pro have levels controls for brightness and for each color channel.

In Avisynth, the built-in "Levels" function and plugins such as the SmoothLevels function in SmoothAdjust work in a similar way, but you have to set their parameters yourself. Almost all of the Levels functions have the same syntax somehwre in their documentation. Usually it looks like this:

Code:
WhateverLevels(black level input, gamma, white level input, dark level output, white level output
You choose to set, for instance, the black level input and specify how you want that black level interpreted. For example, you can specify that all blacks in the region of RGB 16 would be output as RGB 20 (which will slightly brighten the dark RGB and nearby values). Or you could specify input as 16 and output as 10, which would darken the region of darkest values. The same holds for the white level input/output. If you wanted to darken some of the darks, limit the brightest whites to avoid some highlight burnout, and lower gamma a bit to mellow the midtones, you could use this:

Code:
WhateverLevels(16,  0.9,  255,  12,  235)
The exact coding and other parameters depend on which of several Avisynth levels filters you want to use. In the script posted earlier I used SmoothLevels to maintain the incoming values but to dither (smooth) the effects of the ColorYUV statements that precede it, which can sometimes result in banding effects or gaps between small but visible color or luma changes.
12. Originally Posted by sanlyn
I played for a while with a secondary VirtualDub filter, the built-in "Levels" control (below):

Attachment 23390 (click for full size)

It's similar to levels filters in Adobe Pro apps including Photoshop, Premiere, AFterEffects, etc., and (I think) Vegas Pro. While each version is more or less complex than others, VDub's is functional enough and works similarly to the big guys. You can use Levels to tweak images -- in this case, to add a little more punch. I did so, at the risk of losing just a tad of dark detail and another tad of highlights just on the edge of flaring out. The settings I used are in the image above. I added this filter in VirtualDub while viewing the output of the posted Avisynth script.

The control has two sets of 3 arrows, one set across the middle and another just below it. The two sets work differently. Most of the time you can safely ignore the bottom set. It's the 3 arrows in the middle that do what you want here. The arrow at the left-hand side controls dark density. If you move that left-hand arrow toward the right (i.e, toward the middle), it "pulls down" some of the darks into the left-hand (darker) area. If you move the right-hand arrow toward the left (i.e., toward the middle), it "pulls up" the brights and some of the midtones into the right-hand bright area.

The middle of the 3 arrows controls overall gamma (midtones). Usually it makes its own adjustments when you play with the other two arrows. Mainly, if you move it to the right it darkens midtones; to the left, it brightens midtones.

Unfortunately you can't load this in Avisynth (it's part of VirtualDub's internal coding, not a separate filter). But you can always view the output of an Avisynth script, load the filter to process that output, then save the AVI with the colorspace and compression you want. Many prefer controls like Levels, ColorMill, gradation curves, color wheels, etc., instead of the usual "Brightness" and "Contrast" controls which are less precise and more difficult to manage. AVisynth has several versions of "Levels" functions. Naturally, they are more difficult to use and most are limited to working only on luma, not chroma. The big guys like Adobe Pro have levels controls for brightness and for each color channel.

In Avisynth, the built-in "Levels" function and plugins such as the SmoothLevels function in SmoothAdjust work in a similar way, but you have to set their parameters yourself. Almost all of the Levels functions have the same syntax somehwre in their documentation. Usually it looks like this:

Code:
WhateverLevels(black level input, gamma, white level input, dark level output, white level output
You choose to set, for instance, the black level input and specify how you want that black level interpreted. For example, you can specify that all blacks in the region of RGB 16 would be output as RGB 20 (which will slightly brighten the dark RGB and nearby values). Or you could specify input as 16 and output as 10, which would darken the region of darkest values. The same holds for the white level input/output. If you wanted to darken some of the darks, limit the brightest whites to avoid some highlight burnout, and lower gamma a bit to mellow the midtones, you could use this:

Code:
WhateverLevels(16,  0.9,  255,  12,  235)
The exact coding and other parameters depend on which of several Avisynth levels filters you want to use. In the script posted earlier I used SmoothLevels to maintain the incoming values but to dither (smooth) the effects of the ColorYUV statements that precede it, which can sometimes result in banding effects or gaps between small but visible color or luma changes.
Okay Thanks a lot for your help really appreciate it. Learned alot about the different filters. I used my HD PVR 2 with the xbox 360 and it got a so much clearer picture than through the cable box. Took a look, Ill also add the same clip.

13. Originally Posted by sanlyn
Your "after" is probably far closer to what came out of the camera, but the director worked very hard (OK, at least threw in some random plugins! ) to get to what you see "before".

You know that most Hollywood movies these days look like decent consumer camcorder videos straight out of the camera? They get "the look" in post.

Your colour correction is just undoing a cheap attempt at it.

A lot of the grain might be fake and/or intentional too.

Cheers,
David.
14. I don't believe for one minute that the original is what the director intended. Red is red and crushed is crushed. Make it look the way you want.
15. (For once) I agree with sanlyn. I'm fairly certain this was reencoded by someone, between the time of the HBO broadcast and the time angelroj7 downloaded it. And who knows what some idiot may have done to it?
16. I don't know, I've seen some horrible images coming across network and cable TV. I've recorded quite a few of those myself, in SD and HD. And God forbid some of those cable outfits put up the loot for something that can transmit a better bitrate. Some of it looks as bad as VHS.
17. Originally Posted by angelroj7
Okay Thanks a lot for your help really appreciate it. Learned alot about the different filters. I used my HD PVR 2 with the xbox 360 and it got a so much clearer picture than through the cable box. Took a look, Ill also add the same clip.
Attachment 23404 (click for full size)
Looks better. Nice work.

Statistics