vision.VideoFileReader: step function runs slower after reading each frame

2 Ansichten (letzte 30 Tage)
Hi, I'm using MATLAB 2012b on Ubuntu 64 bit. Computer is i7-3930K (6 cores) 3.2 GHz with 16 GB RAM.
I was trying to read a 613 MB video file. Since it's too big to read the whole video at once, I want to read sequentially, frame by frame, just like how normal movie players do.
Since VideoReader + read() combination was very slow, possibly because read function requires a frame number and MATLAB always recompute starting from a keyframe, I tried VideoFileReader. I followed the example written on: http://www.mathworks.co.uk/help/vision/ref/vision.videofilereaderclass.html#btdysrx
I found that for large video files, the time required for reading a single frame increases a lot as it reads more frames. After just 300 frames, it took more than 3 seconds to read each frame!
I used the following code:
vfile='~/work/dataset/VIRAT_training/VIRAT_S_000002.mp4';
vr= vision.VideoFileReader(vidFile,'VideoOutputDataType','uint8')
vr.info
vr.reset
frame= 0;
while ~isDone(vr)
frame= frame+1;
tic; rawimg= step(vr); sec=toc;
fprintf('[%d] %.2f\n', frame, sec);
end
I obtained the following output:
[1] 0.12
[2] 0.13
[3] 0.14
[4] 0.17
[5] 0.17
[6] 0.19
[7] 0.21
[8] 0.22
[9] 0.25
...
[100] 1.57
[101] 1.57
[102] 1.61
[103] 1.60
[104] 1.61
...
[200] 3.02
[201] 3.04
[202] 3.05
[203] 3.05
[204] 3.06
...
[247] 3.76
[248] 3.69
[249] 0.11
[250] 0.11
[251] 0.11
[252] 0.14
(and it slows down again)
I imagined step function to read video frame sequentially by increasing the internal file pointer, which I expected to be better than read function.
Why is it slow, and what would be the best way to read video frames efficiently? Currently, it is literally unusable for my research as I even have video files larger than 1 GB. Saving all the frames into BMP or PNG is also not a feasible work-around for me, as it literally requires terabytes for disk. All I want is to simply read images from a video file with reasonable speed, not like 3 seconds for each frame.
I really need to solve this problem as soon as possible. Any advice would be greatly appreciated.

Akzeptierte Antwort

dbdq
dbdq am 18 Mär. 2014
Ok, finally I moved on to Python + OpenCV environment and now it's almost as efficient as C++ with the support of much more useful features.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by