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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 31st January 2021, 16:55   #41  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
I see what you did, and it works, but will cause problems with my external macro involvement.

However, I can accomplish the same thing (just thought of it) by adding FadeOut(1) to the script, above the function line. So, we have two solutions and are a little closer to perfection.
Danette is offline   Reply With Quote
Old 31st January 2021, 17:04   #42  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
HH,
I thought I was going nuts, I could not see any diff between code block #1 and code block #3,
so I copied to 2 files, 1.txt and 2.txt and did a KDiff, and shows "Binary Equal".
Were they supposed to be identical ?

EDIT:
OK, I see you just edited out this line
Code:
Out = FrameEvaluate(Vid2, """

  IsComb = IsCombedTIVTC(Vid1)
  IsRed = (AverageChromaV() > 128)
  IsEnd = (FrameCount() == (current_frame + 1))
  Count = IsComb ? Count + 1 : Count

  WriteThis = (IsComb || IsRed ? string(current_frame) + \
  (IsComb ? string(Count, "  -  Combing %.0f") : "  -  No Combing")  + \
  (IsRed ? string(AverageChromaV()-128, "  -  %.2f") : "") : "") + \
  ((IsComb || IsRed) && IsEnd ? chr(10) : "") + \
  (IsEnd ? string(FrameCount(), "%.0f  -  Frame Count") : "")

""")

Out = !Write ? Vid2 : \
!All ? WriteFileIf(Out, File, "IsComb || IsRed || IsEnd", "WriteThis", Append=Append) : \
WriteFile(Out, File, "current_frame", "WriteThis", Append=Append)
in code block #1.
__________________
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; 31st January 2021 at 17:08.
StainlessS is offline   Reply With Quote
Old 31st January 2021, 18:48   #43  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Yeah... bad copy and paste. Sorry.

Edit: and I just edited it again as reading your post made me realise I forgot to remove "current_frame" from the last line. Sigh.....

Edit2: %*^$, that's wrong too. Edit number 3 will happen after I've checked it.

Edit 3: Forget the old version. Latest attempt is found in post #46.

Last edited by hello_hello; 31st January 2021 at 20:46.
hello_hello is offline   Reply With Quote
Old 31st January 2021, 18:50   #44  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Quote:
Originally Posted by Danette View Post
I see what you did, and it works, but will cause problems with my external macro involvement.
In what way? I thought it was exactly what you were after.
If the function was to prevent the combing or red information being written for the last frame, and wrote the frame count instead, would that do it?

Last edited by hello_hello; 31st January 2021 at 18:56.
hello_hello is offline   Reply With Quote
Old 31st January 2021, 20:22   #45  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
It's outside the avs and has to do with reading a text file, but I can easily work around it. Simply more convenient if the last line in the text file is not a line also representing a frame number.
Danette is offline   Reply With Quote
Old 31st January 2021, 20:42   #46  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
StainlessS,
Speaking of going nuts... for the function below, which I fixed pointlessly because All=true isn't needed... but I had to make it work anyway... do you know if this is expected behaviour?

If I make the "All" argument global like this:
global All = default(All, false)
it doesn't become global unless I use the argument in the function ie:
FindCombingRed(All=true)
If I don't, the "All" variable isn't seen by FrameEvaluate.
FindCombingRed()

Hence including the new variable "Everything".
global Everything = All
That's seen by FrameEvaluate either way.

I don't understand why "All" doesn't become global unless it's specified, or appears not to. Unless that's the way argument globals work and I've never had a reason to notice.

Anyway.... for the sake of completeness, this version works correctly when All=true.

Code:
# ===============================================================================

function FindCombingRed(clip Vid, bool "Append", string "FileName", bool "All", bool "Write")  {

Append = default(Append, false)
FileName = default(FileName, "")
All = default(All, false)
Write = default(Write, true)

N = ScriptFile()
LN = LCase(N)
NLen = StrLen(N)
ELen = FindStr(LN, ".avs") - 1
File_Name = LeftStr(N, NLen-(NLen-ELen))
FName = (FileName == "") ? File_Name : FileName
File = FName + "_Combing.txt"
global Count = 0
Vid = Vid.GreyScale()
global Vid1 = Vid.TFM(pp=1).TDecimate()
CombTest = BlankClip(Vid, Color=color_red)
Vid2 = Vid.TFM(Clip2=CombTest).TDecimate()
global Everything = All

Out = FrameEvaluate(Vid2, """

  IsComb = IsCombedTIVTC(Vid1)
  IsRed = (AverageChromaV() > 128)
  IsEnd = (FrameCount() == (current_frame + 1))
  Count = IsComb ? Count + 1 : Count

  WriteThis = \
  (!IsComb && !IsRed && !Everything ? "" : string(current_frame)) + \
  (!IsComb && !IsRed ? "" : \
  IsComb && IsRed ? (string(Count, "  -  Combing %.0f") + string(AverageChromaV()-128, "  -  %.2f")) : \
  IsComb ? string(Count, "  -  Combing %.0f") : \
  ("  -  No Combing" + string(AverageChromaV()-128, "  -  %.2f"))) + \
  (!IsEnd ? "" : \
  (!IsComb && !IsRed && !Everything ? "" : chr(10)) + string(FrameCount(), "%.0f  -  Frame Count"))

""")

Out = !Write ? Vid2 : \
!All ? WriteFileIf(Out, File, "IsComb || IsRed || IsEnd", "WriteThis", Append=Append) : \
WriteFile(Out, File, "WriteThis", Append=Append)

return Out  }

