Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将整个视频文件上载到内存时出错_Python_File_Io - Fatal编程技术网

Python 将整个视频文件上载到内存时出错

Python 将整个视频文件上载到内存时出错,python,file,io,Python,File,Io,我试图上传一个完整的视频文件到RAM中,以便快速访问。我希望文件保持原样,没有任何解码,等等。我只想指向RAM中的一个位置,而不是远程驱动程序。该文件只有2GB。我有128 GB内存。我需要进行逐帧分析,从服务器上做好准备需要很长时间 我想我会这样做 with open('my_file.txt', 'r') as f: file_content = f.read() # Read whole file in the file_content string print(file_cont

我试图上传一个完整的视频文件到RAM中,以便快速访问。我希望文件保持原样,没有任何解码,等等。我只想指向RAM中的一个位置,而不是远程驱动程序。该文件只有2GB。我有128 GB内存。我需要进行逐帧分析,从服务器上做好准备需要很长时间

我想我会这样做

with open('my_file.txt', 'r') as f:
    file_content = f.read() # Read whole file in the file_content string
print(file_content)
但我可以纠正一个错误。还有别的办法吗?比如使用IO库

In [11]: u = open("/net/server/raw/2020.04.02/IMG_9261.MOV",'r')

In [12]: data = u.read()

---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-12-eecbc439fbf0> in <module>
----> 1 data = u.read()

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/codecs.py in decode(self, input, final)
    320         # decode input (taking the buffer into account)
    321         data = self.buffer + input
--> 322         (result, consumed) = self._buffer_decode(data, self.errors, final)
    323         # keep undecoded input until the next call
    324         self.buffer = data[consumed:]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 31: invalid continuation byte

为二进制模式添加一个“b”应该可以使它工作

u = open("/net/server/raw/2020.04.02/IMG_9261.MOV",'rb')

尝试以
rb
模式而不是
r
模式打开文件。前者用于从文件中读取字节,后者用于人类可读的文本。
u = open("/net/server/raw/2020.04.02/IMG_9261.MOV",'rb')