Log in

View Full Version : current_frame in HistogramAdjust


gwendolien
5th February 2013, 18:51
Can somebody PLEASE show me how to use current_frame variable inside HistogramAdjust?
Or:
why is clip.SubtitleString(current_frame) OK
but
HistogramAdjust(clip1, type="match", mclip=clip2, mf=current_frame)
is not changing the clip1 at all..
Both examples being inside ScriptClip(.....)
I am trying to adjust the histogram of clip1 to that of clip2 for all frames...
Many thanks in advance for any reply/reaction!

IanB
5th February 2013, 22:03
I believe the mf arg is the match clip frame number offset, not the absolute frame number.

So input frame N is matched with mclip frame N+mf.

gwendolien
5th February 2013, 22:31
Thanks for the response.
The idea is to match each individual frame of clip1 to that same frame of clip2.
Whether I omit the mf=current_frame or not,
NOTHING seems to change....that is the problem here.

ScriptClip(avi, """HistogramAdjust(avi, type="match", mclip=dvd, mf=current_frame)""")

The avi frames are UNCHANGED

IanB
6th February 2013, 00:39
:script:

Why are you using scriptclip?

What does this script do?avi=AviSource(....)

dvd=Mpeg2Source(....)

HistogramAdjust(avi, type="match", mclip=dvd)

gwendolien
6th February 2013, 09:08
Thanks IanB,

I finally got it working!

The documentation of HistogramAdjust says that mf is the frame of dvd to which avi is to be matched.
So I checked again:
avi_1=HistogramAdjust(avi, type="match", mclip=dvd, mf=0)
adjusts avi(all frames) to frame 0 of dvd.

So I concluded that I had to use ScriptClip in combination with current_frame...
and tried the corresponding:
avi_1=ScriptClip(avi, """HistogramAdjust(avi, type="match", mclip=dvd, mf=current_frame)""")

AND THAT WORKED.

Assigning to avi itself:
avi=ScriptClip(avi, """HistogramAdjust(avi, type="match", mclip=dvd, mf=current_frame)""")
however gives an error:

Traceback (most recent call last):
File "avsp.pyo", line 10012, in OnPaintVideoWindow
File "avsp.pyo", line 13149, in PaintAVIFrame
File "pyavs.pyo", line 717, in DrawFrame
File "pyavs.pyo", line 707, in _GetFrame
File "pyavs.pyo", line 272, in _GetFrame
File "avisynth.pyo", line 462, in GetFrame
WindowsError: exception: access violation reading 0x00030354

But who cares(for the moment): I GOT IT!

Thanks!

Gavino
6th February 2013, 11:49
Assigning to avi itself:
avi=ScriptClip(avi, """HistogramAdjust(avi, type="match", mclip=dvd, mf=current_frame)""")
however gives an error:
WindowsError: exception: access violation reading 0x00030354

The variable avi used here in the call to HistogramAdjust is evaluated at run-time (see here (http://avisynth.org/mediawiki/The_script_execution_model/Scope_and_lifetime_of_variables#Runtime_scripts)), so at that point (because of the assignment avi=avi.ScriptClip(...)) it refers to the result of the ScriptClip filter itself.

This produces a loop in the filter graph where the output of ScriptClip (via HistogramAdjust) is derived from itself.
So when Avisynth tries to fetch a frame from the graph, an infinite recursion occurs :eek: - stack overflow!

To avoid this, you could have written it as
avi=ScriptClip(avi, """HistogramAdjust(type="match", mclip=dvd, mf=current_frame)""")
Here the call to HistogramAdjust uses 'implicit last' instead of the variable avi - this last will be the clip passed as input to ScriptClip, ie the original value of avi.

gwendolien
6th February 2013, 12:15
Hello Gavino,

THANKS for the excellent explanation of the observed phenomenon here.
It makes "runtime" things a bit better understood here!



-----------------------------------------------------
There is nothing in such perfect harmony with itself as a "contradictio in terminis"