# ===============================================================================

Last edited by hello_hello; 31st January 2021 at 21:44.
hello_hello is offline   Reply With Quote
Old 31st January 2021, 20:44   #47  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Quote:
Originally Posted by Danette View Post
It's outside the avs and has to do with reading a text file, but I can easily work around it. Simply more convenient if the last line in the text file is not a line also representing a frame number.
Do you want an empty last line, but other than that is it okay? I'm just trying to make sure I follow, because I'm still not sure I do.
Maybe post an example of the last few lines the way you want it.
hello_hello is offline   Reply With Quote
Old 31st January 2021, 21:08   #48  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
Last line that is not identified as "combing" (therefore not a line showing a frame). It would be just the frame count, as already appears when the last frame is not combed.
Danette is offline   Reply With Quote
Old 31st January 2021, 21:16   #49  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Maybe I'm being thick, but isn't that what's happening? If you don't want it labelled, use the function in post #46 and remove
- Frame Count
from the last FrameEvaluate line.

It appears to be writing a blank line at the very end, after the frame count. If that's the issue, I don't know how to prevent it, so you might need to remove it manually.

Code:
...string(FrameCount(), "%.0f"))
From your "Last Line Combed" sample:

Code:
60  -  Combing 24  -  48.78
70  -  Combing 25  -  28.37
72  -  Combing 26  -  22.18
73  -  Combing 27  -  112.00
74  -  Combing 28  -  30.47
76  -  Combing 29  -  112.00
77  -  Combing 30  -  26.82
79  -  Combing 31  -  28.58
80  -  Combing 32  -  112.00
81
The old "Red Test" sample:

Code:
80  -  Combing 33  -  112.00
81  -  No Combing  -  34.56
92  -  Combing 34  -  14.91
93  -  No Combing  -  16.27
161  -  Combing 35
162  -  Combing 36  -  42.75
163  -  Combing 37  -  112.00
164  -  Combing 38  -  35.61
208
Code:
...string(FrameCount(), "%.0f  -  Frame Count"))
"Last Line Combed" sample:

Code:
60  -  Combing 24  -  48.78
70  -  Combing 25  -  28.37
72  -  Combing 26  -  22.18
73  -  Combing 27  -  112.00
74  -  Combing 28  -  30.47
76  -  Combing 29  -  112.00
77  -  Combing 30  -  26.82
79  -  Combing 31  -  28.58
80  -  Combing 32  -  112.00
81  -  Frame Count
"Red Test" sample:

Code:
80  -  Combing 33  -  112.00
81  -  No Combing  -  34.56
92  -  Combing 34  -  14.91
93  -  No Combing  -  16.27
161  -  Combing 35
162  -  Combing 36  -  42.75
163  -  Combing 37  -  112.00
164  -  Combing 38  -  35.61
208  -  Frame Count
Otherwise I'll need an example of what you mean.

Last edited by hello_hello; 31st January 2021 at 21:40.
hello_hello is offline   Reply With Quote
Old 31st January 2021, 21:54   #50  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
Oooops ...sorry, I haven't looked at your last code update. I'm back and forth today. give me some time to check it out.
Danette is offline   Reply With Quote
Old 31st January 2021, 21:55   #51  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
The previous version should have been doing the same thing. This one just makes All=true behave correctly.
hello_hello is offline   Reply With Quote
Old 31st January 2021, 23:19   #52  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
This is what I get when running the code in post #46:
Quote:
72 - Combing 26 - 22.18
73 - Combing 27 - 112.00
74 - Combing 28 - 30.47
76 - Combing 29 - 112.00
77 - Combing 30 - 26.82
79 - Combing 31 - 28.58
80 - Combing 32 - 112.0081 - Frame Count
Danette is offline   Reply With Quote
Old 1st February 2021, 00:10   #53  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by hello_hello View Post
... do you know if this is expected behaviour?

