Distorted frames at reading videos with large width using VideoReader()
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello dear community,
In our project we have to read a wide screen video files (with some specific resolutions). At the begin I had some problems to read mp4-videos with such large resolutions at all. After I installed the K-Lite codec pack (17.1.2) it was possible to read the mp4-videos, but then I got some strange behavior in MATLAB by reading the single frames from these videos (see the attached screenshot).

To demonstrate this behavior I add source code snippet, so evreyone can run this code and see what happens.
The code generates mp4-video file, reads the generated video again and shows just the first frame. But the decoded frame looks distorted. If I increase video width just by 2px (7710px -> 7712px), the encoding is OK. If I increase the width once again (7712px -> 7714px) it looks distorted again. There is no problem to open and play these generated videos with VLC-Player, everything seems to be OK.
What am I doing wrong? Codec problems? Should I try other codecs?
Thank you for taking time to check/solve this problem :)
%% generate video
clear all;
videoWidth = 7712; % 7710 - NOK; 7712 - OK; 7714 - NOK; 7716 - OK;
videoHeight = 1000;
frameRate = 5;
videoLength = 1; % in seconds
%% create image with some dummy content
img = uint8(zeros(videoHeight, videoWidth, 3));
value = 255;
img( 1:250 ,: ,1) = value;
img(251:500 ,: ,2) = value;
img(501:750 ,: ,3) = value;
img(751:1000 ,: ,:) = value;
img(:, 1000:2000 ,:) = 0;
img(500:600, :, :) = 0;
figNr = figure(1); set(figNr, 'Name', 'created image');
imshow(img);
%% create video
filename = ['TestVideo_' num2str(videoWidth) 'x' num2str(videoHeight) '.mp4'];
writer = VideoWriter(filename, 'MPEG-4');
disp('created file object');
writer.FrameRate = frameRate;
writer.Quality = 50;
open(writer);
totalFrames = writer.FrameRate * videoLength;
for i = 1:totalFrames
writeVideo(writer, img);
disp(['progress: ' num2str(floor(i * 100 / totalFrames)) '%']);
end
disp('all frames were written');
close(writer);
%% read the video file
% clearvars -except filename;
disp('read first frame from video file and show it');
reader = VideoReader(filename);
totalFrames = floor(reader.FrameRate * reader.Duration);
reader.CurrentTime = 0;
figNr = figure(2); set(figNr, 'NumberTitle', 2, 'Name', 'read frame');
nextFrame = reader.readFrame();
imshow(nextFrame);
disp('SCRIPT END!');
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!