MemoryError during video presentation - ffmpeg problem? - v1.85.2

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 1.85.2
Standard Standalone? (y/n) If not then what?: y
**What are you trying to achieve?: I have an experiment in which I created a loop of 10 consecutive videos (~2-5 min/each). At the middle of the experiment, the paradigm eventually crashes with a Memory Error. Using the task manager, I noticed that ffmpeg adds a new process for each new video, and when the video is finished, it keeps using ram. I have tried changing the backend to avbin or opencv, but still no luck. I have also tried to change the video units to pix, but the problem still remains. I have an i7 PC with 12GB of ram, so I guess that this is unrelated with PC specs.

Any ideas on how to solve this problem?

Thank you.

Pedro

Here is the error output:
######## Running: D:\Mindprober\NewProtocol\Paradigm_04_dec_lastrun.py ######### Traceback (most recent call last): File "C:\Folder\Paradigm_lastrun.py", line 800, in <module> depth=0.0, File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\movie3.py", line 129, in __init__ self.loadMovie(self.filename) File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\movie3.py", line 189, in loadMovie jwe_tmp.audio.to_soundarray(), File "<decorator-gen-72>", line 2, in to_soundarray File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration return f(clip, *a, **k) File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\audio\AudioClip.py", line 114, in to_soundarray chunksize=buffersize)) File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\numpy\core\shape_base.py", line 237, in vstack return _nx.concatenate([atleast_2d(_m) for _m in tup], 0) MemoryError

It’s to do with the length of the movie and including sound.

Right now PsychoPy MovieStim3 loads the entire sounds stream into memory at the start of a video. If the movie is long then this fails. Your options (until we write the code for the audio to stream instead) are:

  • turn off the audio for the movie (check the box that says ‘mute’ in the movie component)
  • use a different backend. You said that “I have tried changing the backend to avbin or opencv, but still no luck” but I feel sure that you didn’t get this error message with those, so you’d have to tell us what the actual problem was with those in your case
  • cut your movies down in duration

best wishes
Jon

Hi Jon,

Thank you for your response and help with this issue.
Turning off the audio seems to solve the issue. However, I really need to present the videos with sound and with the total duration of the videos.
You’re right: I am obtaining different errors when I use other backends.

With avbin, the program runs but it breaks after the presentation of some videos. Here’s the output of one run using avbin:

Exception in thread Thread-7:

Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy2\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Program Files (x86)\PsychoPy2\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\media\__init__.py", line 145, in _thread_run
    self.run()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\media\__init__.py", line 202, in run
    job()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\media\avbin.py", line 392, in <lambda>
    lambda: self._decode_video_packet(video_packet))
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\media\avbin.py", line 498, in _decode_video_packet
    buffer = (ctypes.c_uint8 * (pitch * height))()
MemoryError

With opencv, the paradigm breaks before initializing any video, with the following error:

  File "D:\NewProtocol\Paradigm_04_dec_lastrun.py", line 750, in <module>
    depth=0.0,
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\contrib\lazy_import.py", line 120, in __call__
    return obj(*args, **kwargs)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\movie2.py", line 242, in __init__
    self.loadMovie(self.filename)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\movie2.py", line 352, in loadMovie
    dtype=numpy.uint8)
TypeError: 'float' object cannot be interpreted as an index

Thank you very much

Best regards,
Pedro

Adding the streaming of the audio (rather than preloading the whole thing) which is what you need will take a while to code.

I don’t know the issue with pygame but my experience with that is that it was really crumby anyway.

The OpenCV backend should be fixable though. In fact, the bug that’s cropping up for you there has already been fixed but not yet released. Try downloading the and using it to replace your psychopy/visual/movie2.py file:

https://raw.githubusercontent.com/psychopy/psychopy/master/psychopy/visual/movie2.py

Hi again Jon,

I am really thankful for your prompt response.
It seems that this updated version of OpenCV is working now. :wink:

Thank you very much

Pedro

Hi Jon,

I also try to run a movie and run into the same problem of memory.
I try to download movie2.py from the link above and replace, but still get the same error.
Is there a solution for this?

Thanks!