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 13th April 2014, 01:48   #1  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
Using avisynth for special interpolation

I want to interpolate frames of a video that looks like the following. It's 30 fps according to specs, but in reality has this order:

Quote:
1. Movie picture
2. Clone of previous movie picture
3. Movie picture
4. Clone of previous movie picture
5. Clone of previous movie picture
6. Repeat from 1
equals

Quote:
AABBBCCDDDEEFFFGGHHH....

where

A = first frame
B = second frame
C = third frame
D = ...

Could start with an offset.

Goal is to create a good* transitionary image from 1 to 3 and 3 to 1 of the next round, so it looks like 30fps when it's in fact less that 15 fps.

Like this

Quote:
Movie picture 1
Morph/other transition method* between Movie picture 1 and Movie picture 2
Movie picture 2
2 frames Morph/other transition method between Movie picture 2 and Movie picture 3
Movie picture 3
Morph/other transition method between Movie picture 3 and Movie picture 4
Movie picture 4
2 frames Morph/other transition method between Movie picture 4 and Movie picture 5
Movie picture 5
Morph/other transition method between Movie picture 5 and Movie picture 6
Movie picture 6
2 frames Morph/other transition method between Movie picture 6 and Movie picture 7
Movie picture 7
etc.

How do I do that in avisynth?

* I love SVP. Maybe it's transition method can be used?

Last edited by Kim Brandstetter; 14th April 2014 at 18:47.
Kim Brandstetter is offline   Reply With Quote
Old 13th April 2014, 02:13   #2  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,922
SelectEvery(5,0,2). Then convert frame rate as needed using your favorite method.

The local Avisynth Gods will arrive shortly, I suppose.

Last edited by Guest; 13th April 2014 at 02:16.
Guest is offline   Reply With Quote
Old 13th April 2014, 02:56   #3  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
Thanks. Doesn't that speed up or slow down the video? The Clones of previous movie pictures are there to keep the video in sync with the audio and in general to keep the video speed in sync with reality.
Kim Brandstetter is offline   Reply With Quote
Old 13th April 2014, 03:00   #4  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,922
You either accept the duplicates or you remove them and do something with the decimated stream. You could try some motion adaptive frame interpolation, but it would have to start from the decimated stream. Your base stream is 11.988 fps. You can play it at that rate or you can make up some new frames.

Have you looked at the available motion-compensated interpolators. I don't know much about it but I have heard of mvflow, etc.

Last edited by Guest; 13th April 2014 at 03:04.
Guest is offline   Reply With Quote
Old 13th April 2014, 15:08   #5  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
SelectEvery(5,0,2) automatically adjusts the video frame rate from 30 fps to 12 fps so there shouldn't be any audio desync.

Assuming the AABBB pattern is fixed throughout the whole video, you can use neuron2's suggestion as is, but if the pattern changes throughout the source, one way out is to use TDecimate(cycleR=3,cycle=5) or the slightly more accurate SelectEven().TDecimate(cycleR=1,cycle=5). These two alternatives also adjust the frame rate automatically.

This is if you're okay with 12 fps output; if you want motion-interpolated 24/30/60/whatever fps output, you'll have to get rid of all the duplicates first (using any of the three methods mentioned above) prior to motion interpolation.
colours is offline   Reply With Quote
Old 13th April 2014, 17:04   #6  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 984
You may try filldrops123.avsi
Copy, paste, rename as filldrops123.avsi, put it into your plugins folder and call function as filldrops3.
---------------------------------------
Code:
# johnmeyer's filldropsI (I for Interlaced) from 16.April 2011 based on MugFunky's filldrops see below, extended by Emulgator on 25.Feb.2012.
# http://forum.doom9.org/showthread.php?p=1493082#post1493082
# Automatic dropping of duplicated frames/fields followed by generation of interpolated frames/fields and reinsertion.
# Needs MVTools2, is more forgiving when duplicates do differ a little.
# johnmeyers's Difference was 0.1, deviation now tunable. 
function filldropsI (clip c, float "dev")
{
 dev=default(dev, 2.0)
  even = c.SeparateFields().SelectEven()
  super_even=MSuper(even,pel=2)
  vfe=manalyse(super_even,truemotion=true,isb=false,delta=1)
  vbe=manalyse(super_even,truemotion=true,isb=true,delta=1)
  filldrops_e = mflowinter(even,super_even,vbe,vfe,time=50)

  odd  = c.SeparateFields().SelectOdd()
  super_odd=MSuper(odd,pel=2)
  vfo=manalyse(super_odd,truemotion=true,isb=false,delta=1)
  vbo=manalyse(super_odd,truemotion=true,isb=true,delta=1)
  filldrops_o = mflowinter(odd,super_odd,vbo,vfo,time=50)

global devthresh=dev
  
  evenfixed = ConditionalFilter(even, filldrops_e, even, "YDifferenceFromPrevious()", "lessthan", "devthresh", show=true)
  oddfixed  = ConditionalFilter(odd,  filldrops_o, odd,  "YDifferenceFromPrevious()", "lessthan", "devthresh", show=true)

  Interleave(evenfixed,oddfixed)
  Weave()
}

