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.
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?
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. Of course, if you just convert your existing movie, there may be some quality loss, but hopefully it won’t be noticeable.
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
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:
Here’s code that reproduces the error (if you switch to MovieStim, it will usually play):
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()
Thanks,
Jen
ps. I probably should have posted this in the coder section, sorry…
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)
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:
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.
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.
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)