MovieStim2 ============================================ (訳注:MovieStim2は原文に掲載されていないが、MovieStimが事実上バグ修正されなくなっているため訳しておく。一般的な視覚刺激オブジェクトにはないデータ属性、メソッドの解説に限る。) .. code-block:: python MovieStim2(win, filename='', units='pix', size=None, pos=(0.0, 0.0), ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0, noAudio=False, vframe_callback=None, fps=None, interpolate=True) PsychoPyで動画(mpeg, avi, etc...)を再生するクラスである。MovieStimと異なり、avbinの代わりにOpenCVのcv2パッケージを利用する。VLC Media playerもインストールされている必要がある。 (訳注:libVLCがPsychoPyから見える場所に置けばVLC Media Playerそのものをインストールしなくてもよい) デモのMovie2Stim.py参照のこと。以下にパラメータを示す。 ============= ============================================================================================================ パラメータ 解説 ============= ============================================================================================================ filename 再生する動画ファイル名。 flipVert TrueまたはFalse。動画を垂直方向に反転するか否かを指定する。 flipHoriz TrueまたはFalse。動画を水平方向に反転するか否かを指定する。 volume 音声のボリュームを指定する。100で公称レベル、0で無音である。(訳注:原文ではnominal level。1.85.0のコードを 確認すると、0.0から1.0の浮動小数点数の場合は100倍され、1以上の場合はそのまま使用される。setVolume()参照。) loop TrueまたはFalse。動画を最後まで再生した時に自動的に最初に戻って再生を続けるか否かを指定する。 ============= ============================================================================================================ .. A stimulus class for playing movies (mpeg, avi, etc...) in PsychoPy that does not require avbin. Instead it requires the cv2 python package for OpenCV. The VLC media player also needs to be installed on the psychopy computer. .. **Example**:: .. See Movie2Stim.py for demo. .. :Parameters: .. filename : .. a string giving the relative or absolute path to the movie. .. flipVert : True or *False* .. If True then the movie will be top-bottom flipped .. flipHoriz : True or *False* .. If True then the movie will be right-left flipped .. volume : .. The nominal level is 100, and 0 is silence. .. loop : bool, optional .. Whether to start the movie over from the beginning if draw is .. called and the movie is done. draw(self, win=None) ---------------------------- 現在のフレームをWindowオブジェクトに描画する。現在のフレームは自動的に決定される。 このメソッドは動画再生時にフレーム毎に呼び出される必要がある。 .. Draw the current frame to a particular visual.Window (or to the default win for this object if not specified). The current position in the movie will be determined automatically. .. This method should be called on every frame that the movie is meant to appear. getCurrentFrameNumber(self) ----------------------------------- 現在のフレームのフレーム番号を取得する。動画ファイルの最初のフレームの番号は1である。 .. Get the current movie frame number. .. The first frame number in a file is 1. getCurrentFrameTime(self) ------------------------------------ 現在のフレームに対応するタイムスタンプを取得する。 .. Get the time that the movie file specified the current video frame as having. getFPS(self) ------------------------ 動画のFPS(フレーム毎秒)を返す。 .. Returns the movie frames per second playback speed. getPercentageComplete(self) ----------------------------------- 動画の再生済み部分の割合を0.0から100.0の値で返す。 .. Provides a value between 0.0 and 100.0, indicating the .. amount of the movie that has been already played. getTimeToNextFrameDraw(self) ------------------------------------ 次のフレームの描画タイミングまでの時間を返す。 .. Get the number of sec.msec remaining until the next .. movie video frame should be drawn. getVolume(self) ------------------------------ 現在の音声ボリュームを返す。0なら無音、100なら最大である。 .. Returns the current movie audio volume. .. 0 is no audio, 100 is max audio volume. isCurrentFrameVisible(self) ---------------------------------- 動画のフレームはメモリ上で2つの段階を経る。第1段階ではディスクからメモリ上にロードされているが、まだ表示されていない。第2段階では実際にディスプレイに表示されたときである。このメソッドはフレームが第1段階にある時はFalse、第2段階にある時はTrueを返す。 .. The current video frame goes through two stages; the first being when the movie frame is being loaded, but is not visible on the display. .. The second is when the frame has actually been presented on the display. Returns False if the frame is in the first stage, True when in stage 2. loadMovie(self, filename, log=True) -------------------------------------------- 指定したファイルから動画を読み込む。読み込みが完了するとデータ属性durationに動画の再生時間が格納される。単位は秒である。 .. Load a movie from file .. :Parameters: .. filename: string .. The name of the file, including path if necessary .. After the file is loaded MovieStim.duration is updated with the movie duration (in seconds). pause(self, log=True) ----------------------------- 動画再生を一時停止する。play()で再開する。 .. Pause the current point in the movie (sound will stop, current frame will not advance). If play() is called again both will restart. play(self, log=True) ------------------------------- 動画を再生する。一時停止後に再開する際にも用いる。 .. Continue a paused movie from current position. seek(self, timestamp, log=True) -------------------------------------- 引数timestampで指定した位置までシークする(再生位置を変更する)。 .. Seek to a particular timestamp in the movie. setContrast(self) -------------------------------- このメソッドはMovieStim2では機能しない。 .. Not yet implemented for MovieStim setFlipHoriz(self, newVal=True, log=True) --------------------------------------------- Trueならば左右反転して描画する。Falseならば通常通り描画する。反転はoriによる回転などを施す前のイメージに対して行われる。 .. If set to True then the movie will be flipped horizontally (left-to-right). Note that this is relative to the original, not relative to the current state. setFlipVert(self, newVal=True, log=True) ------------------------------------------------ Trueならば上下反転して描画する。Falseならば通常通り描画する。反転はoriによる回転などを施す前のイメージに対して行われる。 .. If set to True then the movie will be flipped vertically (top-to-bottom). Note that this is relative to the original, not relative to the current state. setMovie(self, filename, log=True) ------------------------------------------ loadMovie()と同一である。他の視覚刺激オブジェクトとの構文上の整合性を保つために用意されている。 .. See `~MovieStim.loadMovie` (the functions are identical). .. This form is provided for syntactic consistency with other visual stimuli. setVolume(self, v) --------------------- 音声トラックのボリュームを指定する。0.0は無音、100は0 dbである。0.0から1.0までの浮動小数点を用いることも可能で、この場合は0から100の整数に変換される。 .. Set the audio track volume. 0 = mute, 100 = 0 dB. float values between 0.0 and 1.0 are also accepted, and scaled to an int between 0 and 100. shouldDrawVideoFrame(self) ------------------------------- 次のフレームを描画すべき状態であればTrue、そうでなければFalseを返す。getTimeToNextFrameDraw()参照。 (訳注:60fpsのモニターで30fpsの動画を再生している場合、動画の方が1秒当たりのフレーム数が少ないのでまだ次の動画フレームを描画すべきタイミングが来ていないのにモニターの次のリフレッシュのタイミングとなることがある。このメソッドを活用すると、不要なflip()待ちを減らして反応時間の測定精度を上げる等の工夫が可能である。ただし、反応時間の測定精度向上であれば現在ならioHubを使う方が良いかも知れない。) .. True if the next movie frame should be drawn, False if it is not yet time. See getTimeToNextFrameDraw(). stop(self, log=True) ------------------------------ 動画の再生を現在の位置で停止する。このメソッドで停止すると再生しなおすことは出来ない。再び再生するにはload()を実行し直す必要がある。従って、再生を再開する必要がある場合はpause()を使う方がよい。 .. Stop the current point in the movie (sound will stop, current frame will not advance). Once stopped the movie cannot be restarted - it must be loaded again. .. Use pause() if you may need to restart the movie.