Filter löschen
Filter löschen

Frame must be 1464 by 834 but why ?

23 Ansichten (letzte 30 Tage)
muhammad choudhry
muhammad choudhry am 21 Apr. 2021
Kommentiert: Walter Roberson am 26 Apr. 2021
Hi,
I am making a video from the images but I am getting error which I do not know how to deal with. Can anyone help please.
Code:
imgFiles = dir('*.jpg') ;
N = length(imgFiles) ;
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
%writerObj.FrameRate = 10;
% open the video writer
open(writerObj);
% write the frames to the video
for i=1:N
img = imgFiles(i).name ;
I = imread(img) ;
imshow(I) ;
F = getframe(gcf) ;
writeVideo(writerObj, F);
end
% close the writer object
close(writerObj);
Error:
Error using VideoWriter/writeVideo (line 368)
Frame must be 1464 by 834
Error in framesTovideo (line 21)
writeVideo(writerObj, F);

Akzeptierte Antwort

Mohammad Sami
Mohammad Sami am 26 Apr. 2021
In that case perhaps you can try writing the image directly to the video, instead of using getFrame with imshow.
imgFiles = dir('*.jpg') ;
N = length(imgFiles) ;
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
%writerObj.FrameRate = 10;
% open the video writer
open(writerObj);
% write the frames to the video
for i=1:N
img = imgFiles(i).name ;
I = imread(img) ;
writeVideo(writerObj, I);
end
% close the writer object
close(writerObj);
  1 Kommentar
Walter Roberson
Walter Roberson am 26 Apr. 2021
Yes, exactly. When you getframe(), you will not always read back exactly the same size frame, even if you are plotting the same amount of data. The frame size can vary between 2 pixels narrower than normal to 3 pixels wider than normal, based upon the absolute value of the data coordinates being used -- and this can be related to the exact width of the last text label on the axes (proportional width fonts.)
Writing directly from matrix to file is better in situations where it is practical.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Mohammad Sami
Mohammad Sami am 21 Apr. 2021
Bearbeitet: Mohammad Sami am 21 Apr. 2021
The video frame size is set by the first frame that you write. From the documentation.
"The writeVideo method sets values for Height and Width based on the dimensions of the first frame."
If your images are not the same sizes, you will have to use imresize function to resize them to the desired size.
  1 Kommentar
muhammad choudhry
muhammad choudhry am 21 Apr. 2021
Hi Sami, that is the problem, all the images in the folder are of same size 1280x720 but I am still getting this error.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by