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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 23rd April 2012, 00:10   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
MatchFrames/LocateFrames v1.06

MatchFrames, intended for matched frames extraction,
LocateFrames, intended to be usable by other scripts to identify matches.

MatchFrames()

Find And return frames in c clip that are best matched to frames in f clip.

Below a mod of Gavino's FindFrame, Advantages:-

Deals with a clip of frames to find rather than a single frame.
Can find exact/best match or 1st match below or equal to a threshold (rather than last frame if <= Thresh not found).
Extra Paranoia setting continues searching subsequent frames for a better match once thresh is broken.
Float Threshold.
Can show StackHorizontal required 'find' frame alongside source clip 'found' frames.
Can output a command file consisting of frame numbers found.
Command file can be used with FrameSelect() Plugin to select all found frames (useful if viewing StackHorizontal frames without 2nd SLOW run for extraction).

Originally prompted by this thread:
http://forum.doom9.org/showthread.php?t=164662

Code:
v1.02 
  Outputs LogFile
  Can cut down on search times if clip f is known to be time ordered (in c).
v1.03
  Added "(Thresh2)" Indicator to log.
v1.04
 Added Args, "Start", "Stop", "XP".
v1.05
 Added Args, "Chroma", "ChromaWeight", "Title", Added Debug Mode.
v1.06
 Debug mode now holds TotalDiff as two floats providing greater precision.
