Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
![]() |
#1 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
new script: AGC (Automatic Gain Control)
hey yo, before you point out there's an "autogain" function already...
this script functions in a similar manner to a a VCR's AGC circuit, or in more general terms, a dynamic compressor. the difference here is that it's based on temporalsoften, meaning it has scenechange detection ![]() AGC circuits will amplify a too-dark video and reduce a too-bright signal. (this is how Macrovision works - by putting 3-4x white lines in the overscan area, the AGC circuit is fooled into turning the brightness down to stupidly low levels.) i made this because i have a wide variety of too-dark videos, and the pumping effects of colorYUV(autogain=true) were just too horrible for compressibility and aesthetics, as it works on every frame. this script will average over several frames (originally i had a lot of scripting for this, until i had a brain freeze and realised temporalsoften(4,255,255,255,2) did exactly what i wanted), then up the gain (in RGB). this is rather like having an attack time and a release time... here's the script: Code:
global gl_lum=1 function AGC (clip c, int "mode",float "multiplier", float "gamma", int "radius",int "scenechange", bool "luma") { global gl_radius = default(radius,4) global gl_scenechange = default(scenechange,20) global gl_multiplier = default(multiplier,.96) global gl_c = c global gl_gamma = default(gamma,1) mode= default(mode, 2) luma = default(luma,true) global gl_multiplier = (mode==2)? float(gl_multiplier*2) : \ float(gl_multiplier) global gl_method = (mode==1)? "averageluma()" : \ (mode==2)? "YplaneMax()" : "YplaneMedian()" gl_c=gl_c.frameevaluate("global gl_lum = gl_multiplier*128/ \ (gl_c.deleteframe(0).reduceby2().reduceby2(). \ temporalsoften(gl_radius,255,255,gl_scenechange,2). \ levels(0,gl_gamma,255,0,255,coring=false)." + string(gl_method + ")") \ ,after_frame=false) (luma==true)? gl_c.scriptclip("coloryuv(gain_y=round(gl_lum * 256)-256)") : \ gl_c.scriptclip("converttorgb32().RGBadjust(gl_lum,gl_lum,gl_lum,0).converttoyv12()") } if anybody can help make this more useful they are very much encouraged to do so ![]() usage: mode - integer defining whether averageluma() is used (1), YplaneMax() (2), or YplaneMedian (3). i wouldn't bother with median, as it is hell on dark videos. probably the most useful one is mode 2. multiplier - global scale of the output... you may need to lower this for particularly colourful clips, where luma is unexpectedly low and chroma high. radius - this is attack/release time in frames (the radius param in temporalsoften). default is 4, to prevent small pumping in mode=2, try increase it (but if you get error text decrease it again) scenechange - best left at default, or if you want to have fading after scenechanges (too make it look like an old tape), raise it to 255. gamma - this will move the average level around, if need be. useful for videos with dark backround and light foreground - increase the gamma value and the average goes up, meaning less gain is applied. more predictable then tweaking multiplier... agc(gamma=2) will make a video come out lower, agc(gamma=0.75) will make it brighter by a lot. luma - boolean. default true. this will only add gain to luma, rather than converting to RGB and doing each channel (which is a truer kind of gain, but often meaningless for TV caps, and slower to boot) have fun people! [edit] updated the script so multiplier is doubled for mode = 2 [edit edit] another slight update. it's now way more stable, and a little faster in certain situations. you can now run filters after it, it seems. [edit 3] added some line breaks for Scharfis_Brain, careful not to break the script in the process. ![]() [edit 4] added gamma (well added this before but forgot to document it) and luma-only mode.
__________________
sucking the life out of your videos since 2004 Last edited by Mug Funky; 28th March 2004 at 18:37. |
![]() |
![]() |
![]() |
#5 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
update
updated above code...
added "gamma", which i just found is quite an important parameter. it will wieght the average and mitigate clipping on high ocntrast, dark clips (space action movies ![]() default is 1, if you get excessive clipping and oversaturated output, set it to 1.5. this wont apply gamma to the output, but will supply the averaging function with a gamma corrected clip (bringing up the avrage luma)
__________________
sucking the life out of your videos since 2004 |
![]() |
![]() |
![]() |
#7 | Link |
Registered User
Join Date: Feb 2004
Posts: 743
|
mug funky
Hey arn't those auto everything just great on camcorder.....uh, many thanks for your work on this filter. Have you ever thought of a script to reduce the water fall effect that most VCRs suffer. It's caused by the rotating head assembly. richard photorecall.net |
![]() |
![]() |
![]() |
#8 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
waterfall effect? i've not heard of this one.
is it the horizontal warpage that occurs on pretty much all rental tapes i get (my VCR leaves a little to be desired)? avisynth currently doesn't lend itself easily to that kind of thing, but if you're really patient you could use a plugin somebody made that shifts single lines. if you're really patient you could derive an equation for the line warping, and write a script that outputs these values into a bunch of eval( "blah" ) lines... i did that with YV12convolution and a sine squared curve so i could get lowpass filtering at any radius ![]() [edit] added some line breaks. still need to scroll a tiny bit, but all-in-all it helps.
__________________
sucking the life out of your videos since 2004 Last edited by Mug Funky; 24th March 2004 at 15:52. |
![]() |
![]() |
![]() |
#9 | Link |
Registered User
Join Date: Feb 2004
Posts: 743
|
Mug Funkey........waterfall effect, is lets say you have a straight thin vertical line. Because of tape stretch and with the speed of the rotating head varing, each scan line is offset a tiny amount left or right. No longer is the line smooth, but is a little jagged.
On my boardcast decks, you don't see this if the tape was made on this deck, but you can see it quite often with home units, or it shows real bad on a copy of the orignal tape. Its all about timing, and there are several reference points where a Avisynth script could be written. Your a great,programer, I not, but i am a NTSC enginee plus I have even design PAL test equipment when SKY satellite service began. Maybe we could work together on the filter. It would be some what like a TBC with moving each line a tiny bit,expanding the scan line duration or contracting it. richard photorecall.net |
![]() |
![]() |
![]() |
#10 | Link | |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Quote:
This is one of the holy grails of video processing (100% motion detection being the most holy ![]() ![]() regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
|
![]() |
![]() |
![]() |
#11 | Link |
Registered User
Join Date: Feb 2004
Posts: 743
|
Timing.....The start of each scan line could be referenced to the first horizontal,blanking,sync, or burst pulse of the field. We know that the time for each NTSC scan line is, 63us.
The first horzontal sync pulse's time position, and the pulse itself could be repeted for all the lines in the whole field. The lenght of the scan line in the uncorrected video then could be compared to the time between the reference pulse time position to the next pulse position for the following scan line. This works because this is what Zenith used in their Savvy cable decorder. richard photorecall.net |
![]() |
![]() |
![]() |
#12 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
only problem with that is that sync pulses are never captured on any software i've heard of.
i know DV captures more lines than it shows (at least enough to allow macrovision to work when trying to record DV to VHS, although this might be a hack). but getting this vital information into avisynth is a big problem. i've thought about doing this for sure, but until we can get a definite reference point (ie. a sync pulse or at least something on the side of the picture that can be defined as an edge) there's no foolproof way to do this. perhaps there's a capture card out there that will do what we want... (by the way, i'm certainly not a great programmer ![]()
__________________
sucking the life out of your videos since 2004 |
![]() |
![]() |
![]() |
#14 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
update
updated above script (well, i will when i'm done typing this bump)
changes (or rather "change"): - added luma only mode... accessed by "luma=true", true by default. it's now oodles faster as there's no colourspace conversion going on, and seeing as too-dark captures often have too-saturated colours, this is a good compromise in most cases.
__________________
sucking the life out of your videos since 2004 |
![]() |
![]() |
![]() |
#16 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
chainmax: nothing too special.
it just takes an average (or peak) level of the current ~8 frames and applies gain based on that. it's analogous to coloryuv(autogain=true) except that it doesn't work per frame, but rather over an average of several frames (with scenechange detection of course) i've called it "AGC" after the similar function of VCRs (automatic gain control)
__________________
sucking the life out of your videos since 2004 |
![]() |
![]() |
![]() |
#17 | Link |
Almost Silent Member
Join Date: Jun 2002
Location: Purgatory
Posts: 273
|
A bit ago a freind of mine asked me to help him backup some of his more treasured videos that were only available on VHS to DVD-R. While the content of the tapes were great, you're probably all too familiar with the problems inherent to dealing with older VHS tapes.
I'm not sure whether all VCR's are equipped with AGC circuits or not, but apparently the VCR he used was either woefully equipped, completely missing an AGC circuit, or the tape was on it's last play. I don't recall ever seeing so much variance in levels from one frame to another without the cause being that beautiful Macrovision effect. Well, to make an already long story short(er) I threw this updated function into the mix after a few disappointing ventures into other methods. I have two words for you: very nice! Luma=true is a really nice addition. It still achieved the same effect as the previous script (to our eyes) while helping out greatly with the speed factor. Considering he's ending his filterchain with IIP and doesn't have room for any more intermediate AVI's that should be a real bonus. /me returns to burning, shooting, and smashing VHS tapes
__________________
Rethinking the "Why?" chromosome. |
![]() |
![]() |
![]() |
#18 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
glad to help:
![]() i hope it doesn't throw any errors halfway through an encode though... it _should_ be okay if it gets past the first frame without going b0rk. any script wizards are welcome to make it more stable (it's possibly my system more than anything that is giving me crashes ![]()
__________________
sucking the life out of your videos since 2004 |
![]() |
![]() |
![]() |
#19 | Link |
Almost Silent Member
Join Date: Jun 2002
Location: Purgatory
Posts: 273
|
Well, it was fine throughout the 4-5 minute preview we reviewed, and didn't choke during our seeking for the horrid scenes, so... *crosses fingers, knocks on wood, finds an irishman and pays him to do a lucky jig*
First test encode is nearly completed, and no error yet. ![]()
__________________
Rethinking the "Why?" chromosome. |
![]() |
![]() |
![]() |
#20 | Link |
interlace this!
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
|
cool. looks like the crashes must be at my end... i only even get them when advancing 1 frame straight after loading, so looks like even here, if it works it continues to work, and if it doesn't you know straight away (bit of a timesaver there).
hmmm... i'm mostly irish. should i do a little jig?
__________________
sucking the life out of your videos since 2004 |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|