I am currently using:
some_fs = gridfs.GridFS(db, "some.col")
fs_file = some_fs.get(index)
to get a <class 'gridfs.grid_file.GridOut'> object.
How do I get a file object instead or how do I convert this to a python file object? Do I have to save as a temp file to do this?
Edit:
This is the full code I am using:
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()
Output:
[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