Matlab VideoReader reading frames as green images or not at all
2 views (last 30 days)
Show older comments
I'm trying to read a video file and store the frames as a series of images. I'm using VideoReader but for some reason I'm having trouble.
Essentially I've three video files, an original (which reads fine), one compressed with VP9 using ffmpeg, and one compressed with H.624 using ffmpeg. The original video was originally just a set of frames merged into a .avi video using VirtualDub. The compressed videos are also .avi container.
The VP9 video appeared to work fine but when I open the images using imshow() they appear to be just a solid green color. The video opens fine on VLC so I'm not sure what the problem is.
The H.264 video doesn't read at all. When it attempts to enter the "while hasFrame()" loop, it skips over it which leads to believe Matlab thinks the video frames aren't there? Again, this video opens fine in VLC and the three videos look almost identical.
The image below shows the what input video looks like as well as the green frame I'm getting from the VP9 beside it, the code I'm using is below that again. Any one got any ideas why this is happening?

Code:
Main:
test_vid = 'vp9.avi';
images = readVideos(test_vid);
for i=1:length(images)
% Convert from cells to matrices
image1 = cell2mat(images(1,i));
image2 = cell2mat(images(2,i));
% Do stuff with the images here
subplot(1,2,1);
imshow(image1);
subplot(1,2,2);
imshow(image2);
end
readVideos():
function images = readVideos(test_video)
% Video directories
test_video_dir = strcat('src/', test_video);
v_original = VideoReader('src/input.avi');
v_test = VideoReader(test_video_dir);
% Read original video
i = 1;
v_original.CurrentTime = 5;
while hasFrame(v_original)
frame = readFrame(v_original);
originalImages{i} = frame;
i = i + 1;
end
% Read test video
i = 1;
v_test.CurrentTime = 5;
while hasFrame(v_test)
frame = readFrame(v_test);
testImages{i} = frame;
i = i + 1;
end
images = cat(1, originalImages, testImages);
end
2 Comments
Balaji Chandrasekaran
on 21 Jun 2020
SAME ISSUE ON 2020a -- UBUNTU 20.04LTS. i am seeing the same on .mov file
Answers (0)
See Also
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!