Log in

View Full Version : Unipolator - an universal frame interpolator script


Emulgator
27th December 2011, 16:52
And here is my Unipolator.
I decided to release it into the wild today, Santa was close and 2011 ran as hell.

Unipolator is an universal frame interpolator script to be run under Avisynth, based on MFlowInter from MVTools2 plugin.

To ease restoration of film scans Unipolator performs motion-based interpolation
of up to seven consequent missing frames in up to 52 places at one call.
Especially designed for in-place repair of heavily damaged frames and/or recalculation and reinsertion of missing frames.

A walkthrough-documentation is part of the script,
which helps with tailored assertions to check against certain parameter violations.

Unipolator has a nice switchable and resolution and widescreen-dependent info overlay
which fits into bigger scripts that evaluate source and final video parameters.

I guess the conditional splicer could be straightened out and forged into a function,
the whole beast could be a function as well (a Gavino case?), but my time is too limited right now.

Suggestions and Improvements welcome.
--------------
Oops.
The text that you have entered is too long (157793 characters). Please shorten it to 16000 characters long.

A .7z is coming soonish...

Jenyok
28th December 2011, 08:52
Unfortunately,
*.7z attachment is not supported (not approval for long, long time) here in site...
Please, attach *.zip or *.rar normal file...

Guest
28th December 2011, 15:28
[bump after attachment approval -- no problem with 7z files]

Mounir
3rd January 2012, 15:14
I don't freaking understand the syntax; can you give us an example:
For instance:
- frame 1500 is damaged
- frame 1700 to 1704 are damaged

Thanks for your help

Emulgator
3rd January 2012, 20:30
Frame 1500:

insertbeforeAA=1500 insertlengthAA=-1

Frames 1700 to 1704: 5 damaged Frames in a row.
This is not implemented directly as Replace, here up to 3 in a row are possible.

But using pure Frame Insertion in Unipolator up to seven missing frames are implemented.

No sweat here:
First Trim() away the defect frames, then apply Unipolator for Frame Insertion:

Trim(0,1699) ++ Trim(1705,0)

What was frame 1705 now becomes frame 1700.

Then call Unipolator again

insertbeforeAA=1700 insertlengthAA=5

and the motion gap between 1699 and 1700 ( the old 1705) should be populated by 5 freshly interpolated frames becoming the new 1700, 1701, 1702, 1703, 1704.

Emulgator
3rd January 2012, 21:02
I will give some little helpers here to everyone to find your way through the interpolated frames, where they are and where the frame bilance actually ends up:

Put your sourcefilter here...

..source("X:\path\file")

Then control the Overlays here:
(you only use 0 to mute any overlays, 1 to see input framenumbers only and 5 to see input and output frame numbers.

The other controls are only useful in my bergwerk script;-)

FrameCounterOverlay=0 ## 0: FrameCounterOverlay OFF | 1: Source only | 2: Source+PostTrim | 3: Source+PostTrim+PostDec
## 4: Source+PostTrim+PostDec+PostDeRoll | 5: Source+SourceTrim+PostDec+PostDeRoll+PostInterpolator
## 6: All (Source+SourceTrim+PostDec+PostDeRoll+PostInterpolator+Final)

Give Overlay-Fontsizes here:

ResizerWide= false
ResizerHD= false
OverlayFontWidth= ResizerWide==true ? 3.75 : 4.0
OverlayFontSize= ResizerHD==true ? 12 : 10

Then evaluate the framecount before Unipolator as follows:

#[*#.....................................................................................Print Source-Framenumber Top/Bottom.....................................................................................................
function PrintSourceFrameNumberATop(clip a) {
ScriptClip(a, """Subtitle("Source Frame "+string(current_frame), size=overlayfontsize+2, align=5, x=(width*1/8)+12, y=overlayfontsize+10, font_width=OverlayFontWidth, text_color=$00AAAAFF)""")
}
function PrintSourceFrameNumberABottom(clip a) {
ScriptClip(a, """Subtitle("Source Frame "+string(current_frame), size=overlayfontsize+2, align=5, x=(width*1/8)+12, y=height-12, font_width=OverlayFontWidth, text_color=$00AAAAFF)""")
}
FrameCounterOverlay>=1 ? PrintSourceFrameNumberATop(last) : NOP
FrameCounterOverlay>=1 ? PrintSourceFrameNumberABottom(last) : NOP
#*]#.........................................................................................End of Source-Framenumber Top/Bottom..............................................................................................

Put Unipolator code here...

