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 18th October 2010, 13:39   #21  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
Issuing basic Avisynth syntax/grammar.

Code:
WhateverSourceFilter("thesource.ext")

Source = last

	Sup = msuper()
	bv = manalyse(Sup, isb=true, delta=3)
	fv = manalyse(Sup, isb=false, delta=3)  

[..etc..]
Or to make everything ultimately explicit:

Code:
source = WhateverSourceFilter("thesource.ext")

	Sup = source.msuper()
	bv = manalyse(Sup, isb=true, delta=3)
	fv = manalyse(Sup, isb=false, delta=3)  

[..etc..]

source = source.RecoverOneFrame(7)
source = source.RecoverFramePair(26)
source = source.RecoverOneFrame(30)
source = source.RecoverFramePair(50)
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 18th October 2010, 14:00   #22  |  Link
pirej
Registered User
 
Join Date: Aug 2009
Posts: 26
Well.. thanks for the basic Avisynth syntax/grammar
Anyway.. Source = last worked, thanks.
pirej is offline   Reply With Quote
Old 28th November 2011, 06:13   #23  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
Didee
Are you correct in Code, see below ?
.
Code:
function RecoverFramePair(clip Source, int N)
{
	# N is number of the first frame in Source that needs replacing. 
	# Frames N and N+1(O) will be replaced.
	
	Source.trim(0,N-1) ++ CandidatesForN.trim(N-1,-1) ++ CandidatesForO.trim(N-1,-1) ++ Source.trim(N+2,0)
}

function RecoverOneFrame(clip Source, int N)
{
	# N is number of the frame in Source that needs replacing. 
	# Frame N  will be replaced.
	
	Source.trim(0,N-1) ++ CandidatesForC.trim(N-1,-1) ++ Source.trim(N+1,0)
}
.
or maybe Code else
.
Code:
function RecoverFramePair(clip Source, int N)
{
	# N is number of the first frame in Source that needs replacing. 
	# Frames N and N+1(O) will be replaced.
	
	Source.trim(0,N-1) ++ CandidatesForN.trim(N,-1) ++ CandidatesForO.trim(N+1,-1) ++ Source.trim(N+2,0)
}

function RecoverOneFrame(clip Source, int N)
{
	# N is number of the frame in Source that needs replacing. 
	# Frame N  will be replaced.
	
	Source.trim(0,N-1) ++ CandidatesForC.trim(N,-1) ++ Source.trim(N+1,0)
}
.
Wait answer from you...
Jenyok is offline   Reply With Quote
Old 28th November 2011, 10:58   #24  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by Jenyok View Post
Are you correct in Code, see below ?
The original code is correct.
The 'candidate' clips are produced by MFlowInter and frame N-1 is the interpolation between the original N-1 and N+1 or N+2 to give the replacement frame N or N+1.

But actually there is a bug here:
Quote:
Originally Posted by Didée View Post
Code:
	Sup = msuper()
	bv = manalyse(Sup, isb=true, delta=3)
	fv = manalyse(Sup, isb=false, delta=3)  
global 	CandidatesForN = mflowinter(sup, bv, fv, time=33.3, ml=100)
global 	CandidatesForO = mflowinter(sup, bv, fv, time=66.7, ml=100)
global 	CandidatesForC = mflowinter(sup, bv, fv, time=50.0, ml=100)
The CandidatesforC should be done using vectors with a delta of 2, not 3.
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 28th November 2011 at 11:06.
Gavino is offline   Reply With Quote
Old 28th November 2011, 20:16   #25  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Another problem with this code (also in original by pirej) is that the functions don't work for N=1 (ie when replacing frame 1 by interpolating between frame 0 and frame 2 or 3).
Quote:
Originally Posted by Didée View Post
Code:
function RecoverFramePair(clip Source, int N)
{
	# N is number of the first frame in Source that needs replacing. 
	# Frames N and N+1(O) will be replaced.
	
	Source.trim(0,N-1) ++ CandidatesForN.trim(N-1,-1) \
    ++ CandidatesForO.trim(N-1,-1) ++ Source.trim(N+2,0)
}
Because of the special meaning of 0 as the 2nd argument to Trim, this will give the wrong result when N=1.
It should be written instead as Source.Trim(0, -N), and similarly in RecoverOneFrame.

