Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] How to play a video on a canvas?

edited September 2014 in OpenSesame

Hi all,

I have a fairly extensive inline script running the majority of my experiment. Basically, there are two images displayed on the screen and subjects have to select one (then other things happen, but they don't matter for this question).

Now, I want to have a video playing (on loop, at the top center) while the participants are making their selection. In other words, I need my stimuli (which participants click on) and the video to display simultaneously.

I've tried several pieces of code I found on these forums and others, but I'm not having any luck.

Any ideas? Do I need to display my stimuli on something other than a canvas?

from openexp.canvas import canvas
from openexp.mouse import mouse
import subprocess
import time
import random
import pygame

#create canvas
my_canvas = canvas(exp)

#name images
high_image = "green.png"
low_image = "stars.png"
high_image_path = exp.get_file(high_image)
low_image_path = exp.get_file(low_image)
movie = exp.get_file('rn-face.avi')

#draw images
high_pic=my_canvas.image(high_image_path, scale=.9, x=self.get('xHigh'), y=self.get('yHigh'))
low_pic=my_canvas.image(low_image_path, scale=0.55, x=self.get('xLow'), y=self.get('yLow'))

###I need the video to show some where###

my_canvas.show()

Comments

  • edited 9:26AM

    Hi,

    A canvas object is static, so there's no way to play video with it. Of course, you could present an animation by showing many canvases after another. But this is impractical for video playback.

    What back-end do you use? If you use the legacy back-end, you can quite easily present video using OpenCV. Some examples are here:

    This will give you a lot of control, because you can extract video frames and draw your own stuff on top of them, which seems exactly what you want to do. However, the limitations are that it doesn't (as easily) work with OpenGL-based back-ends (i.e. xpyriment and psycho), and doesn't support sound.

    Is that a useful solution for you?

    Cheers,
    Sebastiaan

Sign In or Register to comment.