[*################ Start of Emulgator's Universal Motion Based Frame Interpolator #######################
.....
*]############ End of Emulgator's Universal Motion Based Frame Interpolator Unipolator 1.15 ###################

Then evaluate the framecount after Unipolator as follows:

#[*#...........................................................................Print PostInsert-Framenumber Top/Bottom.......................................................................................................
function PrintPostInsertFrameNumberETop(clip e) {
ScriptClip(e, """Subtitle("PostInterpol Frame "+string(current_frame), size=overlayfontsize+2, align=5, x=(width*6/8)-24, y=overlayfontsize+10, font_width=OverlayFontWidth, text_color=$00EEEEEE)""")
}
function PrintPostInsertFrameNumberEBottom(clip e) {
ScriptClip(e, """Subtitle("PostInterpol Frame "+string(current_frame), size=overlayfontsize+2, align=5, x=(width*6/8)-24, y=height-12, font_width=OverlayFontWidth, text_color=$00EEEEEE)""")
}
FrameCounterOverlay>=5 ? PrintPostInsertFrameNumberETop(last) : NOP
FrameCounterOverlay>=5 ? PrintPostInsertFrameNumberEBottom(last) : NOP
#*]#..........................................................................End of PostInsert-Framenumber Top/Bottom......................................................................................................


Now one should be able to see what he is doing framecountwise...

Emulgator
3rd January 2012, 23:55
To illustrate cases where linear motion interpolation between two frames might not succeed
(jiggling motion, to and fro, colliding objects...), I'd like to quote from PM:

Mounir, your sample has 13 defective frames in row.
It looks like heavy encoding artifacts to me (moving white blocks).

While these 13 defective frames pass
the original motion of the running men (bouncing of body and limbs)
stretches over more than a half oscillation period.

Interpolated motion will only look convincing if less than half of an oscillation period has to be interpolated.
because linear interpolation can not know about the number of oscillations in between.

Only if all motion parts and their expected oscillations could be modeled from more previous and following frames this would be feasible.
But this is outside of the scope of MVTools at the moment, I guess.

The result will be morphing of the last good frame of the starting part into the first good frame of the ending part
and so unfortunately not resemble a running crowd.

Lyris
4th March 2012, 09:52
Sorry, but can you explain how to use this?

Let's say I have a file and I want to replace one damaged frame, say, frame 51186, using data from frames 51185 and 51187. How do I do this with your script?

I've tried changing the values inside the .AVS file, for example:

insertbeforeAA=51186 insertlengthAA=-1

But it just throws the error, "Evaluate: Unrecognized exception".

Emulgator
4th March 2012, 10:20
Lyris, your syntax is correct.
Hm. I could not repeat this fault. I just opened an .avi source, total length 5750 frames,
insertbeforeAA=5118 insertlengthAA=-1
threw the script on VirtualDub 1.10.0, Goto frame 5118 and got a properly interpolated and replaced frame
(source was interlaced, so horizontally scrolling credits are a bit skewed.)
http://www.dvd-manufactur.de/files/2012_03_05_Screenshot_Unipolator.png
Maybe a dependency on MVTools versions ?
At my editing system (WinXP32 SP3 T7600G, 4GB RAM, 9x500GB HDD), Unipolator calls mvtools2 version 2.5.11.6 at the moment.
As the shape of the frame number renderings up to 4th position suggest,
the resulting frame 5118 is indeed an interpolation of the former adjacent frames 5117 and 5119.
If you had seen the first frame version before 10:34 GMT+1, please refresh your browser,
I had my new version of filldrops3 still activated in the chain while screenshooting...

lisztfr9
22nd April 2012, 21:53
Hi,

I would need such a script for about 15 frames, for the sudden bursts of noise on my old VHS-TV records.

L

Revgen
24th April 2012, 12:13
This filter does a great job at SD resolutions. I use it to repair damaged frames from TV broadcasts.


Unfortunately I can't get it to work at HD resolutions. Nothing in the instruction manual mentions high definition sources being restricted.

Emulgator
25th April 2012, 21:41
Yes, confirmed. I developed Unipolator for SD restoration and was happy with it.

Now that I have some HD footage to restore myself I will have to make it work for HD too...
On a WinXP32 SP3 here Unipolator eats up 2GB rapidly when loading HD.
When reaching the first frame to be interpolated and MVtools kick in,
Memory use gets even higher and voila: access violation.

Will see how it behaves on a Win7U64 sooner or later, but no time for now.