Error while trying to play movie

I’m using psychopy ver 1.84.0.
I was trying to play a video for my experiment. But when i ran the experiment, there was this error message:

**File "/Applications/PsychoPy2_64bit.app/Contents/Resources/lib/python2.7/moviepy/audio/io/readers.py", line 193, in get_frame**
**    "but len(buffer)=%d\n"%(len(self.buffer))+ str(error))**
**IOError: Error in file 1F2.mp4, At time t=22.68-22.76 seconds, indices wanted: 100000-103715, but len(buffer)=102505**
**index 102505 is out of bounds for axis 0 with size 102505**

Please anyone help me. I don’t know what this error means. Thanks a lot.

I think this is fixed in more recent versions. Some movies appear to have slightly different durations for their video versus audio streams. One solution is to fix those movies in ffmpeg to have exactly the same duration but PsychoPy now checks and makes the audio fit to the video stream.

Could you try PsychoPy 1.84.2 and see if that fixes your problem? thanks

@jon sorry for the late reply. I’ve tried the 1.84.2 version and the problem still exists. I changed the video format from .mp4 to .mov, the problem still exists, but not as often as when I used .mp4 format.

About using ffmpeg, i don’t really understand how to do it. Should I trim the movie? What should I do to have exactly the same duration using ffmpeg?

Thanks a lot!

OK, could you email me a copy of your movie or share a link to it here so we can take a look?

I ran into the same issue recently. It seems to me that there’s a bug in moviepy: apparently moviepy relies on the movie duration to decide how many sound frames to expect from ffmpeg when to extract the sound track from the movie: that doesn’t necessarily correspond to the actual size of the sound track.

I fixed this by patching moviepy/audio/io/readers.py.readers.py (7.9 KB)

The patch affects these two function: get_frame and buffer_around.

@Jon, pls check my reply to Lily.

I repost the patch as I forgot to remove a debug print in it. readers.py (7.9 KB)

1 Like

Thanks Luca
If this is a bug that could be contributed to moviepy itself that seems preferable than here, no?

1 Like

I just checked on my own mac with the video file you provided, Lily, and I couldn’t reproduce the problem. Do you say it’s intermittent, even with the same video file?

Any progress on this issue? In 1.84.2 I’m getting this error as well. Luca: Sorry for the beginner question but how do you use that patch file? Does it have to be inserted into the start of a code (rather than builder) experiment?

Thank you!

Actually, figured out how to locate the file and replaced it with the patch. Seems to fully fix the problem, thank you!