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 3rd March 2009, 05:44   #1  |  Link
carrot691
Registered User
 
Join Date: Apr 2008
Posts: 3
Getting results from compare

I am trying to find a frame that match an other video using compare(). The problem seems to be that the returned value of compare is a frame, but I would need value...

Ex :
psnr = compare(video, frame)
if psnr > 40 then "I don't know yet".

This is the be able to align to video on the same frame without having to do it manually.

Maybe I'm just on the wrong track, any pointers would help. Thanks.
carrot691 is offline   Reply With Quote
Old 8th March 2009, 18:24   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,418
I'm not aware of a function that returns the PSNR. However, here's a way of doing basically what you ask:
Code:
# given a clip 'c' and a (potentially one-frame) clip 'f',
# show 'c' starting at frame matching (1st frame of) 'f'.
function findFrame(clip c, clip f, int "thresh") {
  thresh = Default(thresh, 2) # threshold for declaring match
  f = f.Loop(c.FrameCount, 0, 0)
  n = findFrame2(c, f, thresh, 0)
  return c.Trim(n, 0)
}

# recursive auxiliary function called by findFrame
function findFrame2(clip c, clip f, int thresh, int current_frame) {
  current_frame >= c.FrameCount-1 || LumaDifference(c, f) <= thresh ?
\   current_frame :
\   findFrame2(c, f, thresh, current_frame+1)
}

# contrived example for testing:
c = AviSource("myVid.avi").ShowFrameNumber()
f = c.Trim(30, -1) #select frame 30

findFrame(c, f) # should show starting at frame 30
It uses LumaDifference to detect matching frames (use RGBDifference if you have RGB).
The threshold parameter can be amended to suit how close a match you have or require.
If no match is found, the last frame will be shown.
Gavino 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 23:51.


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