Frame must be 1464 by 834 but why ?

39 ビュー (過去 30 日間)
muhammad choudhry
muhammad choudhry 2021 年 4 月 21 日
コメント済み: Walter Roberson 2021 年 4 月 26 日
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);

採用された回答

Mohammad Sami
Mohammad Sami 2021 年 4 月 26 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 26 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Mohammad Sami
Mohammad Sami 2021 年 4 月 21 日
編集済み: Mohammad Sami 2021 年 4 月 21 日
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 件のコメント
muhammad choudhry
muhammad choudhry 2021 年 4 月 21 日
Hi Sami, that is the problem, all the images in the folder are of same size 1280x720 but I am still getting this error.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by