Code:
############################################################################
# MatchFrames v1.06, by StainlessS:
#
# Find And return frames in c clip that are best matched to frames in f clip.
# Requires YV12, as uses LumaDifference(). Null Audio returned.
# ##################################
# 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
# ##################################
#
# MatchFrames(clip c,clip f,bool "Show",float "Thresh",float "Thresh2",string "FileName",string "LogFile", \
#               int "Start",int "Stop",bool "XP",Bool "Chroma",Float "ChromaWeight",string "Title")
#
# Args:
#
# c       = clip, Source clip.
# f       = clip, Consisting of frames that you wish to find in the c clip.
# Show    = bool[true], True returns both find and found frames using StackHorizontal. NOTE, hires clips, may cause problems in eg VDUB
#                if StackHorizontal width goes over some VD imposed limit.
# Thresh  = float[0.0 == Search for 1st exact match or best possible if no exact match found]. Threshold for declaring match (diff <= Thresh).
# Thresh2 = float[0.0 == NOT time ordered]. Both a 'time ordered' indicator and a threshold.
#           If (Thresh < Thresh2) Then clip f is taken as time ordered (in c), ie frames in both f and c clips are temporally ordered.
#           If f clip is known to be time ordered (in c), this arg can significantly cut down on the time taken to search for frames.
#
#           Assuming time ordered f clip (Thresh < Thresh2),
#
#               If a match found where diff of find to found frame <= Thresh,
#                    Next frame search will start from found frame + 1.
#               Else if diff of find to Full Scan BEST found frame < Thresh2
#                    Next frame search will start from BEST found frame + 1.
#               Else
#                    Next frame search will start from current start position.
#               End if                    
#               *** Where above 'Full Scan' means scan from current start postion to the last valid search frame.
#                
# FileName= string["MatchFramesCmd.txt"], Output Frames command file.
#             Can use FrameSelect() Plugin to select frames using MatchFramesCmd.txt Command file.
#             FrameSelect() Plugin can be found here:- http://forum.doom9.org/showthread.php?t=164497
#             Can monitor the MatchFramesCmd.txt file during scanning to view progress (ie view in notepad, [Read-Only viewer maybe safer]).
#
# LogFile = string["MatchFrames.Log"], Output Log file. Can monitor as for command file.
#             The Logfile might produce an output line like that below:
#
#             "0]=[1100] Diff=0.239 (T1:XP) S=1000 E =1101 XPCNT=5"
#
#             Where eg 0] is find frame number, [1100] is found frame, 
#             Diff is the Difference (Luma + optional Chroma) between find and found frames.
#             S and E are the search start and end positions that were searched for that frame.
#             The "(T1:XP)" stuff presents just a little info about the search:
#              "(BM:  )" Best Match, where no frame was found with a Diff <= Thresh, the returned frame was best match found in search area.
#              "(BM:T2)" Same as "(BM:  )" but was an Ordered search & because Diff<Thresh2, then next frame search will start at Best Match+1.
#              "(T1:  )" Means that the found frame had a Diff <= Thresh.
#              "(T1:XP)" Same as "(T1:  )" but Xtra Paranoia (XP) successfully found a better matching frame following the one that
#              initially broke thresh. If this flag is shown, you will also see "XPCNT" which will tell how many successive better frames 
#              were found after the initial frame that broke Thresh.
#
# Start   = int[0, == First frame of clip], Start frame to search from (eg Skip introduction).
# Stop    = int[0, == Last frame of clip + 1], Frame prior to which, c clip is searched (Exclusive). (eg Skip end credits).
# XP      = bool[true == Extra Paranoid] Main purpose of XP is so that you can use Thresh > 0.0 even if you dont fully trust a non best search.
#               If diff of find to found frame <= Thresh, then search would normally stop at that frame, but when
#               XP is true (Default), it will continue to search so long as subsequent frames provide a better match. Will usually result
#               in 1 extra frame being compared (providing that your Thresh is not too high).
#               If Thresh is set to 0.0 (default) then will only stop search on EXACT match, and so is likely to do a full search
#               (unless exact frame exists). XP allows you to settle for a close match by setting thresh a little above 0.0, and when a close
#               match is found, it will continue to edge forward 1 frame at a time until matches cease to be better.
#               If exact match was found, ie diff == 0.0 then will not scan extra frames (no better match possible).
#
# Chroma   = bool[false==Luma diff Only], If true then also uses chroma difference as per ChromaWeight.
# ChromaWeight=float[1.0/3.0 ie 0.33333], default for now, may change. If Chroma==true then LumaWeight = 1.0-ChromaWeight.
#               If Chroma==false then ChromaWeight is ignored and only luma difference is used.
# Title    = string[""== none], Allows you to place a string of text in the Log and Command file headers, eg "Hires Test#2" or whatever.
# ##################################
# DEBUG MODE: If the f FrameCount and c[START,STOP] FrameCount (ie STOP-START) are same AND Thresh < Thresh2 (ie Ordered), then the script is put
# into DEBUG mode. This would be easiest achieved when START and STOP are at their default 0 values meaning 'All of c clip' and lengths of
# f and c are same.
# In Debug Mode, there is no searching for best match, log is produced with difference between all corresponding frames
# and in the footer of the log, it will show Average Diff, Min Diff, and Max Diff for the entire frame set.
# In DEBUG mode, the command file is cleared, prints header only.
# ##################################
# 
# Will take some time to show results, it is not a bug if it seems to hang, it is WORKING HARD.
#
############################################################################
#
Suggested settings, Thresh=1.0, (if ordered clips then Thresh2=Thresh+0.1) but of course depends on f clip quality.
And always leave XP default.
If you have a lot of frames to find, might like to do a dummy run on only the first find frame and note what the difference
is, then repeat full scan with eg Thresh = Diff *1.25 (maybe 1.5) and Thresh2 = Thresh + 0.1 (assuming ordered clips).

As Script overflowed D9 16kb limit, have had to move posts around and the current script is in next post.

For Sister script LocateFrames(), see here:- http://forum.doom9.org/showthread.ph...61#post1600961

MatchFrames & LocateFrames in single zip, also available via MediaFire in Sig.
__________________
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; 18th November 2012 at 18:49. Reason: Update
StainlessS is offline   Reply With Quote
 

Tags
find, findframe, frame, search

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 19:17.


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