Video Playback: Difference between revisions
Jump to navigation
Jump to search
| Line 121: | Line 121: | ||
This is an example of a Python script that plays a .mp4 video file with high time accuracy. <syntaxhighlight lang="python" line> from psychopy import visual, core, prefs prefs.hardware['videoLib'] = ['avbin', 'ffpyplayer'] # Choose based on installed libraries | This is an example of a Python script that plays a .mp4 video file with high time accuracy. <syntaxhighlight lang="python" line> from psychopy import visual, core, prefs prefs.hardware['videoLib'] = ['avbin', 'ffpyplayer'] # Choose based on installed libraries | ||
#!/usr/bin/env python3.10 | |||
# -*- coding: utf-8 -*- | |||
import time | |||
import keyboard | |||
from psychopy import visual | |||
from psychopy import core | |||
## Setup Section | |||
win = visual.Window([720,720], fullscr=False, monitor="testMonitor", units='cm') | |||
# append this stimulus to the list of prepared stimuli | |||
vlc_movies = [] | |||
my_movies = ['YourMovie.mp4']#path to your movies from this directory | |||
for movie in my_movies: | |||
win. | mov = visual.VlcMovieStim(win, movie, | ||
size=600, # set as `None` to use the native video size | |||
pos=[0, 0], # pos specifies the /center/ of the movie stim location | |||
flipVert=False, # flip the video picture vertically | |||
flipHoriz=False, # flip the video picture horizontally | |||
loop=False, # replay the video when it reaches the end | |||
autoStart=True) # start the video automatically when first drawn | |||
vlc_movies.append(mov) | |||
print("playing video....") | |||
while not(keyboard.is_pressed('q')) and vlc_movies[0].status != visual.FINISHED: | |||
vlc_movies[0].draw() | |||
win.flip() | |||
buffer_in = vlc_movies[0].frameIndex | |||
print(vlc_movies[0].status) | |||
print("Stop") | |||
## Closing Section | |||
core.quit() | |||
</syntaxhighlight> | |||