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. |
24th May 2013, 01:02 | #1 | Link |
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(). |
24th May 2013, 01:50 | #2 | Link |
HeartlessS Usurer
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) 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. |
24th May 2013, 17:14 | #5 | Link |
Registered User
Join Date: May 2011
Posts: 68
|
Thanks for the suggestions! I'll look into both and post back if I get stuck.
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. 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? |
24th May 2013, 20:50 | #6 | Link |
HeartlessS Usurer
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
__________________
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. |
25th May 2013, 20:39 | #7 | Link |
HeartlessS Usurer
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 ??? |
17th June 2013, 21:59 | #9 | Link |
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 } |
17th June 2013, 23:43 | #10 | Link |
HeartlessS Usurer
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 ??? |
Thread Tools | Search this Thread |
Display Modes | |
|
|