#[*
# MugFunky's filldrops from 19.December 2005 
# http://forum.doom9.org/showthread.php?p=753779#post753779
# "...so i wrote a little function to replace all frames that are identical to the previous one with a motion-interpolation of the adjacent frames.
# it could be useful for captures that you can't get again, but are full of drops..."
# Needs MVTools, duplicates must match perfectly, (useful only for capture drop&repeats).
function filldrops (clip c, float "dev")
{
vf=c.mvanalyse(truemotion=true,pel=2,isb=false,delta=1,idx=1)
vb=c.mvanalyse(truemotion=true,pel=2,isb=true,delta=1,idx=1)
global filldrops_d = c.mvflowinter(vb,vf,time=50,idx=1)
global filldrops_c = c
global devthresh=dev

c.scriptclip("""ydifferencefromprevious()<devthresh? filldrops_d : filldrops_c""")
}
#*]

# MugFunky's filldrops from 19.December 2005, extended by Emulgator on 25.Feb.2012
# http://forum.doom9.org/showthread.php?p=753779#post753779
# "...so i wrote a little function to replace all frames that are identical to the previous one with a motion-interpolation of the adjacent frames.
# it could be useful for captures that you can't get again, but are full of drops..."
# Needs MVTools2, deviation now tunable.
function filldrops2 (clip c, float "dev")
{
dev=default(dev, 2.0)
super=MSuper(c,pel=2)
vf=manalyse(super,truemotion=true,isb=false,delta=1)
vb=manalyse(super,truemotion=true,isb=true,delta=1)

global filldrops_d = mflowinter(c,super,vb,vf,time=50)
global filldrops_c = c
global devthresh=dev

c.scriptclip("""ydifferencefromprevious()<devthresh? filldrops_d : filldrops_c""")
}


