psychopy.org | Reference | Downloads | Github

Rare and strange conflict between sound file and movie file with ffmpeg

sound
movies

#1

In short, I’ve built a script for running studies with babies that plays an attention getter followed by a movie file. The attention getter consists of a looming geometric shape and, at the same time, plays a short .wav sound file which is loaded at the start of the script. Immediately after the attention getter, the script displays the first frame of the movie, paused. The movies are all .movs with mpeg-4 encoding and 48000Hz mono audio.

I built in the capability to re-play the attention-getter if the infant does not immediately look at the screen, with the first frame of the movie frozen on the screen. So, the movie disappears, the attention getter plays again, first frame reappears paused. All fine.

The issue is, if the movie has sound, sometimes (and only sometimes, which is maddening) after re-playing the attention-getter several times, when I start trying to play the movie, I get the following error (picking up from the draw command in my script):

    dispMovie.draw()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/movie3.py", line 383, in draw
    self._updateFrameTexture()  # will check if it's needed
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/movie3.py", line 303, in _updateFrameTexture
    self._numpyFrame = self._mov.get_frame(self._nextFrameT) 
  File "<decorator-gen-14>", line 2, in get_frame
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/moviepy/video/io/VideoFileClip.py", line 74, in <lambda>
    self.make_frame = lambda t: reader.get_frame(t)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/moviepy/video/io/ffmpeg_reader.py", line 163, in get_frame
    result = self.read_frame()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/moviepy/video/io/ffmpeg_reader.py", line 106, in read_frame
    s = self.proc.stdout.read(nbytes)
AttributeError: FFMPEG_VideoReader instance has no attribute 'proc'

My best guess is some kind of conflict caused by the sound.play() of the attention-getter using the same FFMPEG resources as the movie’s sound.play (because moviestim uses psychopy.sound for its sound), so in theory this could happen if you were alternating sound files as well.

Has anyone else encountered this, or have any ideas about how to stop it from happening?


#2

Hi,

Note that the error comes from the _FFMPEG_VideoReader object, not from the FFMPEG_AudioReader:

FFMPEG_VideoReader instance has no attribute ‘proc’

The audio and the video streams of a movie are treated as two separate streams (see movie3.py).

Probably the close() method of the FFMPEG_VideoReader object has been called somewhere before (provided that the subprocess.popen which creates the proc object never returns None).
Try to insert some debug print in FFMPEG_VideoReader.close() and see what happens.

Hard to guess more without having a look to your code.

Cheers,
L.


#3

Hi Luca,

Sorry for the slow response. Haven’t had a chance to try the debug code in FFMPEG yet, but I’ll be able to do that probably Monday. In the interim, you can see the code for yourself here: https://github.com/jfkominsky/PyHab