Valentyn :
I am trying to upload an entire video file into RAM for quick access. i want the file to be as it is without any decoding, etc. I just want to point to a location in RAM instead of remote driver. The file is only 2 GB. I have 128 GB RAM. I need to do frame by frame analysis and readying from a server takes forever.
I thought i would do something like this
with open('my_file.txt', 'r') as f:
file_content = f.read() # Read whole file in the file_content string
print(file_content)
But I can an error. Is there another way to do it? Like using IO library?
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
this example uses requests.get, but this works only for HTTP i have a local server I can mount with NFS
import requests
from pygame import mixer
import io
r = requests.get("http://example.com/somesmallmp3file.mp3")
inmemoryfile = io.BytesIO(r.content)
mixer.music.init()
mixer.music.load(inmemoryfile)
mixer.music.play()
Friedrich S :
Adding a 'b' for binary mode should make it work.
u = open("/net/server/raw/2020.04.02/IMG_9261.MOV",'rb')
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=398229&siteId=1