# filldrops3 based on MugFunky's filldrops from 19.December 2005, extended by Emulgator on 26.Feb.2012 to accommodate interpolation of Doupledrops
# http://forum.doom9.org/showthread.php?p=753779#post753779
# "...so i wrote a little function to replace all frames that are identical to the previous one with a motion-interpolation of the adjacent frames.
# it could be useful for captures that you can't get again, but are full of drops..."
# Needs MVTools2, deviation now tunable.
function filldrops3 (clip c, float "dev")
{
blksz=16 # Blocksize for Motion search. Default = 8. My Default 16: Delivers a smoother picture. 4: Gives too many artefacts with poorer source.
searchp=32 # Radius for Motion search. Default = 2, My Default = 32
bld=true # Decides what to do if a Scenechange is detected by the following parameters: true will blend, false will repeat previous frame.
SCDpb=800 # Default = 400. thSCD1. SAD (pixels*luma values) Threshold per Block. A Block exceeding this SAD is considered changed.
##                     SAD = Sum of Absolute Differences  = Number of pixels per 8x8 block (=64) multiplied with their luma difference.
##                     SCDpb is always given related to 8x8 blocks and scaled internally to match other block sizes. SCDbp is thSCD1 and is evaluated before SCDpf=thSCD2
SCDpf=200 # 0-255, Default=130. thSCD2. Changed Blocks percentage threshold per frame. 0=0%, 127=50%, 255 = 100%.
##                     This Threshold sets which minimal percentage of changed blocks a frame has to contain to be considered as a scene change.

dev=default(dev, 2.0)
super=MSuper(c,pel=2)

back_vec=MAnalyse(super, blksize=blksz, search=5, searchparam=searchp, isb=true, delta=1, temporal=false, dct=0, divide=0, trymany=false)#delta=framedistance;isb=IS Backward
		# Looks 1 frame ahead and calculates vectors backward to reference frame.
forw_vec=MAnalyse(super, blksize=blksz, search=5, searchparam=searchp, isb=false, delta=1, temporal=false, dct=0, divide=0, trymany=false)#search 3:=Exhaustive; 4:=Hex(default); 5:=UMH
		# Looks 1 frame behind and calculates vectors forward to reference frame.
dblback_vec=MAnalyse(super, blksize=blksz, search=5, searchparam=searchp, isb=true, delta=2, temporal=false, dct=0, divide=0, trymany=false)#delta=framedistance;isb=IS Backward
		# Looks 2 frames ahead and calculates vectors backward to reference frame. To be used when reference frame + 1 has to be excluded.
dblforw_vec=MAnalyse(super, blksize=blksz, search=5, searchparam=searchp, isb=false, delta=2, temporal=false, dct=0, divide=0, trymany=false)#search 3:=Exhaustive; 4:=Hex(default); 5:=UMH
		# Looks 2 frames behind and calculates vectors forward to reference frame. To be used when reference frame -1 has to be excluded.

global fillsingdrops = MFlowInter(c,super,back_vec,forw_vec,time=50, blend=bld, thSCD1=SCDpb, thSCD2=SCDpf)
global filldoubdrops33 = MFlowInter(c,super,dblback_vec,dblforw_vec,time=33, blend=bld, thSCD1=SCDpb, thSCD2=SCDpf)
global filldoubdrops67 = MFlowInter(c,super,dblback_vec,dblforw_vec,time=67, blend=bld, thSCD1=SCDpb, thSCD2=SCDpf)
global oric=c
global devthresh=dev


#ConditionalFilter(c, c, fillsingdrops, "YDifferenceFromPrevious()", ">", "devthresh", show=true)##works for mending of single framerepeats
#ConditionalFilter(c, c, filldoubdrops33, "YDifferenceFromPrevious()>devthresh", "&&", "YDifferenceToNext()>devthresh", show=true)##wrong syntax

c.scriptclip("""(YDifferenceFromPrevious<devthresh) && (YDifferenceToNext<devthresh) ? (filldoubdrops33++filldoubdrops67.Trim(1,0)) : (YDifferenceFromPrevious<devthresh) ? fillsingdrops : oric""")

}
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain)
"Data reduction ? Yep, Sir. We're working on that issue. Synce invntoin uf lingöage..."

Last edited by Emulgator; 13th April 2014 at 17:07.
Emulgator is offline   Reply With Quote
Old 13th April 2014, 20:44   #7  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
Quote:
Originally Posted by Emulgator View Post
You may try filldrops123.avsi
Copy, paste, rename as filldrops123.avsi, put it into your plugins folder and call function as filldrops3.
---------------------------------------
Code:
super=MSuper(c,pel=2)
Thanks. MSuper is missing though.

PS: How to deactivate those annoying random questions?
Kim Brandstetter is offline   Reply With Quote
Old 13th April 2014, 20:58   #8  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
MSuper is part of MVTools; there's a patched build in Dither tools.

