我目前正在使用:如何使用pymongo從mongodb獲取文件對象?
some_fs = gridfs.GridFS(db, "some.col")
fs_file = some_fs.get(index)
獲得<class 'gridfs.grid_file.GridOut'>
對象。
我該如何獲取文件對象,或者如何將其轉換爲python文件對象? 我必須保存爲臨時文件才能做到這一點嗎?
編輯:
這是完整的代碼我使用:
FFMPEG_BIN = "ffmpeg.exe"
some_fs = gridfs.GridFS(db, "some.col")
vid_id = ObjectId("5339e3b5b322631b544b2338")
vid_file = some_fs.get(vid_id)
raw = vid_file.read()
print type(vid_file), type(raw)
with open(raw, "rb") as infile:
pipe = sp.Popen([FFMPEG_BIN,
# "-v", "quiet",
"-y",
"-i", "-",
"-vcodec", "copy", "-acodec", "copy",
"-ss", "00:00:00", "-t", "00:00:10", "-sn",
"test.mp4" ]
,stdin=infile, stdout=sp.PIPE
)
pipe.wait()
輸出:
[2014-03-31 19:03:00] Connected to DB.
<class 'gridfs.grid_file.GridOut'> <type 'str'>
Traceback (most recent call last):
File "C:/dev/proj/src/lib/ffmpeg/win/test.py", line 19, in <module>
with open(raw, "rb") as infile:
TypeError: file() argument 1 must be encoded string without NULL bytes, not str
infile沒有設置任何東西...我應該使用什麼作爲輸入? – Jeff
我編輯了我的答案來修復我的複製粘貼錯誤。 –
這給了我:'TypeError:必須可轉換爲緩衝區,而不是GridOut' – Jeff