Sound and Movie Files Not Always Working

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022.1.3
Standard Standalone? (y/n) If not then what?: y
Error report: I am trying to conduct an experiment that includes sound and video files. The experiment usually works, but occasionally crashes at the first presentation of either the sound or video files, claiming that the files are not there or are an incorrect format.

Basically, the experiment sometimes, but not always (or even usually) crashes at the first sound or video. Regardless, my RAs are always able to restart the program and it works successfully the second time around. That’s fine for the sound files (which happen at the beginning of the study, so restarting is no problem) but can be disastrous with the video files (which happen somewhere in the middle). I’m not entirely sure if it’s the exact same issue for each, but I thought I’d bundle the error reports together.

Here’s an example of a sound file error that happens on crash:

File “C:\Users\cast.cspanlab\Box\CSPAN Lab General\Experiments\Implementations\Armenia\”, line 94, in
pre_wav = sound.Sound(‘Stimuli/Sounds/puppies_1_dn_62_100_norm.wav’, secs=1.0, stereo=True, hamming=True,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\”, line 331, in init
self.setSound(value, secs=self.secs, octave=self.octave,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\”, line 426, in setSound
_SoundBase.setSound(self, value, secs, octave, hamming, log)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\”, line 200, in setSound
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\”, line 429, in _setSndFromFile
self.sndFile = f = sf.SoundFile(filename)
File “C:\Program Files\PsychoPy\lib\site-packages\”, line 629, in init
self._file = self._open(file, mode_int, closefd)
File “C:\Program Files\PsychoPy\lib\site-packages\”, line 1183, in _open
File “C:\Program Files\PsychoPy\lib\site-packages\”, line 1357, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode(‘utf-8’, ‘replace’))
RuntimeError: Error opening ‘Stimuli/Sounds/puppies_1_dn_62_100_norm.wav’: File contains data in an unknown format.
################# Experiment ended with exit code 1 [pid:9940] #################

And for the video file error:

Traceback (most recent call last):
File “C:\Users\cast.cspanlab\Box\CSPAN Lab General\Experiments\Implementations\Armenia\”, line 1619, in
stim_a_mp4 = visual.MovieStim3(
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\contrib\”, line 118, in call
return obj(*args, **kwargs)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 139, in init
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 248, in loadMovie
raise IOError(“Movie file ‘%s’ was not found” % filename)
OSError: Movie file ‘Stimuli/Images/puppies_1_dn_70_140_visl.mp4’ was not found
Exception ignored in: <function MovieStim3.del at 0x0000017AD0EF3CA0>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 571, in del
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 548, in _unload
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\”, line 1188, in clearTextures
OSError: exception: access violation reading 0x0000000000000000
################ Experiment ended with exit code 1 [pid:10220] #################

There is nothing wrong with the files themselves. Like I said, the experiments usually work! So the sound and video files work just fine in other contexts; they are there in the directory listed and PsychoPy can find them other times.

This isn’t a PsychoPy error:

OSError: Movie file ‘Stimuli/Images/puppies_1_dn_70_140_visl.mp4’ was not found

The operating system is telling PsychoPy that there is no file in that location with that name.

That issue needs to be resolved - we can’t debug this remotely, as it is all about what files are on your disk. Do some careful checking (e.g. paste the name above into a text editor and then copy the name of the file from Windows into the same text editor on the next line, so each character lines up). Are you sure they are the same (e.g. look for errant spaces, hyphens instead of underscores, etc)? Are you sure that this relative path is specified correctly?

If the experiment sometimes has an immediate error, but other times runs for a few trials or longer, this can simply be due to randomisation and potentially limitation of rows within your conditions files. e.g. the first video filename in your conditions file might be incorrect, but if the order of presentation is random, it won’t necessarily trigger an error immediately. If you are not presenting all rows in your conditions file in a given run, then it might not trigger an error at all. So while debugging this problem, it can be worth setting your loop to “sequential” rather than “random” - that way, any error will always occur at the same trial number.

Yep, I can see what that looks like, and trust me, I’ve had plenty of relative path issues before! I am absolutely, without a doubt, totally and completely sure that the path is specified correctly. The evidence I have for this is that the experiment also can run completely through without any crash whatsoever; it’s just not consistent in this behavior. That is, without doing anything to the files themselves or the experiment file, PsychoPy might have no problem finding “Stimuli/Images/puppies_1_dn_70_140_visl.mp4” a second time around. Similarly, the error that pops up for the video file is inconsistent with the filename that it claims it can’t find… it’s always the first video file that crashes PsychoPy even when it’s set up on “random”. The sound file that PsychoPy claims is “in an unknown format” is always the first sound file. But, like I mentioned, it’s also not consistent; the experiment can successfully and completely run other times without any changes to the PsychoPy program, the file structure, filenames, or anything else.

My only thought was that it has something to do with the fact that the experiments are saved in cloud folders (on Box). My university has really aggressive policies on user account management and it’s not practical to run it locally. Has this led to issues in the past?

Sorry for the late reply, but yes, this does sound consistent with you using cloud storage. I don’t know how Box works, but it might be that local copies of a file are only fetched when needed, and get pruned afterwards. That could explain why it fails when fetching a file for the first time, but not subsequently.

Again, the error you’re seeing is at an OS level - PsychoPy can’t work with a file if the OS can’t deliver it. So a file system issue would be a clear possible culprit, and your cloud storage could indeed be doing that. Cloud storage systems can do clever hacks to the Windows File Explorer or Mac Finder to make it seem like the icons they display are regular local files. But in reality they are just links to online resources - effectively a promise to deliver the file, rather than the file itself. As a user you might not notice the brief delay while the file is downloaded in the background, but a computer program might not be fooled so easily.

Because of performance issues, you should generally avoid using cloud storage to provide files for an experiment anyway (not only for delivering files to your experiment - such systems can unexpectedly hog your computer while syncing something else, completely throwing off the timing of your study). If your university imposes limits on your account, then the only option might be to use external storage, like a sufficiently-large USB flash drive, to hold your experiment.

Yep, looks like the cloud storage was the issue! We started making Box save the files as local about a week ago and it seems to be working flawlessly now. Thanks for your help and explanation for why that change fixed things.