How to recognize if a video feed is frozen.

Asked by squaremind

Hello there.
I would like to ask how can i make Sikuli recognize if a video feed is frozen. I am basic level programmer and i am trying to develop a script that interacts with a internet application that has a video feed, and I want Sikuli to restart this application when the video freezes. I thought about making it observe the video region, but none of the commands available with observe solves this, because I am not looking for a change or an appearance or a vanishment, but just if two images are the same after a period of time. Maybe I should take screenshots at 2 different times and compare them? Can you make an example of how can i do this if it is possible?
Thank you in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Interesting challenge.

--- Your idea taking screenshots and compare:
(made on a Mac, playing a video on my MobileMe gallery,
Webpage is opened and video ready to start)

switchApp("Safari")
vid = selectRegion() # select video region
switchApp("Safari")
type(" "); wait(1) # start video play
while True:
    vidImg1 = capture(vid) # capture 1
    wait(3) # waiting time between captures
    vidImg2 = capture(vid) # capture 2

    comp = Finder(vidImg1) # compare base
    comp.find(Pattern(vidImg2).similar(0.99)) # compare
    found = comp.hasNext()
    comp.destroy()
    if not found:
       print "running"
    else:
       print "frozen"
       break

this continually prints "running" as long as the video plays. When I hit space bar to pause, script stops and prints frozen.

Now you have to adapt this to your situation and add the internet application handling framework.

Revision history for this message
squaremind (rzorzut) said :
#2

Thank you Mr.Raiman... This solves the issue...
But to complete my program i need another advice: i need to do this check only about every 1-2 minutes... so i need to run other instructions
once i have taken the first frame. Then the wait function causes me some problems. I think I can replace the wait function with other blocks of the program... I will let you know.

Revision history for this message
squaremind (rzorzut) said :
#3

Thanks RaiMan, that solved my question.