Why do I get black frames from a video ?
显示 更早的评论
Hi everyone,
I have some problem to extract all the frames of a video. When I run my code, it returns almost only black frames. The video is recorded in 4K, 30fps. I'm using Matlab 2015 on a macbook pro version 10.12.5.
My code is the following :
close all;
clear all;
v = VideoReader('TEST.mp4');
currAxes = axes;
framecnt = 0;
blackcnt = 0;
while hasFrame(v)
framecnt = framecnt +1;
vidFrame = readFrame(v);
image(vidFrame, 'Parent', currAxes);
currAxes.Visible = 'off';
fprintf('Extracted frame %d\n', framecnt);
pause(0.5/v.FrameRate);
if all(vidFrame(:)==0)
blackcnt= blackcnt+1;
fprintf('\t frame %d is black\n', framecnt);
end
end
fprintf('Total of %d frames extracted, %d of which black.\n',framecnt,blackcnt);
return;
Any help would be great,
Thanks
1 个评论
Walter Roberson
2017-6-30
On my MacBook Pro, R2017a, readFrame says that it cannot open the file. So does step() for Vision.VideoFileReader. But the Quicktime application is happy with the file.
回答(1 个)
Image Analyst
2017-6-30
0 个投票
I tried it with the demo video xylophone.mp4 and it worked fine - no black frames. Can you upload your video so I can try yours?
4 个评论
Guillaume Rion
2017-6-30
Image Analyst
2017-6-30
I downloaded the original resolution and see this:
Extracted frame 439
Total of 439 frames extracted, 0 of which black.
I'm using R2017a and Windows 10, 64 bit. Sorry, but I can't reproduce your situation.
Guillaune
do you mean you want to remove everything darker than the white foam dots floating on the water?
Since the floating foam is white white compared to everything else except the reflection of the fluorescent on the water, you may want to first go for the pixels that for instance have RGB>210, R>210 && G>210 && B>210.
The lighting reflection is static and the foam seems to be moving most of the time. Filtering it is not difficult either diff between consecutive frames, once white filtered.
John BG
Guillaume Rion
2017-7-1
类别
在 帮助中心 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!