If I make the "All" argument global like this:
global All = default(All, false)
it doesn't become global unless I use the argument in the function ie:
FindCombingRed(All=true)
If I don't, the "All" variable isn't seen by FrameEvaluate.
FindCombingRed()
Not sure why you were having problems there, this seems to work just fine.

Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()
#Return Test(undefined)
#Return Test(All=undefined)
#Return Test(All=false)
#Return Test(false)
#Return Test(True)
#Return Test(All=True)

Function Test(clip c, bool "All") {
    c
    Global All = Default(All,false)
    ScriptClip("Subtitle(String(ALL))")  # COMMENT THIS OUT, NOTHING AT ALL HAPPENS
    Subtitle(String(ALL),Align=2)        # Should print ALL on Bottom of frame. NOTHING HAPPENS. # EDIT ADDED LINE
}
EDIT: Added subtitle at align=2, nothing happens there, not printed.
Where it prints ALL on bottom of frame, and input to function is undefined, then prints undefined ie null string "".

Why it Happens:-
Local variable hides a Global variable of same name, so although you have defined ALL as Global, because the local ALL variable exists,
but is undefined, so prints nothing on bottom of frame.
However inside scriptclip the global All is NOT hidden by local All and so prints on top of frame OK.
So is NOT a BUG, is as expected, but a bit tricky to figure out why.
__________________
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; 1st February 2021 at 00:38.
StainlessS is offline   Reply With Quote
Old 1st February 2021, 00:31   #54  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Stainless, I saw your edited post after submitting this one, but anyhow....
Edit: Still trying to wrap my head around it, but in your example, where is a local All being declared as a variable? I can only see the global one. Surely converting it to a string shouldn't effect it's actual value, or global status? string(ALL)


StainlessS, that certainly produces the expected result, but this.... not so much.

Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()

Function Test(clip c, bool "All") {
    Global All = Default(All,false)
    Return All ? c.Subtitle("All") : c.Subtitle("Not All")
}
Neither does this:

Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()

Function Test(clip c, bool "All") {
    Global All = Default(All,false)
    Global All = All
    Return All ? c.Subtitle("All") : c.Subtitle("Not All")
}
This does work:

Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()

Function Test(clip c, bool "All") {
    All = Default(All,false)
    Global All = All
    Return All ? c.Subtitle("All") : c.Subtitle("Not All")
}
Odd....

PS Version() says Avisynth+ 3.5 r3106

Last edited by hello_hello; 1st February 2021 at 01:21.
hello_hello is offline   Reply With Quote
Old 1st February 2021, 00:37   #55  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
I figured out the reason, as in edit, hope it makes sense.
[I made a number of edits.]
EDIT:
When getting value of a variable, it searches the list of Local variables first, only if it does not find it there
does it then search the Global variables list.
Inside your function the optional arg "All" does exist, its just not defined unless provided by the caller with a value.
__________________
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; 1st February 2021 at 00:49.
StainlessS is offline   Reply With Quote
Old 1st February 2021, 00:59   #56  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Quote:
Originally Posted by StainlessS View Post
defined unless provided by the caller with a value.
So are you saying

All = default(All, false)

All doesn't have any value until something wants to know what "All" means later in the script? That seems odd to me. Because this works, not being an argument.

Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()

Function Test(clip c, bool "All") {
    Global MyCat = false
    Return MyCat ? c.Subtitle("All") : c.Subtitle("Not All")
}
If that's the way it works then it's the way it works, and now I know I know, but it's unexpected, at least to me.
hello_hello is offline   Reply With Quote
Old 1st February 2021, 01:11   #57  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()

Function Test(clip c, bool "All") {
    Global All = Default(All,false)
    Global MyCat = true
    Return MyCat ? c.Subtitle(string(All)) : c.Subtitle("Not All")
}
"All" is obviously considered undefined at the return line above because there's no error.

Yet here at the return line it's false. That seems inconsistent to me.

Code:
Colorbars.ConvertToYV12.KillAudio

Return Test()

Function Test(clip c) {
    Global All = false
    Global MyCat = true
    Return MyCat ? c.Subtitle(string(All)) : c.Subtitle("Not All")
}
Okay, maybe now I get it.
Because "All" is a function argument it's instantly a local variable inside the function, even though it's undefined, so as a global variable it's ignored. I dunno though... should an argument be a local variable before it's defined? Maybe it has to be, I think my brain is slowly coming to terms with how it works.

