Log in

View Full Version : Automated frame comparsion - how?


moviefan
15th August 2008, 11:34
Hi guys,

I need a program that is able to compare a single frame (e.g. PNG-picture) with a video clip and calculate a similarity factor so that I can automatically identify the frame number of the matching frame in the clip. Does anybody know a software that can do this?

Regards

Zwitterion
15th August 2008, 13:03
AviSynth will do that:

a=AviSource("test.avi")
b=ImageSource("test.png", end=500)

Compare(a.ConvertToYV12(),b.ConvertToYV12(), logfile="test.txt")

Replace '500' with the framecount of your test clip.
In the resulting test.txt just look for the biggest PSNR value.

moviefan
15th August 2008, 14:23
Amazing! I will try it!

Edit: I tried it out, but first thing: YV12 seems not to be allowed... second: the logfile has been created, but it is empty... How do I start the script? I loaded it into VirtualDub...

Edit2: Solved... I run the Video Analysis Pass in VirtualDub :) Thanks for help Zwitterion, this saves a huge amount of work!

Edit3: Now I need to compare about 150 different frames of a video of around 2 hours length. My idea to do it would be the following:


vid1 = MPEG2Source(...) #length: 186628 frames
vid2 = MPEG2Source(...)

frame_00070 = vid2.trim( 70, 70).Loop(186628)
frame_00165 = vid2.trim( 165, 165).Loop(186628)
frame_00245 = vid2.trim( 245, 245).Loop(186628)
...

r = Compare(vid1, frame_00070, "", "00070.txt")
r = Compare(vid1, frame_00165, "", "00165.txt").overlay(r)
r = Compare(vid1, frame_00245, "", "00245.txt").overlay(r)

return r


But this method is very slow and doesn't work at all on my computer for all 150... If I divide them up into two parts, it works at about 1 fps... Is there another way to do that?

Zwitterion
16th August 2008, 14:29
Try this:
vid1 = MPEG2Source(...) #length: 186628 frames
vid2 = MPEG2Source(...)

frame_00070 = vid2.trim( 70, 70).Loop(186628)
frame_00165 = vid2.trim( 165, 165).Loop(186628)
frame_00245 = vid2.trim( 245, 245).Loop(186628)
...

r = Compare(Compare(Compare(vid1, frame_00070, "", "00070.txt"), frame_00165, "", "00165.txt"), frame_00245, "", "00245.txt")

return r
i.e. delete all overlay(), then cut the first line and paste it into the 'vid1' of the second line. Then cut that line and paste it into the 'vid1' of the third line, and so on...
This should improve speed and memory usage. I don't know about AviSynth's maximum line length, though.

reepa
16th August 2008, 14:38
You could also try MSU Video Quality Measurement Tool from http://www.compression.ru/video/quality_measure/video_measurement_tool_en.html

I've used it in the past and it's easy to use and works. You can produce frame by frame graphs by exporting the comparison data as csv and importing it into a spreadsheet app. From the graph you can identify the most similar frame.

Gavino
16th August 2008, 16:44
...
r = Compare(Compare(Compare(vid1, frame_00070, "", "00070.txt"), frame_00165, "", "00165.txt"), frame_00245, "", "00245.txt")
return r

Completely equivalent, and easier to read and write, is
Compare(vid1, frame_00070, "", "00070.txt")
Compare(frame_00165, "", "00165.txt")
Compare(frame_00245, "", "00245.txt")