Why do I get black frames from a video ?
Show older comments
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 Comment
Walter Roberson
on 30 Jun 2017
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.
Answers (1)
Image Analyst
on 30 Jun 2017
0 votes
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 Comments
Guillaume Rion
on 30 Jun 2017
Image Analyst
on 30 Jun 2017
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
on 1 Jul 2017
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!