# Moviestim 1/2/3, mp4s, pauses and IOErrors

**URL:** https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637
**Category:** Coding
**Created:** [August 3, 2016, 9:49pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637 "2016-08-03T21:49:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jwe080](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jwe080](https://discourse.psychopy.org/u/jwe080)
#### Post date: [August 3, 2016, 9:49pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/1 "2016-08-03T21:49:03Z")

</div>

Hi there,

I want to show a set of movie clips separated by fixation. I had working code just using the pyschopy library from the command line but somehow broke the module by installing avbin10 when I tried running my code in the standalone version of psychopy and it asked for avbin10 to play the mp4.

In the standalone version 1.84.0rc4:  
If the movie is loaded as MovieStim then there are a pauses and some odd low res frames at the beginning and end of each clip and some kind of memory dequeuing error if I don’t pause the movie before switching to the next.

If the movie is loaded as MovieStim2 then it won’t load the movie at all (copy/paste doesn’t seem to work from the psychopy output window and I can only post one image as a new user so you’ll have to believe me).

If the movie is loaded as MovieStim3 then it has an indexing error for the clip, which was originally saved with moviepy.

 ![](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/1X/14df65cc8b36fa30b7644c537f1bd7734e080e91.png)

I probably want to use MovieStim3, but am not really sure what to do about the fact it is trying to index one value past the end of the clip. I also don’t know how to make the original MovieStim behave in the standalone version, nor do I know how to fix what avbin10 broke. The demo works flawlessly, of course. Any ideas?

Thanks,  
Jen

---

<div class="post-metadata">

### Author: ![lindeloev](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/lindeloev/32/15_2.png) [@lindeloev](https://discourse.psychopy.org/u/lindeloev)
#### Post date: [August 4, 2016, 8:27am UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/2 "2016-08-04T08:27:24Z")

</div>

It could be that something in the movie file itself is corrupted, making it difficult for most players to play it. Could you try exporting it to a different format/codec? There’re many tools out there to do this (Google it). [But I like using VLC](https://www.google.dk/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=use%20vlc%20to%20convert%20movie&oq=use%20vlc%20to%20convert%20movie&aqs=chrome..69i57j0.7251j0j7). Of course, if you just convert your existing movie, there may be some quality loss, but hopefully it won’t be noticeable.

---

<div class="post-metadata">

### Author: ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)
#### Post date: [August 4, 2016, 8:35am UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/3 "2016-08-04T08:35:45Z")

</div>

Maybe you could provide a link to an example movie for testing? Does it have audio (and is this needed)? I wonder if the audio and video streams are mis-aligned.

moviepy is relatively new but actively being developed so we might be able to get them to investigate why it fails

---

<div class="post-metadata">

### Author: ![jwe080](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jwe080](https://discourse.psychopy.org/u/jwe080)
#### Post date: [August 5, 2016, 5:36pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/4 "2016-08-05T17:36:15Z")

</div>

The clip plays fine in vlc, quicktime etc, even using moviepy’s preview. It does have audio, which would be nice to keep. The clip claims to be 16.04s.

Here’s a link to one of the files:  
[http://www.dropbox.com/s/vrrqd0vzgh1hb2f/01.mp4?dl=0](http://www.dropbox.com/s/vrrqd0vzgh1hb2f/01.mp4?dl=0)

Here’s code that reproduces the error (if you switch to MovieStim, it will usually play):

```auto
from psychopy import visual, core, event

win = visual.Window([800,600])
mov = visual.MovieStim3(win, '01.mp4', flipVert=False, flipHoriz=False, loop=False)

print 'duration=%.2fs' %(mov.duration)
globalClock = core.Clock()

while mov.status != visual.FINISHED:
   mov.draw()
   win.flip()
   for key in event.getKeys():
      if key in ['escape','q']:
         win.close()
         core.quit()

core.quit()

```

[https://www.dropbox.com/s/vrrqd0vzgh1hb2f/01.mp4?dl=0](https://www.dropbox.com/s/vrrqd0vzgh1hb2f/01.mp4?dl=0)

Thanks,  
Jen  
ps. I probably should have posted this in the coder section, sorry…

---

<div class="post-metadata">

### Author: ![jwe080](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jwe080](https://discourse.psychopy.org/u/jwe080)
#### Post date: [August 10, 2016, 3:03pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/5 "2016-08-10T15:03:48Z")

</div>

So I figured out that moviepy is adding a fraction of a second to the duration of the saved clips, which is causing the issue with creating the sound array. I added a work around to my version of psychopy visual. Seems to fix things for now.

```
    if os.path.isfile(filename):
        self._mov = VideoFileClip(filename, audio=(1 - self.noAudio))
        if (not self.noAudio) and (self._mov.audio is not None):
            # JWE added this as a patch for a moviepy oddity where the duration is inflated in the saved file
            jwe_tmp = self._mov.subclip(0,round(self._mov.duration))
            self._audioStream = sound.Sound(
                #self._mov.audio.to_soundarray(),
                jwe_tmp.audio.to_soundarray(),
                sampleRate=self._mov.audio.fps)
            del(jwe_tmp)
```

---

<div class="post-metadata">

### Author: ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)
#### Post date: [August 10, 2016, 4:11pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/6 "2016-08-10T16:11:37Z")

</div>

Thanks, and sorry I didn’t get to it earlier, but the problem and the fix work on my machine too). Not sure why audio and video don’t align correctly though.

I think this would be worth adding into the psychopy source upstream, but done as:

```python
try:
    theNormalWay
except:
    tryTheJenHack

```

Do you want to do that with a pull request or shall I do it on your behalf. I slightly prefer if you do because that maintains credit and you can join the list of contributors (in 6 months time I will have forgotten why this was an issue, but if your name is associated with that line in the repository then I can track back). Let us know if you need help adding it.

---

<div class="post-metadata">

### Author: ![jwe080](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@jwe080](https://discourse.psychopy.org/u/jwe080)
#### Post date: [August 10, 2016, 5:24pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/7 "2016-08-10T17:24:55Z")

</div>

I think I added a pull request in the right way. I also raised the issue on the moviepy page because that’s really where this specific problem arises, so the change may become obsolete if they end up addressing the issue.

---

<div class="post-metadata">

### Author: ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)
#### Post date: [August 10, 2016, 8:27pm UTC](https://discourse.psychopy.org/t/moviestim-1-2-3-mp4s-pauses-and-ioerrors/637/8 "2016-08-10T20:27:18Z")

</div>

Thanks, I’ve pulled it in. You’re a model citizen in the open-source world. Thanks for your contribution!  
(Initially wrote this in the wrong topic)
