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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th November 2012, 23:20   #1  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Display test pattern (Gscript)

Quote:

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\GScript.dll")

A = BlankClip(500, 483, 320, color=$00008B)
A

Function V_lines(clip "A", int "large", int "start")

{

W = width(A)
# large = 1
# start = 13
end = W - start

left = Crop(A, 0, 0, -end, 0)
right = Crop(A, start, 0, 0, 0)
Wr = width(right)

hband = Crop(right, 0, 0, -(Wr - large), 0)
right = Crop(right, large, 0, 0, 0)

hband = hband.BlankClip(color=$FFFF00)

A = StackHorizontal(left , hband, right)

Return A

}

GScript("""

for (i=1, Width(A), 10){

V_lines(last, 1, i)

}

""")


Thanks, L
lisztfr9 is offline   Reply With Quote
Old 18th November 2012, 18:51   #2  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
Could we see picture of script result ?
__________________
Warm and fuzzy (white and fluffy)
Jenyok is offline   Reply With Quote
Old 18th November 2012, 19:10   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Same script but a little less ugly: (EDIT: Removed quotes from V_lines args as were NOT optional args)
Code:
A = BlankClip(500, 483, 320, color=$00008B)
A

Function V_lines(clip A, int large, int start) {
	W = width(A)
	# large = 1
	# start = 13
	end = W - start
	left = Crop(A, 0, 0, -end, 0)
	right = Crop(A, start, 0, 0, 0)
	Wr = width(right)
	hband = Crop(right, 0, 0, -(Wr - large), 0)
	right = Crop(right, large, 0, 0, 0)
	hband = hband.BlankClip(color=$FFFF00)
	A = StackHorizontal(left , hband, right)
	Return A
}

GScript("""
	for (i=1, Width(A), 10) {
		V_lines(last, 1, i)
	}
""")
Result:
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 16th July 2017 at 04:09.
StainlessS is offline   Reply With Quote
Old 18th November 2012, 20:45   #4  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
@StainlessS

Nice StainlessS ! i have to beautify my code. Ok, for the quotes

This is just an exercise in order to make a poor man's descratch... It's the line scanning stage. I should be able to remove 1 dark line in a frame thanks to this, keeping the last 3 values of luma (for i), checking thresholds (1 and 3 mostly equal, 2 spike), and later calling V_lines for (i - 1) to correct luma. It's a kind of normalisation.

I guess that flicker correction (with an horizontal scan) should involve working on more than 1 frame, but seems possible.... Since flicker changes every single frame, real luma variations would span over at least 2 frames and would be skipped for correction.
lisztfr9 is offline   Reply With Quote
Old 18th November 2012, 21:13   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Dont know if helpful but RT_stats has functions to get eg AverageLuma of a single line (horiz/vert), usuable via GScript.
Also eg YDifference (RT_YDifference) to get luma difference between lines (horiz/vert via x,y,w,h).
Lines can be from different frames or the same frame with different x,y coords.
EDIT: Or even different frames with different x,y coords.
EDIT: Or even different clips, different frames with different x,y coords.

EDIT: Some of the funcs available in RT_Stats:
Code:
RT_AverageLuma(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,int "Matrix"=0)
Returns FLOAT value average luma (0.0 -> 255.0) in frame(n+delta) for area x,y,w,h.

RT_YDifference(clip,int "n"=current_frame,int "delta"=1,int "x"=0,int "y"=0,int "w"=0,int "h"=0,int "x2"=x,int "y2"=y,
  bool "interlaced"=false,int "Matrix"=0)
Returns FLOAT value luma difference (0.0 -> 255.0) between frame n area x,y,w,h, and frame (n+delta) area x2,y2,w,h.
Note, by default it will be equivalent to YDifferenceToNext as delta defaults to 1 and x,y,w,h defaults full frame.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively. 
 
RT_LumaDifference(clip,clip2,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,
    int "n2"=current_frame,int "delta2"=0,int "x2"=x,int "y2"=y,bool "interlaced"=false,int "Matrix"=0)
Returns FLOAT value luma difference (0.0 -> 255.0) between clip frame (n+delta) area x,y,w,h, and clip2 frame (n2+delta2) area x2,y2,w,h.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th November 2012 at 21:54.
StainlessS is offline   Reply With Quote
Old 18th November 2012, 21:35   #6  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Quote:
Originally Posted by StainlessS View Post
Dont know if helpful but RT_stats has functions to get eg AverageLuma of a single line (horiz/vert), usuable via GScript.
Also eg YDifference (RT_YDifference) to get luma difference between lines (horiz/vert via x,y,w,h).
Lines can be from different frames or the same frame with different x,y coords.
EDIT: Or even different frames with different x,y coords.
Ok i will read further on that... gosh.

Last edited by lisztfr9; 18th November 2012 at 23:12.
lisztfr9 is offline   Reply With Quote
Old 22nd November 2012, 17:33   #7  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Hi StainlessS,

I tried the If statement but can't get this to work :

Quote:
if ( condition ) {
statements
}
else {
statements
}
Testing :

Quote:
GScript("""
for (i=1, Width(A), 10){
V_lines(last, 1, i)
If (i =< 100 = true){
V_lines(last, 1, i + 1)
}
Else {
V_lines(last, 1, i + 3)
}
}
""")
TIA, L

Edit : I see there is something wrong with the brackets...

Also wrong ...

Quote:
GScript("""
for (i=1, Width(A), 10){
V_lines(last, 1, i)
(i =< 100) ? V_lines(last, 1, i + 1) : V_lines(last, 1, i + 3)
}
""")