Last edited by hello_hello; 1st February 2021 at 01:20.
hello_hello is offline   Reply With Quote
Old 1st February 2021, 01:31   #58  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,829
Quote:
Originally Posted by Danette View Post
This is what I get when running the code in post #46:
I don't understand. I was using the function from post #46 to show you the examples. Are you sure you don't have two versions of the same function auto-loading? I've driven myself a little mad doing that before.
My favourite trick is to have the function open in a text editor (one that doesn't lock files), change the file name in Explorer, click "save" in the text editor, and then there's two versions. I did that yesterday or the day before while playing with an earlier version of this function and lost about 30 minutes banging my head on the desk before the penny dropped.

I moved my copy out of the auto-loading plugins folder, made sure it resulted in a "no function named" error message, put it back and ran the script again.

Code:
73  -  Combing 27  -  112.00
74  -  Combing 28  -  30.47
76  -  Combing 29  -  112.00
77  -  Combing 30  -  26.82
79  -  Combing 31  -  28.58
80  -  Combing 32  -  112.00
81  -  Frame Count

Last edited by hello_hello; 1st February 2021 at 01:42.
hello_hello is offline   Reply With Quote
Old 1st February 2021, 01:34   #59  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
How bout this, any good

Code:
Colorbars.ConvertToYV12.KillAudio.Trim(0,-1) # 1 frame

Return  Test()
#Return Test("Some Test String")

Function Test(clip c, String "All") {
    c
    Out("1:- Test local All arg",All)                   # Local All, may be undefined
    Global All = "G_" + Default(All,"Undefined String") # This is 'Invisible' due to presence of function arg All.
    Out("2:- Test Global All",All)                      # This will output Local All, local All hides Global All
    SSS="""
        Out("3:- Scriptclip Subtitle Global All",All)   # Local arg All is not available in ScriptClip and so cannot hide the global All
        Subtitle(String(ALL))
    """
    ScriptClip(SSS)
    Subtitle(String(ALL),Align=2)                       # Should print ALL on Bottom of frame.
    Out("4:- Test local Subtitle All",All)              # Local All, may be undefined
    Return Last
}

Function Out(String s, val "v") {
    RT_debugF("%s = '%s'",s,String(v),name="Out: ")    # if v is undefined, then String(v) will produce "".
}

Return Test()
Code:
00001012    0.28597242  [1224] Out: 1:- Test local All arg = ''
00001013    0.28608471  [1224] Out: 2:- Test Global All = ''
00001014    0.28634524  [1224] Out: 4:- Test local Subtitle All = ''
00001015    0.28672349  [1224] Out: 3:- Scriptclip Subtitle Global All = 'G_Undefined String'
Return Test("Some Test String")
Code:
00001115    0.28165036  [3932] Out: 1:- Test local All arg = 'Some Test String'
00001116    0.28175980  [3932] Out: 2:- Test Global All = 'Some Test String'
00001117    0.28203043  [3932] Out: 4:- Test local Subtitle All = 'Some Test String'
00001118    0.28244600  [3932] Out: 3:- Scriptclip Subtitle Global All = 'G_Some Test String'
EDIT:
Code:
Colorbars.Subtitle(String(All))
Above, As a 1 line script would produce an error as All variable does NOT exist.

All=undefined at main script level, creates a named but undefined variable. [it has neither a variable type (int/bool etc) nor value, but it does exist]
Code:
All=undefined
Colorbars.Subtitle(String(All))     # String(undefined) : produces ''
Above, Would not produce an error as All variable exists, but is not defined, it has no value or type.

EDIT: Below copied here from previous posts.

Quote:
Why it Happens:-
Local variable hides a Global variable of same name, so although you have defined ALL as Global, because the local ALL variable exists,
but is undefined, so prints nothing on bottom of frame.
However inside scriptclip the global All is NOT hidden by local All and so prints on top of frame OK.
So is NOT a BUG, is as expected, but a bit tricky to figure out why.
Quote:
When getting value of a variable, it searches the list of Local variables first, only if it does not find it there
does it then search the Global variables list.
Inside your function the optional arg "All" does exist, its just not defined unless provided by the caller with a value.
A variable that dont exist has no entry in the Avisynth Local or Global variable List (or Table).
An Undefined variable does have an entry in the Local or Global variable Lists (or Tables), but has no value,
nor type (strictly speaking its type is undefined).

EDIT: Creating an additional Global as you have done will of course work, I tend to like naming globals with a prepended "G_" eg "G_All",
or sometime prepend the function name as in "G_Test_All" or "_G_Test_All", or "__G_Test_All".
__________________
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; 1st February 2021 at 14:46.
StainlessS is offline   Reply With Quote
Old 1st February 2021, 05:47   #60  |  Link
Danette
Registered User
 
Join Date: Apr 2013
Posts: 346
Quote:
Originally Posted by hello_hello View Post
I moved my copy out of the auto-loading plugins folder, made sure it resulted in a "no function named" error message, put it back and ran the script again.
This ^

Seems to work fine, now.

I'll wait until you and StainlessS exercise everything.
Danette is offline   Reply With Quote
Reply


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 00:44.


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