Unable to play .avi and .mp4 videos: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81

231 views
Skip to first unread message

Max Smith

unread,
Jul 26, 2016, 6:21:04 PM7/26/16
to psychopy-users
Hello,

I am using:
Windows 7 32bit (Intel Integrated Graphics)
Psychopy 1.83.4
Python 2.7.3

I want to start by stating that I am very new to the world of video presentation, psychopy, and python so I apologize up front if I leave important information out or improperly phrase my questions. I am trying to play .avi video clips that I have rendered via Unity Game Engine using MovieStim2. In order to get the clips to play at all through VLC or Windows Media Player in the first place I had to install Lagarith Lossless Codec (LAGS). The display resolution of the videos is 1920x1080 and VLC shows that the files are being decoded in 24 bits RGB. As a work around, I have also tried recording clips using Open Broadcaster Software saving the videos as .mp4 files using x264 codec for encoding. When I try playing both the .avi and the .mp4 files with this script:

videopath = 'C:\Users\lab user\Videos\2016-07-26-1617-46.mp4'
# set window
win = visual.Window([500, 400], fullscr=False)
# movie stimuli
mov = visual.MovieStim2(win, videopath)
print 'Movie Duration: ', mov.duration
print 'Movie: ', mov
shouldflip = mov.play()
while mov.status != visual.FINISHED:
    # Only flip when a new frame should be displayed. Can significantly reduce
    # CPU usage. This only makes sense if the movie is the only /dynamic/ stim
    # displayed.
    if shouldflip:
        # Movie has already been drawn , so just draw text stim and flip
        text.draw()
        win.flip()
    else:
        # Give the OS a break if a flip is not needed
        time.sleep(0.001)

win.close()
core.quit()

 I get some form of this Error message:
 
Traceback (most recent call last):
  File "C:\Experiments\CategoryMovieStimPractice.py", line 32, in <module>
    mov = visual.MovieStim2(win, videopath)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\contrib\lazy_import.py", line 120, in __call__
    return obj(*args, **kwargs)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\visual\movie2.py", line 220, in __init__
    self.loadMovie(self.filename)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\visual\movie2.py", line 294, in loadMovie
    self._createAudioStream()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\visual\movie2.py", line 334, in _createAudioStream
    raise RuntimeError('Error: %s file not readable' % self.filename)
Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\app\coder\coder.py", line 1513, in onIdle
    self.outputWindow.write(text)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\app\stdOutRich.py", line 56, in write
    self.WriteText(thisLine)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\wx-2.8-msw-unicode\wx\richtext.py", line 2516, in WriteText
    return _richtext.RichTextCtrl_WriteText(*args, **kwargs)
  File "C:\Program Files (x86)\PsychoPy2\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 45: character maps to <undefined>

It seems to me that the issue has to do with psychopy automatically using cp1252 codec and is therefore unable to interpret the .avi and mp4 files because they use LAGS and x264 codecs. Is there any way to add codecs to psychopy? Any thoughts on this matter would be greatly appreciated.

Thank you!

Max

Michael MacAskill

unread,
Jul 26, 2016, 6:56:46 PM7/26/16
to psychop...@googlegroups.com

> On 27/07/2016, at 10:21, Max Smith <mkaill...@gmail.com> wrote:
>
> It seems to me that the issue has to do with psychopy automatically using cp1252 codec and is therefore unable to interpret the .avi and mp4 files because they use LAGS and x264 codecs. Is there any way to add codecs to psychopy? Any thoughts on this matter would be greatly appreciated.

Hi Max,

I'm guessing (and hoping, because it's a much simpler problem to fix) that you're mixing up different codec concepts here. The error actually seems to be referring to Unicode text encoding rather than video codecs.

– Are there any non-standard characters in either the filenames of your videos, or the path to them?

– Are you reading the filenames from a .csv file with an unusual text encoding? Try using utf-8, or switch to a .xlsx file.

Regards,

Michael


--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Reply all
Reply to author
Forward
0 new messages