MrKickkiller MrKickkiller - 8 months ago 21
Python Question

Trouble with encoding of .265 files. Python script to split them in NAL-units gives UnicodeDecodeError

While working on a project, i've hit a dead stop.

Whenever I try to execute the following python script with arguments

-i Bitstreams/BasketballDrive.265

where the Bitstreams/BasketballDrive.265 is an encoded video file, I get a UnicodeDecodeError

Traceback (most recent call last):
File "C:/Users/Mathieu/Documents/Deel-4--Video-3/", line 84, in <module>
File "C:/Users/Mathieu/Documents/Deel-4--Video-3/", line 79, in main
extractLayers(args['inputFile'], args['outputFile'], args['temporalLayer'])
File "C:/Users/Mathieu/Documents/Deel-4--Video-3/", line 17, in extractLayers
gesplit = split_file(voorsplit, "0x00".encode("cp1252"))
File "C:/Users/Mathieu/Documents/Deel-4--Video-3/", line 41, in split_file
for block in iter(lambda:, ''):
File "C:/Users/Mathieu/Documents/Deel-4--Video-3/", line 41, in <lambda>
for block in iter(lambda:, ''):
File "C:\Users\Mathieu\AppData\Local\Programs\Python\Python35-32\lib\encodings\", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 192: character maps to <undefined>

(Error was produced without specifying the encoding on the

If I include


I get

>>> utf-8

to the
didn't work either.

Python version : 3.5

Windows version : W8.1


Open the files in binary mode;


By default, Python 3 opens files in text mode. This implies trying to make a str out of the contents when reading. This is generally not what you want to do with a binary file.