(See stickboy's classic Caveats of using Trim in functions.)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th November 2011, 13:58   #26  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
I wrote some restore bad frame functions with MFlowInter with following parameters (big number functions - 10)
.
delta=11 # 10 frames
time=9.09
.
Also I wrote Backdoor restore functions.
All functions work fine.
I really restored 10 continious bad frames in video with motions.

Last edited by Jenyok; 1st December 2011 at 19:53.
Jenyok is offline   Reply With Quote
Old 2nd December 2011, 10:18   #27  |  Link
sven_x
Registered User
 
Join Date: Oct 2011
Location: Germany
Posts: 39
Quote:
Originally Posted by Jenyok View Post
I wrote some restore bad frame functions with MFlowInter with following parameters (big number functions - 10) [...]
Also I wrote Backdoor restore functions.
Please post your script.
I am searching for a script that can do this interpolations basing on a ConditionalReader file, that the following script produces.

PHP Code:
# perhaps ydiffp can be replaced by last value of ydiffn to speed up the analysis pass.

#0.6b:
#Writing ConditionalReader() Type files dups_pl.txt, dups_pre.txt, dups_post.txt


global source1=AVISource("test79400.avi")
#DirectshowSource("....avi",30,true,false,true)
#global source1=SegmentedAVISource("....avi")

last=source1
ConvertToYV12
()  #  YV12 needed for MVTools and for CCE Basic

global diffp=0
global diffn=0
global fp1=0

global dup_thresh=0.0001    #threshold, below threshold is considered as duplicate frame
global gap_pos=0               #Gap start
global gap_l=0                   #Gap length
global pregap=0                 #Gap YDifference before gap
global postgap=0               #Gap YDifference after gap
global gap_end=false         # Bolean, triggers writing of gap properties into dup.txt file
global gapmarker="="         #Visual Gap length marker
global ydiffp=1                 
global ydiffn=1

#Test function: display parameter results visually
#..................................................

#ScriptClip("""Subtitle("frame_number: "+String(fp1)+", YdiffP: "+String(diffp)+", YdiffN: "+String(diffn)) """)

#~ ScriptClip("""Subtitle(x=8, Y=20,text_color=$FF4422,\
#~ "pos: "+String(gap_pos)+", gap_l: "+String(gap_l)+", pregap: "+String(pregap)\
#~ +", postgap: "+String(postgap)+", gapmarker: "+String(gapmarker) ) """)



#Display frame number and diffp, diffn
#...................................................................

ScriptClip("f1()")
ScriptClip("f3()")
ScriptClip("f4()")

function 
f1(clip c) {
c=FrameEvaluate(c,"fp1=current_frame")
return(
c)
}

function 
f3(clip c) {
c=FrameEvaluate(c,"diffp=YDifferenceFromPrevious(source1)")
return(
c)
}

function 
f4(clip c) {
c=FrameEvaluate(c,"diffn=YDifferenceToNext(source1)")
return(
c)
}

#Search gaps with duplicate frames  and write dups_report.txt + txt-files
#......................................................................
ScriptClip("fg1a()")
ScriptClip("fg1b()")
ScriptClip("fg1c()")
ScriptClip("fg2()")
ScriptClip("fg3a()")
ScriptClip("fg3b()")
ScriptClip("fg3c()")

colon=" "   #define colon

WriteFileStart("dups_report.txt"""" "frame number gap-length Ydiffpregap Ydiffpostgap marker" """)
WriteFileIf("dups_report.txt""gap_end== true""gap_pos""colon""gap_l""colon""pregap""colon","postgap", \
"colon""""LeftStr("===========",gap_l)""")

WriteFileStart("dups_pl.txt"""" "Type int" """,false)                #position, gap lenght
WriteFileStart("dups_pl.txt"""" "Default 0" """,true)  
WriteFileStart("dups_pre.txt"""" "Type float" """,false)          #position, Ydiff pre gap
WriteFileStart("dups_pre.txt"""" "Default 0.0" """,true)          #append
WriteFileStart("dups_post.txt"""" "Type float" """,false)        #position, Ydiff post gap
WriteFileStart("dups_post.txt"""" "Default 0.0" """,true)          #append

WriteFileIf("dups_pl.txt",    "gap_end== true""gap_pos""colon""gap_l")        #position, gap lenght
WriteFileIf("dups_pre.txt",  "gap_end== true""gap_pos""colon""pregap")        #position, Ydiff pre gap
WriteFileIf("dups_post.txt""gap_end== true""gap_pos""colon""postgap")       #position, Ydiff post gap


#gapmarker=LeftStr("=========",gap_l)  #visually marking gap length 

#begin gap: gap_pos=current_frame, gap_l=1
#YDifferenceFromPrevious() > dup_thresh && YDifferenceToNext() < dup_thresh ? 

function fg1a(clip c) {
c=FrameEvaluate(c,"gap_pos= ydfp > dup_thresh && ydfn < dup_thresh ? current_frame+1 : gap_pos" )
return(
c)
}

function 
fg1b(clip c) {
c=FrameEvaluate(c,"gap_l= ydfp > dup_thresh && ydfn < dup_thresh ? 0 : gap_l" )
return(
c)
}

function 
fg1c(clip c) {
c=FrameEvaluate(c,"pregap= ydfp > dup_thresh && ydfn < dup_thresh ? ydfp : pregap" )
return(
c)
}


#middle gap: gap=gap+1
#YDifferenceFromPrevious() < dup_thresh && YDifferenceToNext() < dup_thresh ? 

function fg2(clip c) {
c=FrameEvaluate(c,"gap_l= ydfp < dup_thresh && ydfn < dup_thresh ? gap_l+1 : gap_l" )
return(
c)
}


#end gap: gap=gap+1 , call writefileif, 
#YDifferenceFromPrevious() < dup_thresh && YDifferenceToNext() > dup_thresh ? 

function fg3a(clip c) {
c=FrameEvaluate(c,"gap_l= ydfp < dup_thresh && ydfn > dup_thresh ? gap_l+1 : gap_l" )
return(
c)
}

function 
fg3b(clip c) {
c=FrameEvaluate(c,"gap_end= ydfp < dup_thresh && ydfn > dup_thresh && current_frame > 0 ? true : false" )
return(
c)
}   
# recognize and of gap, but exclude frame 0 


function fg3c(clip c) {
c=FrameEvaluate(c,"ydfp=YDifferenceFromPrevious(source1)"\
                          +
"ydfn=YDifferenceToNext(source1)" \
                          +
"postgap= ydfp < dup_thresh && ydfn > dup_thresh ? ydfn : postgap" )
return(
c)
}


#Cropping to increase encoding speed
#..............................................................................
Crop(500360, -0, -0)
#cropping increases speed up to 400% for first pass if you run the script by encoding 



The ConditionalReader file dups_pl.txt looks like this:
Code:
Type int
Default 0
57 10
104 1
107 1
110 1
118 1
Which is: Position LengthOfGap

The report file dups_report.txt looks like this:
Code:
frame number : gap-length : Ydiffpregap : Ydiffpostgap : marker
57 10 3.217846 10.803629 ==========
104 1 4.960470 4.838520 =
107 1 7.204895 4.491889 =
110 1 7.093846 4.452096 =
118 1 5.184397 5.302520 =
Where the "===" are a visual marker that helps to find faster long traces of duplicate frames in that list. In very long gaps the interpolation results may be bad.

When there are scene changes inside the gap, an interpolation of that gap makes no sense. They can be recognized by a great value of Ydiffn. therefore the script also writes another ConditionalReader file dups_post.txt which contains this value for each gap.

Code:
Type float
Default 0.0
57 10.803629
104 4.838520
107 4.491889
110 4.452096
118 5.302520

Last edited by sven_x; 2nd December 2011 at 12:06.
sven_x is offline   Reply With Quote
Old 2nd December 2011, 12:59   #28  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Mug Funky wrote a generic function that will replace a specified range of frames (of any length) by MVTools interpolation between the start and end points. See this post (and my comments following it).

@sven_x
Quote:
Originally Posted by sven_x View Post
Code:
...
ScriptClip("f1()")
ScriptClip("f3()")
ScriptClip("f4()")
...
ScriptClip("fg1a()")
ScriptClip("fg1b()")
... etc ...
You are invoking the run-time environment recursively here. There is no need for these function calls to be inside ScriptClip - they can be called directly, since FrameEvaluate is itself a run-time filter.

Also, none of the variables need to be global (as can be seen since you have global variables ydiffp and ydiffn, but you actually use variables called ydfp and ydfn in the script).
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 2nd December 2011 at 13:05.
Gavino is offline   Reply With Quote
Old 3rd December 2011, 15:29   #29  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
sven_x
.
See addited ZIP file...
There are some comments in Russian in AVS file.
There is NO anything check Code done.
Attached Files
File Type: zip 03-build_avi_1991_Programma_A_Delete_Bad_Frames p2.zip (4.3 KB, 29 views)
Jenyok is offline   Reply With Quote
Old 3rd December 2011, 21:44   #30  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by Jenyok View Post
See addited ZIP file...
Can you explain the purpose of the XXXBackFrames functions?
It seems to me, for example, that PairBackFrames(N) replaces frames N-2 and N-1 with new frames interpolated between N and N+3, which doesn't seem right.

Also, you should use Trim(0, -N) everywhere instead of Trim(0, N-1), which gives the wrong result for N=1 (as I explained in post #25).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 4th December 2011, 16:12   #31  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
Gavino
.
Thank you for your critic.
Please, write correct Code, how you think, in example of function TenBackFrames(clip clp, int N) .
See Code below.
Thankful in advance to you for your cooperation.
.
Code:
function TenBackFrames(clip clp, int N)
{
  # N is number of the last frame in Source that needs replacing. 
  # Frames N - 10 and N - 9 and N - 8 and N - 7 and N - 6  and N - 5 and N - 4 
  # and N - 3 and N - 2 and N - 1 (O) will be replaced.
	
  clp.trim(0, N - 11) ++ interTen1.trim(N, -1) ++ interTen2.trim(N, -1) ++ \
  interTen3.trim(N, -1) ++ interTen4.trim(N, -1) ++ interTen5.trim(N, -1) ++ \
  interTen6.trim(N, -1) ++ interTen7.trim(N, -1) ++ interTen8.trim(N, -1) ++  \
  interTen9.trim(N, -1) ++ interTen10.trim(N, -1) ++ clp.trim(N, 0)
}
Jenyok is offline   Reply With Quote
Old 4th December 2011, 16:41   #32  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
I don't understand the purpose of your 'Back' functions.
Is TenBackFrames(N) supposed to do the same thing as TenFrames(N-10)? If so, why not just use TenFrames instead?

If you really want two separate functions for convenience, just make TenBackFrames simply a call to TenFrames.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 14th December 2011, 14:42   #33  |  Link
2Bdecided
Registered User
 
Join Date: Dec 2002
Location: Yorkshire, UK
Posts: 1,673
What I would love is a generic function that lets me just list the bad frames, and returns a clip with those frames replaced with motion-interpolated versions.

If it works properly for frame number 1, and also for any number of consecutive bad frames, so much the better.

So, something like Badframeinter(1,5,6,7,1000,1001,1205). Option to just hand it a text file with frame numbers (one on each line) would be cool too.

Shall I ask Santa?

Seriously, I could hack to together myself, in the most inefficient way possible, but I would make all the mistakes described in this thread, and more.

Cheers,
David.
2Bdecided is offline   Reply With Quote
Old 14th December 2011, 14:57   #34  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by 2Bdecided View Post
What I would love is a generic function that lets me just list the bad frames, and returns a clip with those frames replaced with motion-interpolated versions.
I did this (restricted to replacing single frames) a while back:
http://forum.videohelp.com/threads/3...96#post2089696
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 14th December 2011, 14:58   #35  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,648
ClipClop() would be of assistance in developing something if Santa does not show up.

EDIT: Just saw that Gavino beat me to it, was meaning something pretty much the
same as in the Gavino link.

EDIT:, it is my intent to at some stage put up a collection of frame fix options and use ClipClop
to select the best particular option for a frame. Eg using Bi-directional predicton,
PredictFromPrevious, PredictFromNext and then using eg ClipClop Command file:

1 10 # replace frame 10 using Bidirectional prediction
2 20 # replace frame 20 using PredictFromPrevious
3 30 # replace frame 30 using PredictFromNext

Clip 0 would be the original clip, 1 bidir,2 fromPrev, 3 fromNext
Quite easy to knock it up yourself.

EDIT: You could also make a couple of replacement clips for eg CopyFromPrevious and CopyFromNext
just by shifting the frames over by 1 frame.
__________________
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 December 2011 at 18:21.
StainlessS is offline   Reply With Quote
Old 17th December 2011, 17:11   #36  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 648
And here is my Unipolator.
I decided to release it into the wild today, Santa is close and 2011 ran as hell.

Can do motion-based interpolation of 0-7 consequent missing frames in 0-52 places at once.
Especially designed for in-place repair of heavily damaged frames and/or recalculation and reinsertion of missing frames.

It is walkthrough-documented,
helps with tailored assertions to check against certain parameter violations
and has a nice switchable and resolution and widescreen-dependent overlay.

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.
--------------
Oops.
Quote:
The text that you have entered is too long (157793 characters). Please shorten it to 16000 characters long.
A .7z is coming soonish...


Maybe this post missed the thread, because Unipolator uses MFlowInter, not MVFlow.
I will open a new thread.

http://forum.doom9.org/showthread.php?p=1547405

This could help the attachment approval as well.
__________________
Die toten Augen von Friedrichshain: "Data reduction ? Yep, Sir. We're working on that issue. Synce invntoin uf lingöage..."
"To bypass shortcuts and find suffering"...no, it was somehow different...

Last edited by Emulgator; 27th December 2011 at 16:58.
Emulgator is offline   Reply With Quote
Old 18th December 2011, 17:26   #37  |  Link
Mounir
Registered User
 
Join Date: Nov 2006
Posts: 709
I am waiting for the approval to clear, upload to mediafire if you can
Mounir is offline   Reply With Quote
Old 20th December 2011, 21:24   #38  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,648
@Moderator, I hope that Emulgator's attachment can be approved soon, please,
and merry xmas to one & 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 ???
StainlessS is offline   Reply With Quote
Old 26th December 2011, 19:28   #39  |  Link
bizz & buzz
Registered User
 
Join Date: Jun 2008
Posts: 95
can someone please approve Emulgator's attachment?
bizz & buzz is offline   Reply With Quote
Old 27th December 2011, 11:02   #40  |  Link
Mounir
Registered User
 
Join Date: Nov 2006
Posts: 709
i co-sign its been 10 days and we're still waiting...
Mounir 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 01:43.


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