def _setup(self, exp_win): if self._fixations_duration > 0: from ..shared.eyetracking import fixation_dot self.fixation_dot = fixation_dot(exp_win) self.movie_stim = visual.MovieStim2(exp_win, self.filepath, units="pix") # print(self.movie_stim._audioStream.__class__) aspect_ratio = (self._aspect_ratio or self.movie_stim.size[0] / self.movie_stim.size[1]) min_ratio = min( exp_win.size[0] / self.movie_stim.size[0], exp_win.size[1] / self.movie_stim.size[0] * aspect_ratio, ) width = min_ratio * self.movie_stim.size[0] height = min_ratio * self.movie_stim.size[0] / aspect_ratio if self._scaling is not None: width *= self._scaling height *= self._scaling self.movie_stim.size = (width, height) self.duration = self.movie_stim.duration # print(self.movie_stim.size) # print(self.movie_stim.duration) super()._setup(exp_win)
def _setup(self, exp_win): self.movie_stim = visual.MovieStim2(exp_win, self.filepath, units="pixels") # print(self.movie_stim._audioStream.__class__) aspect_ratio = (self._aspect_ratio or self.movie_stim.size[0] / self.movie_stim.size[1]) min_ratio = min( exp_win.size[0] / self.movie_stim.size[0], exp_win.size[1] / self.movie_stim.size[0] * aspect_ratio, ) width = min_ratio * self.movie_stim.size[0] height = min_ratio * self.movie_stim.size[0] / aspect_ratio if self._scaling is not None: width *= self._scaling height *= self._scaling self.movie_stim.size = (width, height) self.duration = self.movie_stim.duration # print(self.movie_stim.size) # print(self.movie_stim.duration) super()._setup(exp_win)
def playVids(): for vid in vids: v = visual.MovieStim2(win, pathVids+vid) core.wait(2) win.flip() #press=event.waitKeys(keyList=['return']) #waits for the participant to press 'return' while v.status != visual.FINISHED: #On my system the videos appear to only play inside a 'while' loop v.draw() win.flip() print(vid) #shows latest played vid (to check for errors in individual files) #event.waitKeys(keyList=['return']) win.close()
if __name__ == '__main__': removeExistingResultsFile() win = visual.Window(WINDOW_SIZE, fullscr=USE_FULLSCREEN_WINDOW, allowGUI=not USE_FULLSCREEN_WINDOW, screen=SCREEN_NUMBER) # Create your movie stim. mov = visual.MovieStim2( win, getVideoFilePath(), size=None, # (1280, 720), # pos specifies the /center/ of the movie stim location pos=[0, 0], flipVert=False, flipHoriz=False, noAudio=not INCLUDE_AUDIO_TRACK, # fps=90, loop=False) mov.useTexSubImage2D = True initProcessStats() # Start the movie stim by preparing it to play dt1 = getTime() display_frame_num = mov.play() draw_dur = getTime() - dt1
#Declare probe word for if Before condition if table['ProbeBeforeAfter'][trial] == 'Before': keystext = targetSentence text = visual.TextStim(win, keystext, pos=(0, 0), units='pix') text.draw() win.flip() event.clearEvents(eventType=None) core.wait(1) # Create your movie stim. if movStimVersion == 2: mov = visual.MovieStim2( win, videopath, size=720, # pos specifies the /center/ of the movie stim location pos=[0, 150], flipVert=False, flipHoriz=False, loop=False, noAudio=True) audioSound = sound.Sound(tmpSoundFile, sampleRate=48000) soundDur = audioSound.getDuration() else: mov = visual.MovieStim3( win, videopath, size=720, # pos specifies the /center/ of the movie stim location pos=[0, 150], flipVert=False, flipHoriz=False,
videopath = r'./movies/jwpIntro.mov' videopath = os.path.join(os.getcwd(), videopath) if not os.path.exists(videopath): raise RuntimeError("Video File could not be found:" + videopath) benq = monitors.Monitor(name="benq", width=53.5, distance=75.0) benq.saveMon() win = visual.Window(size=[1024, 768], pos=[(1920 - 1024) / 2, (1080 - 768) / 2], monitor=benq, allowGUI=False) mov = visual.MovieStim2(win, videopath, size=640, pos=[0, 0], flipVert=False, flipHoriz=False, loop=False) # Initialise the countdown timer = None timer_started = False timer_finished = False timer_value = 2 # Send a zero to the TMS machine. # Sending a value to the TMS device when the countdown finishes # will only have an effect if the value sent differs from the value # that the port had on it immediately before - # i.e., the trigger only has an effect if it changes the current state of the port
2. VLC application. Just install the standard VLC (32bit) for your OS. http://www.videolan.org/vlc/index.html """ from psychopy import visual, core, event import time videopath = r'D:\Dropbox\WinPython-32bit-2.7.6.0\my-code\pycvlcmovie\Epic.mp4' win = visual.Window([1024, 768]) # Create your movie stim. mov = visual.MovieStim2( win, videopath, size=1024, # pos specifies the /center/ of the movie stim location pos=[0, 100], flipVert=False, flipHoriz=False, loop=False) keystext = "PRESS 'q' or 'escape' to Quit.\n" keystext += "# 's': Stop/restart Movie.\n" keystext += "# 'p': Pause/Unpause Movie.\n" keystext += "# '>': Seek Forward 1 Second.\n" keystext += "# '<': Seek Backward 1 Second.\n" keystext += "# '-': Decrease Movie Volume.\n" keystext += "# '+': Increase Movie Volume." text = visual.TextBox(win, keystext, font_name=None,
else: frameDur = 1.0/60.0 # couldn't get a reliable measure so guess # Initialize components for Routine "instr" instrClock = core.Clock() instructions = visual.TextStim(win=win, ori=0, name='instructions', text="Please look and listen to the speakers, then speak the words you heard, then type the words you heard. Press any key to continue.", font='Arial', pos=[0, 0], height=0.07, wrapWidth=None, color='white', colorSpace='rgb', opacity=1, depth=0.0) # Initialize components for Routine "trial" trialClock = core.Clock() movie = visual.MovieStim2(win=win, name='movie', filename='test.mp4', ori=0, pos=[0, 0], opacity=1, depth=0.0, ) sound_1 = sound.Sound(u'si621.wav', secs=-1) sound_1.setVolume(1) # Initialize components for Routine "trialpost" trialpostClock = core.Clock() speak_instruct = visual.TextStim(win=win, ori=0, name='speak_instruct', text='Say what you heard!', font='Arial', pos=[0, 0], height=0.1, wrapWidth=None, color='white', colorSpace='rgb', opacity=1, depth=0.0)
alignHoriz='center', name='bottomMsg', text="bbb", units='norm') # check if movie exists pathToMovie = '%s%s' % (params['movieFolder'], params['movieNames'][0]) if not os.path.exists(pathToMovie): raise RuntimeError("Video File could not be found: " + pathToMovie) # Create movie stimulus mov = visual.MovieStim2( win, pathToMovie, size=640, # pos specifies the /center/ of the movie stim location pos=[0, 100], flipVert=False, flipHoriz=False, loop=False) # Create bottom text stim tapText = visual.TextStim(win, 'Please tap along with the video.', pos=(0, -250), units='pix', color='#000000') # read questions and answers from text files [topPrompts, bottomPrompts] = BasicPromptTools.ParsePromptFile(params['promptDir'] +
def movie_tiral(self, timeout=10): # ------Prepare to start Routine "trial"------- trialClock = core.Clock() # setub folder structure for file saving if not os.path.exists( str(self.thisDir) + '\\data\\' + self.filename + '\\movie_trial\\'): os.makedirs( str(self.thisDir) + '\\data\\' + self.filename + '\\movie_trial\\') # initiate movie self.mov = visual.MovieStim2(win=self.win, filename='trial_ressources/animals.mp4', flipVert=False, flipHoriz=False, loop=False, depth=0.0) # set movie size self.mov.setSize([1920, 1080]) # initiate some text stuff self.text = visual.TextStim( win=self.win, ori=0, name='text', text='Please wait. \nSaving is in progress', font='Arial', pos=[0, 0], height=0.1, wrapWidth=None, color='white', colorSpace='rgb', opacity=1, depth=0.0) # assign mouse and stuff for the loop myMouse = event.Mouse() counter = 0 self.m_pos = [] trialClock.reset() while True: # start movie self.mov.draw() self.win.flip() # track mouse pressing event mouseIsDown = myMouse.getPressed()[0] myMouse.clickReset() if mouseIsDown and not oldMouseIsDown: m_po = myMouse.getPos() self.m_pos.append(m_po) if counter == 0: print('Clicks Maus position') print(str(counter) + ' ' + str(m_po)) # if pressed save frame to RAM filename = str( self.thisDir ) + '\\data\\' + self.filename + '\\movie_trial\\' + 'shot.png' self.win.getMovieFrame(buffer='front') counter += 1 oldMouseIsDown = mouseIsDown # quit if event.getKeys(keyList=['escape']): self.win.close() core.quit() break if trialClock.getTime() >= timeout: break # stop movie and show text self.mov.stop() self.win.flip() self.text.draw() self.win.flip() # save frames from RAM to Folder self.win.saveMovieFrames(fileName=filename, clearFrames=True) # extract mouse clicks self.x = [] self.y = [] for i in self.m_pos: self.x.append(i[0]) self.y.append(i[1]) # export key events as column df = pd.DataFrame({'X': self.x, 'Y': self.y}) # create a Pandas Excel writer using XlsxWriter as the engine. writer = pd.ExcelWriter(str(self.thisDir) + '\\data\\' + self.filename + '\\' + 'Maus_Position' + '.xlsx', engine='xlsxwriter') # convert the dataframe to an XlsxWriter Excel object. df.to_excel(writer, sheet_name='Sheet1') # close the Pandas Excel writer and output the Excel file. writer.save()