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.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Display Modes
Old 25th November 2015, 23:13   #1  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
Gavino's: Delete frames satisfying user-defined condition

Hello,

http://forum.doom9.org/showthread.php?t=163107

This works so very well but I would like it to delete the original as well as the duplicate (don't ask!). Is that possible?
Thanks.
Floatingshed is offline   Reply With Quote
Old 26th November 2015, 02:06   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,418
Can you be more specific in requirement,
you want to delete START (where START is frame before 1st dupe) and 1st dupe only, or START + ALL following dupes ?
EDIT: Ignore Above, its rubbish

EDIT: NOTE, potential problem in linked script function is that it only compares dupes with the previous frame,
and not with the START frame, so could delete low motion sequences.

You could try this, (untested), deletes START + all dupes not just first.
Code:
DeleteFrames("YDifferenceToNext < 0.1 && current_frame < fc-1")
EDIT: Above does not remove final dupe
__________________
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; 26th November 2015 at 08:38.
StainlessS is offline   Reply With Quote
Old 26th November 2015, 08:29   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,418
I guess above question was a bit stupid , you would end up deleting multiple pairs of dupes if not deleting all dupes in run.

How bout this

Code:
Function DeleteCompleteDupeRun(clip c,float "th",Bool "Debug") {
    # Delete dupe START frame plus all following dupes.
    # Dupes compared with run START frame rather than DupeFrame-1
    # Req RT_Stats + GSCript.
    myName="DeleteCompleteDupeRun: "
    c    
    th=Float(Default(th,0.1))       Debug=Default(Debug,False)
    res = BlankClip(c,   length=0)
    fc  = FrameCount()   fmx=fc-1
    GSCript("""
        n = 0             
        while(n < fc) {
            DelS=n
            while(n<fmx && RT_LumaDifference(Last,Last,n=DelS,n2=n+1) < th) {           # YDifference To run START frame
                n = n + 1
            }
            if(n>DelS) {
                (Debug)?RT_DebugF("Deleting %d to %d",DelS,n,name=myName):NOP
                n = n + 1   # Point @ start keep frame
            }
            if(n < fc) {  # not at end
                KeepS = n # start of wanted section
                while((n<fmx && RT_YDifference(Last,n=n,delta=1) >= th) || n==fmx) {    # YDifferenceToNext
                    n = n + 1
                }
                (Debug)?RT_DebugF("Keeping  %d to %d",KeepS,n-1,name=myName):NOP
                res = res + Trim(KeepS, KeepS-n)
            }
        }    
    """)
    return res
}

ColorBars.ConvertToYV12.Killaudio

A=Trim(0,-1)
B=A.FlipHorizontal
C=A.Flipvertical
A=A.Subtitle("A")
B=B.Subtitle("B")
C=C.Subtitle("C")

#A+A                                               # Del  0-1                                == No Frames 
#A+B                                               # Keep 0-1                                == AB 
#A+B+C+ A+A+A +B+C+A                               # keep 0-2, Del 3-5, keep 6-8             == ABCBCA  
#A+B+C+ A+A+A +B+C+C                               # keep 0-2, Del 3-5, keep 6, Del 7-8      == ABCB 
A+B+C+ A+A+A +B                                    # keep 0-2, Del 3-5, keep 6               == ABCB 

DeleteCompleteDupeRun(0.1,Debug=True)
Only tested with above demo tests
__________________
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 November 2015, 09:02   #4  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
Works perfectly on my test clip. Many, many thanks.
Floatingshed is offline   Reply With Quote
Old 26th November 2015, 16:48   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,442
Quote:
Originally Posted by Floatingshed View Post
Hello,

http://forum.doom9.org/showthread.php?t=163107

This works so very well but I would like it to delete the original as well as the duplicate (don't ask!). Is that possible?
Thanks.
StainlessS's dedicated solution looks right (though I haven't tried it in practice).
I think it can also be done using my original generic DeleteFrames function by extending the supplied condition to be:
Code:
DeleteFrames("(YDifferenceFromPrevious < 0.1 && current_frame > 0) 
        \  || (YDifferenceToNext < 0.1 && current_frame < fc-1)")
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 26th November 2015 at 19:48. Reason: fixed errors - thanks, raffriff42
Gavino is offline   Reply With Quote
Old 26th November 2015, 18:31   #6  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
Sorry, don't understand the: ¦¦
Neither does the filter!
Thanks.
Floatingshed is offline   Reply With Quote
Old 26th November 2015, 18:38   #7  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,442
Quote:
Originally Posted by Floatingshed View Post
Sorry, don't understand the: ¦¦
Neither does the filter!
Thanks.
Sorry, I meant to use || not ¦¦.
Edited the earlier post to fix.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th November 2015, 19:00   #8  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
Thanks for the update but I still get syntax error. AVSP highlights the final ")" but that can be misleading...
Floatingshed is offline   Reply With Quote
Old 26th November 2015, 19:21   #9  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,371
DeleteFrames("(YDifferenceFromPrevious < 0.1 && current_frame > 0)
\ || (YDifferenceToNext < 0.1 && current_frame < fc-1)")
raffriff42 is offline   Reply With Quote
Old 26th November 2015, 19:47   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,442
Quote:
Originally Posted by raffriff42 View Post
DeleteFrames("(YDifferenceFromPrevious < 0.1 && current_frame > 0)
\ || (YDifferenceToNext < 0.1 && current_frame < fc-1)")
Thanks raffriff.
Should have tested it - I must be getting rusty.
Original post edited (again!)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th November 2015, 19:51   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,418
Quote:
Originally Posted by Gavino View Post
I think it can also be done using my original generic DeleteFrames function by extending the supplied condition to be:
Code:
DeleteFrames("(YDifferenceFromPrevious < 0.1 && current_frame > 0) 
        \  || (YDifferenceToNext < 0.1 && current_frame < fc-1)")
Now that would have saved me some work, had I thought of it.

EDIT: With long run of (EDIT: Localized) low motion, my version might output eg
ddkddkddkddkddk instead of (d=del, k=keep)
ddddddddddddddd

due to comparisons with START frame rather than DupeFrame-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; 26th November 2015 at 20:23.
StainlessS is offline   Reply With Quote
Old 26th November 2015, 22:24   #12  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
Now I'm finding that on regular occasions I need to delete yet another frame.

My clip has some nasty blending (Kinescope with phase errors) at scene changes: A, A/B, B/A, damaged B, B.
If I run John Meyers' scene change detection script I get: A, A, A, damaged B, B.
Then after Stainless/Gavino's script: A, damaged B, B.
So, does anyone have any idea for removing "damaged B"? TBH its all a bit above me, I don't know how Gavino's script does what it does. Wish I had a brain!
Thanks for all the help.
Floatingshed is offline   Reply With Quote
Old 26th November 2015, 22:43   #13  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,371
You need to define 'damaged' in Avisynth terms...

Does 'Kinescope with phase errors' mean the colors are wonky? Then try
Code:
DeleteFrames("(YDifferenceFromPrevious < 0.1 && current_frame > 0)
\ || (YDifferenceToNext < 0.1 && current_frame < fc-1)"
\ || (UDifferenceToNext > 42 && current_frame < fc-1)")
http://avisynth.nl/index.php/UDiffer...time_functions
- YDifferenceToNext tests luminance (brightness)
- UDifferenceToNext tests color on the blue-yellow axis
- VDifferenceToNext tests color on the red-green axis

Threshold level "42" was chosen at random. Try different values.

EDIT thx StainlessS, please remove the red quote.

Last edited by raffriff42; 26th November 2015 at 23:15.
raffriff42 is offline   Reply With Quote
Old 26th November 2015, 23:03   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,418
RaffRiff, you got too many quotes in there ? (middle line)

Not related to previous Floatingshed post, here func for deleting dupes not-including START of run (just duplicates),
Dupes compared with inital START of run frame rather than DupeFrame-1.

Code:
Function DeleteDupRun(clip c,float "th",Bool "Debug") {
    # Delete all dupes (leaving initial START frame [of which dupes are a copy]).
    # Dupes compared with run START frame rather than DupeFrame-1
    # Req RT_Stats + GSCript.
    myName="DeleteDupRun: "
    c    
    th=Float(Default(th,0.1))       Debug=Default(Debug,False)
    res = BlankClip(c,   length=0)
    fc  = FrameCount()   fmx=fc-1
    GSCript("""
        n = 0             
        while(n < fc) {
            DupS=n                                                                  # n - 1 is START (if n != 0)
            while(n<fc && n>0 && RT_LumaDifference(Last,Last,n=DupS-1,n2=n) < th) {
                n = n + 1
            }            
            if(DupS<n) { # DupS < n if we are deleting some
                (Debug)?RT_DebugF("Deleting %d to %d",DupS,n-1,name=myName):NOP
            }
            if(n < fc) {  # not at end 
                KeepS = n # start of wanted section
                n = n + 1
                while(n<fc && RT_YDifference(Last,n=n,delta= -1) >= th) {           # YDifference From Previous
                    n = n + 1
                }
                # Exit here with n == Dupe Seq START frame + 1 (or fc)
                (Debug)?RT_DebugF("Keeping  %d to %d",KeepS,n-1,name=myName):NOP
                res = res + Trim(KeepS, KeepS-n)
            }
        }    
    """)
    return res
}

ColorBars.ConvertToYV12.Killaudio

A=Trim(0,-1)
B=A.FlipHorizontal
C=A.Flipvertical
A=A.Subtitle("A")
B=B.Subtitle("B")
C=C.Subtitle("C")

#A+A                                               # Keep 0-0, Del 1-1                       == A 
#A+B                                               # Keep 0-1                                == AB 
#A+B+C+ A+A+A +B+C+A                               # keep 0-3, Del 4-5, keep 6-8             == ABCABCA  
#A+B+C+ A+A+A +B+C+C                               # keep 0-3, Del 4-5, keep 6-7, Del 8      == ABCABC 
A+B+C+ A+A+A +B                                   # keep 0-3, Del 4-5, keep 6               == ABCAB 

DeleteDupRun(0.1,Debug=True)
Again, only tested with included DEMO tests.

EDIT:
Quote:
Threshold level "42" was chosen at random. Try different values.
Nah, I'm guessin that its because that number is "The meaning of, Life, the Universe, and Everything", and
also because its part of RaffRiff42's moniker. (random my foot).

EDIT:
From Below post,
Quote:
Nothing is random. Nothing.
I'll take that as a confession of guilt

EDIT:
42, Life, the Universe, and Everything:- http://www.independent.co.uk/life-st...g-2205734.html
https://www.youtube.com/watch?v=aboZctrHfK8
http://www.theguardian.com/books/201...-42-hitchhiker

EDIT: The Movie, (The Hitch Hiker's Guide To The Galaxy) is quite naff compared to original TV series or even the World Service
radio broadcasts. (I've got both TV series and Movie on DVD, only had the stomach to watch the movie about twice,
like many/most US backed re-makes of British classics, result is garbage, US producers seem to presume that their audience is stupid)
EDIT: The YouTube clip linked above, is the naff Movie version.
__________________
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; 29th November 2015 at 15:35.
StainlessS is offline   Reply With Quote
Old 26th November 2015, 23:16   #15  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,371
Nothing is random. Nothing.


EDIT I'm not sure what that statement means. I just typed it "at random."

Last edited by raffriff42; 26th November 2015 at 23:49.
raffriff42 is offline   Reply With Quote
Old 26th November 2015, 23:51   #16  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
'Kinescope with phase errors'.. is not a colour problem, the footage is B&W.
Phase errors in this case refers to the alignment of the tv fields with the film frames. A situation where a single frame of film can contain field B of a tv frame blended with field A of the next.

Here is an example, not one of the worst by any means.

https://www.mediafire.com/?p85f5sar45autrw

Last edited by Floatingshed; 26th November 2015 at 23:54.
Floatingshed is offline   Reply With Quote
Old 27th November 2015, 00:23   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,418
FloatingShed, cant you just eg convert toYV24/YUY2, AssumeTFF/AssumeBFF, SeparateFields, delete first field, weave, to match up like fields.

...

Having looked at Exotic Interlacing by ScharfisBrain see below (See Mediafire in my sig, DATA folder for Exotic Interlacing in English),

Quote:
Imitation in AviSynth: (creating problem)
Code:
AVISource("24fpsFilm.avi")
AssumeFPS(25, true).DoubleWeave().SelectOdd()
This kind of the Telecine is called phase shifted or sometimes also as Perverse Telecine and can be repaired by AVISynth quite simply, by sorting the fields again:

Recovery in AviSynth:

Code:
DoubleWeave().SelectOdd()
EDIT: I think at least one of the field matching plugins should be able to fix Phase Shifted fields that do not stay in sequence (TFM or whatever).
__________________
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; 27th November 2015 at 00:39.
StainlessS is offline   Reply With Quote
Old 27th November 2015, 00:36   #18  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
No, you misunderstand. This is a kinescope/Telerecording/Film-recording. Made, in essence, by pointing a film camera at a tv monitor.
The field/frame matching errors are burned into the film frames.
Floatingshed is offline   Reply With Quote
Old 27th November 2015, 02:00   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,418
FS, you got a bit bigger sample, ~30MB please (audio not necessary).

EDIT: With a few of scene cuts.
__________________
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 27th November 2015, 02:19   #20  |  Link
Floatingshed
Registered User
 
Join Date: Nov 2008
Posts: 327
Ok. Will sort tomorrow. Thanks.
Floatingshed is offline   Reply With Quote
Reply

Thread Tools
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 22:17.


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