Last edited by lisztfr9; 22nd November 2012 at 18:03.
lisztfr9 is offline   Reply With Quote
Old 22nd November 2012, 18:12   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Try this (untested)

Code:
GScript("""
    for (i=1, Width(A), 10) {
        V_lines(last, 1, i)
        If (i <= 100) {
            V_lines(last, 1, i + 1)
        } Else {
            V_lines(last, 1, i + 3)
        }
    }
""")
EDIT: "<=" is LessOrEqual, presume thats what you want, or would it be just plain "<" LessThan, that you want.
http://avisynth.org/mediawiki/Operators

Try indenting your code, it does not just "look nice", you can see the logic structure just from the shape
without even reading the code.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 22nd November 2012 at 18:34.
StainlessS is offline   Reply With Quote
Old 22nd November 2012, 18:32   #9  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Yes it's that, sorry ! Same as in Qbasic
lisztfr9 is offline   Reply With Quote
Old 22nd November 2012, 19:00   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
No need to be sorry, wer'e all just beginners.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 24th November 2012, 14:44   #11  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
lisztfr9,
I am not sure if you are trying GScript or if you are making a test pattern.
For a test pattern, I would like to give you a hint.
AviSynth video processing is made as a chain of elementary processing steps. Typically, every step takes the frame in memory, allocates additional memory for its output and calculates the output pixels from the input pixels (if we omit the time line for a moment).
That means: because you call a function that takes and delivers a clip in a loop, you (maybe inadvertently) build a long chain of processors and thus something that allocates much memory.

This script (verified) also produces vertical thin lines at a distance of 10:
Code:
BlankClip(pixel_type="YV12").mt_lutspa(mode="absolute", expr="x 10 % 0 == 255 0 ?")

Last edited by martin53; 24th November 2012 at 15:43. Reason: typos
martin53 is offline   Reply With Quote
Old 24th November 2012, 14:59   #12  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
@martin53

Thanks martin, i'm happy to learn every bit here...

Some other thing that worries me is the link between Levels and mt_lutf as :

mt_lutf(B, hband, mode = "avg", expr = "y 6 +")

I'm sure the same thing can be done with Levels, maybe just setting average_luma + 6 as last parameter. I will check that later. Or reducing gamma.... but gamma act as a multiplicand , so imho it increase dynamic range...

Edit : Ok i should definitively use Tweak for that.

Last edited by lisztfr9; 24th November 2012 at 18:52.
lisztfr9 is offline   Reply With Quote
Old 24th November 2012, 20:04   #13  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
Yep - or ColorYUV(off_y=6).
martin53 is offline   Reply With Quote
Old 24th November 2012, 23:57   #14  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Quote:
BlankClip(pixel_type="YV12").mt_lutspa(mode="absolute", expr="x 10 % 0 == 255 0 ?")
It's working as promised, but i had to update masktools V2, from masktools-v2.0a37 to the last one, masktools-v2.0a48.

The "?" execute code conditionally, the 2 last integers seems to set colors, and if i cancel the "==" i get it in reverse colors. gosh...

http://unreal666.hdd1.ru/docs/avisyn....htm#mt_lutspa

Last edited by lisztfr9; 25th November 2012 at 00:15.
lisztfr9 is offline   Reply With Quote
Old 25th November 2012, 00:20   #15  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by lisztfr9 View Post
It's working as promised, but i had to update masktools V2, from masktools-v2.0a37 to the last one, masktools-v2.0a48.
Because the 'mode' parameter was not added to mt_lutspa until v2.0a45.

Quote:
The "?" execute code conditionally, the 2 last integers seems to set colors, and if i cancel the "==" i get it in reverse colors. gosh...
Also when i set "!=" instead. Why ? Also i don't understand why it draws lines !
The expression means 'if x%10 == 0 then 255 else 0'. ('%' means mod)
So at points in the image where x=0, 10, 20, ..., the pixel is set to 255 (white), otherwise it is set to 0 (black). This results in a series of vertical lines.

Changing '==' to '!=' reverses the condition, thus inverting the colors at each point.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 25th November 2012, 08:52   #16  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
@Gavino

Yes Gavino, i'm not used to RPN, in particular having the "==" sign as postfix. It's rather a boolean operator as a equal sign. I should ever translate to infix
lisztfr9 is offline   Reply With Quote
Old 25th November 2012, 10:38   #17  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Don't forget that masktools also has a mt_polish() function which converts infix notation to RPN, so you don't need to use RPN if you don't want to. For example, the previous expression could be written as:
expr=mt_polish("x % 10 == 0 ? 255 : 0")

There is also a function mt_infix() which does the reverse, and can be used to check the meaning of RPN expressions you find in other people's scripts (or the correctness of your own).

Subtitle(mt_infix("x 10 % 0 == 255 0 ?"))
will show
x % 10 == 0 ? 255 : 0
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 25th November 2012, 11:02   #18  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Very useful ! but

http://manao4.free.fr/mt_masktools.html

Don't say anything about mt_infix, or i'm blind

Ok it's shown as add (Alpha 5)
lisztfr9 is offline   Reply With Quote
Old 25th November 2012, 11:39   #19  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by lisztfr9 View Post
Very useful ! but

http://manao4.free.fr/mt_masktools.html

Don't say anything about mt_infix, or i'm blind

Ok it's shown as add (Alpha 5)
The on-line web page is hopelessly out of date, and covers only up to v2.0a27.
mt_infix was introduced in v2.0a37 (it was actually mt_polish that came in at alpha 5).

You need to look at the documentation in the masktools download zip file - documentation\mt_masktools.html.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.