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 commentaire

Walter Roberson
Walter Roberson le 30 Juin 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.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 30 Juin 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 commentaires

Guillaume Rion
Guillaume Rion le 30 Juin 2017
You can download the video at this adress : https://vimeo.com/223800643
Thanks for your help !
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.
John BG
John BG le 30 Juin 2017
Modifié(e) : John BG le 30 Juin 2017
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
Guillaume Rion le 1 Juil 2017
Thanks anyway ! I tried it with a lower video resolution on my computer and it works ... I don't understand why the videos recorded in 4K doesn't work...

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by