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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th May 2013, 01:02   #1  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
Find specific solid color frames

I have clips that have a single green frame at frame 0, then the video. My issue is that frame 0 isn't at the start of the file....it might be 200 frames into the file.

Is there a way to have AVISynth automagically go find that green frame and report back the frame number? If so, I could write a script that would automatically align my clips without having to do it manually with Trim().
Aegwyn11 is offline   Reply With Quote
Old 24th May 2013, 01:50   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Not sure this should be in Development section but,

Write a function that scans first n frames using GScript and returns frame number+1 of found frame, or 0 (not found).

Code:
  z=fn(250)
  Trim(z,0)
There are a number of methods to find color of frame, eg

AverageLuma, AverageChomaU, AverageChomaV

ShowChannels,

RT_RgbChanAve from RT_Stats.

EDIT: Ignore above, color difference wanted not eg averageluma.
__________________
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; 24th May 2013 at 21:02.
StainlessS is offline   Reply With Quote
Old 24th May 2013, 09:16   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
You can use the FindFrame function from this post, or something similar derived from it.

(Since it pre-dates the release of GScript, it uses recursion instead.)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 24th May 2013, 13:36   #4  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
Quote:
Originally Posted by Aegwyn11 View Post
My issue is that frame 0 isn't at the start of the file....it might be 200 frames into the file.
What do you mean by this?
wonkey_monkey is offline   Reply With Quote
Old 24th May 2013, 17:14   #5  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
Thanks for the suggestions! I'll look into both and post back if I get stuck.

Quote:
Originally Posted by StainlessS View Post
Not sure this should be in Development section but,
You're right! I goofed when I made the post...it should be in the usage forum. Mods: please move this if you can. Thanks.


Quote:
Originally Posted by davidhorman View Post
What do you mean by this?
Imagine you have a source that has green frames at the beginning prior to the content. Now imagine that source playing out in a linear, real time fashion, looping when it gets to the end of the file. Now imagine that feeding a real time encoder, where the output is being captured for analysis/evaluation. The green frames would be at frame 0 of the source, but would be somewhere else in the output capture (unless your timing was REALLY good!).

Make sense?
Aegwyn11 is offline   Reply With Quote
Old 24th May 2013, 20:50   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Ignore what I said earlier, you would want to use color difference rather than eg averageluma, as suggested in Gavino link.

Here, something I just knocked up, not much testing. If not to your liking, then maybe take parts of it and
integrate into Gavino FindFrame.

Anyway, here tis:
Code:
Import("LocateFrames.avs") # Included in RT_Stats zip
# Based on FindFrame() (c) Gavino:   http://forum.doom9.org/showthread.php?p=1569622#post1569622
# Required: GScript    (c) Gavino:   http://forum.doom9.org/showthread.php?t=147846
# Required: RT_Stats   (c) StainlesS:http://forum.doom9.org/showthread.php?t=165479
# ---------------------------------------------------------------------------------
# Testclip, Replace 10 Green frames at frames 100 to 109
ColorBars().ConvertToYV12().ShowFrameNumber()
G=Last.BlankClip(Length=10,color=$00FF00)
Last=Trim(0,99) ++ G ++ Trim(110,-(1000-110))

Function SkipGreen(clip c,float "th",int "frames",int "R",int "G",int "B",bool "LastGreen") {
# Supply args OR change defaults (easier)
# Should supply non zero th OR change SkipGreen default.
    c
    th=Float(Default(th,0.0)) # 0.0==Search for 1st exact match or best possible if no exact match found]. Threshold for declaring match (diff <= Thresh).
    frames=Default(frames,250)      # Frames count to search
    R=Default(R,0)        G=Default(G,$FF)     B=Default(B,0)
    LastGreen=Default(LastGreen,false)
    Assert(R>=0 && R<=255 && G>=0 && G<=255 && B>=0 && B<=255,"SkipGreen: Bad color")
    Dclip=Trim(0,-frames)
    DClip = (!LastGreen) ? DClip : DClip.Reverse
    Green=c.BlankClip(Length=1,color=(R*256+G)*256+B)
#   Return Green
    s=DClip.LocateFrames(Green,thresh=th,Chroma=True)
    Eval(s)
    Start = (LF_MATCH>=2) ? ((!LastGreen)?LF_FOUND:frames-1-LF_FOUND) + 1 : 0
#   RT_Debug("SkipGreen:","Trim(" + String(Start) + ",0)")
    Trim(Start,0)
#    Subtitle("Frame="+String(Start),Last_frame=0)
    Return Last
}

# These will search for EXACT match only, set th non zero
return SkipGreen(LastGreen=False)   # Should trim @ 101, ie second green frame
return SkipGreen(LastGreen=True)    # Should trim @ 110, ie frame after last green frame
EDITED: Change to RGB specification, Added LastGreen to find last +1 where multiple green frames.
__________________
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; 25th May 2013 at 20:37.
StainlessS is offline   Reply With Quote
Old 25th May 2013, 20:39   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Previous post updated script.
__________________
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 28th May 2013, 16:00   #8  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
That is fantastic. Very nifty...this is going to make my life much much easier.

Thanks StainlessS and Gavino!!
Aegwyn11 is offline   Reply With Quote
Old 17th June 2013, 21:59   #9  |  Link
Aegwyn11
Registered User
 
Join Date: May 2011
Posts: 68
Thanks again for the awesome script. I modified it slightly to allow for use of pixel types other than YV12 (without altering the input clip pixel type).

Code:
Import("LocateFrames.avs") # Included in RT_Stats zip
# Based on FindFrame() (c) Gavino:   http://forum.doom9.org/showthread.php?p=1569622#post1569622
# Required: GScript    (c) Gavino:   http://forum.doom9.org/showthread.php?t=147846
# Required: RT_Stats   (c) StainlesS:http://forum.doom9.org/showthread.php?t=165479
# ---------------------------------------------------------------------------------
# Modified by Aegwyn11 - 6/17/2013 - Enabled so that any pixel type will work, not just YV12

Function SkipGreen(clip c,float "th",int "frames",int "R",int "G",int "B",bool "LastGreen") {
# Supply args OR change defaults (easier)
# Should supply non zero th OR change SkipGreen default.
    c
    th=Float(Default(th,0.0)) # 0.0==Search for 1st exact match or best possible if no exact match found]. Threshold 

for declaring match (diff <= Thresh).
    frames=Default(frames,250)      # Frames count to search
    R=Default(R,0)        G=Default(G,$FF)     B=Default(B,0)
    LastGreen=Default(LastGreen,false)
    Assert(R>=0 && R<=255 && G>=0 && G<=255 && B>=0 && B<=255,"SkipGreen: Bad color")
    Dclip=Trim(0,-frames)
    DClip = (!LastGreen) ? DClip : DClip.Reverse
    Green=c.BlankClip(Length=1,color=(R*256+G)*256+B,pixel_type="YV12")
#   Return Green
    s=DClip.ConvertToYV12().LocateFrames(Green,thresh=th,Chroma=True)
    Eval(s)
    Start = (LF_MATCH>=2) ? ((!LastGreen)?LF_FOUND:frames-1-LF_FOUND) + 1 : 0
#   RT_Debug("SkipGreen:","Trim(" + String(Start) + ",0)")
    Trim(Start,0)
#    Subtitle("Frame="+String(Start),Last_frame=0)
    Return Last
}
Aegwyn11 is offline   Reply With Quote
Old 17th June 2013, 23:43   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Nice.
__________________
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
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 09:24.


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