decord
decord copied to clipboard
VideoReader: Fastest way to get all the frames?
Hi there,
I'm using get_batch
to get all the frames from a 1 min video and I wanted to ask you if there is a fastest method to achieve this? I read the code from video_reader.py
and I don't think so, but I just wanted to confirm.
Here is my code:
vr = VideoReader(video, ctx=gpu(0))
n_frames = len(vr) # 1800
frames_indexes = list(range(0, n_frames)) # [0, ..., 1799]
frames = vr.get_batch(frames_indexes).asnumpy()
Thank you.
It's not faster but it is more concise:
vr = VideoReader(video, ctx=gpu(0))
frames = vr[:].asnumpy()
Also do you really need ctx=gpu(0)
? Isn't numpy always on cpu anyway ?
I'm not a numpy expert but we see our script appearing in nvidia-smi
when we use ctx=gpu(0)
so I guess it works.
The weird thing though: when we hash the frames, the hashes are different when we use ctx=cpu(0)
and ctx=gpu(0)
.
For instance:
vr_gpu = VideoReader(video, ctx=gpu(0))
vr_cpu = VideoReader(video) # defaults to ctx=cpu(0)
hash(vr_gpu[0].asnumpy()) == hash(vr_cpu[0].asnumpy()) # => False