Be aware that unless you do some munging with variable frame rates (which is not recommended unless you really know what you're doing), there will be judder if you don't remove the duplicate frames prior to motion interpolation.

I assume the annoying questions go away after you hit some arbitrary post count; some other forum posters I asked said they didn't see the questions at all.

Edit: To make this work with one of the filldrops functions (without judder), you'd need to make the group of three identical frames a group of only two identical frames. (filldrops3 looks like it was designed to handle such groups of three, but that is not the right thing to do in this case.) TDecimate(mode=1) does exactly that, getting rid of the third frame. The script you use should be something like:

Code:
source
TDecimate(mode=1) # so instead of an AABBB pattern, you have AABB
filldrops3()
But then you might run into issues with multiple duplicate frames being detected etc., and the best option is just to decimate to 12 fps first.

Code:
source
SelectEven().TDecimate()
super = MSuper(last)
vecb = MAnalyse(super,isb=true)
vecf = MAnalyse(super,isb=false)
MFlowFps(last,super,vecb,vecf,num=30,den=1,blend=false) # replace num/den with the desired output frame rate

Last edited by colours; 13th April 2014 at 21:23. Reason: elaborate on judder
colours is offline   Reply With Quote
Old 13th April 2014, 21:07   #9  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
It works now. This is just amazing. Thanks to all of you for your quick support.

EDIT: See below.

Last edited by Kim Brandstetter; 13th April 2014 at 23:50.
Kim Brandstetter is offline   Reply With Quote
Old 13th April 2014, 23:42   #10  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
I was wrong. filldrops3 does well at dropping cloned frames, but it does not interpolate between them. So what I got was 30fps while those 30fps are the previous pictures minus the cloned ones, so it is way faster.

Now I have this code

Code:
DirectShowSource("13. April 2014, 082538.AVI")
ConvertToYV12()
SelectEven().TDecimate()
super = MSuper(last)
vecb = MAnalyse(super,isb=true)
vecf = MAnalyse(super,isb=false)
MFlowFps(last,super,vecb,vecf,num=30,den=1,blend=false) # replace num/den with the desired output frame rate
But that creates a weirdly distorted video with artefacts all over the place. Also, I get 0.92 fps rendering time in virtualdub, which is bad.

Last edited by Kim Brandstetter; 13th April 2014 at 23:50.
Kim Brandstetter is offline   Reply With Quote
Old 13th April 2014, 23:47   #11  |  Link
Richard1485
AviSynth monkey
 
Richard1485's Avatar
 
Join Date: Feb 2010
Posts: 398
Quote:
Originally Posted by colours View Post
but if the pattern changes throughout the source, one way out is to use TDecimate(cycleR=3,cycle=5) or the slightly more accurate SelectEven().TDecimate(cycleR=1,cycle=5).
I understand the first option but not the second. Might changes in the pattern not cause problems if at some point SelectEven() discards a frame that is not duplicated? I'm just curious.
Richard1485 is offline   Reply With Quote
Old 14th April 2014, 04:17   #12  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 9,037
Quote:
Originally Posted by Kim Brandstetter View Post
Code:
DirectShowSource("13. April 2014, 082538.AVI")
ConvertToYV12()
SelectEven().TDecimate()
super = MSuper(last)
vecb = MAnalyse(super,isb=true)
vecf = MAnalyse(super,isb=false)
MFlowFps(last,super,vecb,vecf,num=30,den=1,blend=false) # replace num/den with the desired output frame rate
Quote:
creates a weirdly distorted video
Perhaps try replace stuff in blue
Code:
    super=MSuper(pel=1, hpad=0, vpad=0)
    backward_1=MAnalyse(super, chroma=false, isb=true,  blksize=16, blksizev=16, searchparam=3, plevel=0, search=3, badrange=(-24))
    forward_1 =MAnalyse(super, chroma=false, isb=false, blksize=16, blksizev=16, searchparam=3, plevel=0, search=3, badrange=(-24))
    backward_2 = MRecalculate(super, chroma=false, backward_1, blksize=8, blksizev=8, searchparam=0, search=3)
    forward_2  = MRecalculate(super, chroma=false, forward_1,  blksize=8, blksizev=8, searchparam=0, search=3)
    MBlockFps(super, backward_2, forward_2, num=num, den=den, mode=0)
EDIT: replace num=30, den=1

should get rid of weird swirly stuff.
__________________
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; 14th April 2014 at 16:59.
StainlessS is offline   Reply With Quote
Old 14th April 2014, 04:23   #13  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
First arrow is SelectEven, second is TDecimate (assuming it picks the correct frames).

AAABBCCCDD → AABCD → ABCD
ABBBCCDDDE → ABCDD → ABCD
AABBBCCDDD → ABBCD → ABCD
ABBCCCDDEE → ABCDE → ABCD or BCDE (note that A/E are duplicates across groups of five)
AABBCCCDDE → ABCCD → ABCD

The increased accuracy comes from nuking five sixths of the dupes in each ten-frame section without even needing to detect which frames are duplicates. The pattern change transitions might not be handled exactly, but stepping through the video to manually handle these is rather time-consuming.

Kim Brandstetter: You might also want to check if it's DirectShowSource causing the artifacts if StainlessS' suggestion doesn't help. Not likely, but it's not something to overlook.
colours is offline   Reply With Quote
Old 14th April 2014, 09:30   #14  |  Link
Richard1485
AviSynth monkey
 
Richard1485's Avatar
 
Join Date: Feb 2010
Posts: 398
Quote:
Originally Posted by colours View Post
The pattern change transitions might not be handled exactly, but stepping through the video to manually handle these is rather time-consuming.
Ah! So you're accepting a trade off: an overall increase in accuracy set against the risk of not handling some pattern changes exactly. Thanks for the explanation. Apart from that, I more or less saw what you were doing.
Richard1485 is offline   Reply With Quote
Old 14th April 2014, 17:05   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 9,037
Quote:
Originally Posted by colours View Post
You might also want to check if it's DirectShowSource causing the artifacts
Yep, DirectshowSource can cause blending and other anomalies depening upon how it is set up (eg does AUTO deinterlace, inverse telecine + more), use AviSource or other, DirectShowSource only if nothing else works.

If the weird distortions you wrote of are sort of 'swirly', then MBlockFps instead of MFlowFps may get rid.

EDIT: The previously posted MBlockFPS script is product of some Avisynth wizard, not mine, dont recall where I got it but it
does generally produce less artifacts than the script snippet it replaces.
__________________
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; 14th April 2014 at 18:37.
StainlessS is offline   Reply With Quote
Old 14th April 2014, 19:12   #16  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
It is still juddering and disappointing.

So a general question: what can I expect from frame generation 12 fps -> 30 fps?

30 fps -> 60 fps is great but 12 fps -> 30 fps is not. Anybody can offer samples?

Last edited by Kim Brandstetter; 14th April 2014 at 19:48.
Kim Brandstetter is offline   Reply With Quote
Old 14th April 2014, 19:42   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 9,037
I think it likely that 12fps -> 24fps would be somewhat better than 12fps -> 30fps, the amount of movement
between frames at 12fps will be quite large and is asking rather a lot to smoothly generate flaw free video at 30fps.
The smaller movement differences between frames at 30fps make it much easier to 'guess' tweened frames to produce
60fps (it's also an exact multiple).

I've read good thinks about SVP but have never tried it.

Is 30fps an absolute requirement ?
__________________
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 14th April 2014, 19:43   #18  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
Quote:
Originally Posted by StainlessS View Post
I think it likely that 12fps -> 24fps would be somewhat better than 12fps -> 30fps, the amount of movement
between frames at 12fps will be quite large and is asking rather a lot to smoothly generate flaw free video at 30fps.
The smaller movement differences between frames at 30fps make it much easier to 'guess' tweened frames to produce
60fps (it's also an exact multiple).

I've read good thinks about SVP but have never tried it.

Is 30fps an absolute requirement ?
12 fps is almost unbearable.
Kim Brandstetter is offline   Reply With Quote
Old 14th April 2014, 19:45   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 9,037
Try 24fps, see if that is bearable.
__________________
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 14th April 2014, 20:34   #20  |  Link
Kim Brandstetter
NSA Agent
 
Kim Brandstetter's Avatar
 
Join Date: Dec 2011
Location: Classified data
Posts: 20
Here's a testfile:
Quote:
http://www.mediafire.com/watch/durwstuwhk0b0dz/14._April_2014,_095208.AVI
Why don't you get the file and apply your ideas to it to tell me what works best?

Last edited by Kim Brandstetter; 14th April 2014 at 21:00.
Kim Brandstetter 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 08:59.


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