movie2avi has been removed
80 ビュー (過去 30 日間)
Hi, I was trying to use movie2avi but it was removed in the 2016 release (I am working on 2017b) and I need some help trying to use the VideoWriter. The below code gave me the following error: all 'cdata' fields in FRAMES must be the same size. What exactly does that mean? How would I be able to do what movie2avi does, but in such a compatibility with 2016/later releases, since I am getting errors in my implementation?
data = fread(fid, [1692, 480], '*uchar'); %read in the data
imshow(uint8(imageData), 'Border', 'tight');
%movie2avi(M,'framefile.avi','fps', 15, 'compression', 'None');
%movie2avi(M,'filename.avi','fps', 35, 'compression', 'Cinepak');
vw = VideoWriter('filename.avi');
%fileName = sprintf('video%d.avi',videoId);
Guillaume 2018 年 10 月 30 日
The code you're showing is obviously meant to be in a loop which you haven't showned. That makes it harder to pinpoint the cause of the problem.
A red flag is this line:
getframe always return a scalar structure so it's unclear why it's being put into a 3D array. At best, dimensions 1 and 2 of the existing M are singleton, in which case the above is the same as
M(1, 1, count) = getframe(fig);
If they're not singleton, then the scalar structure will be replicated as many times as necessary to fill these dimensions. A complete waste. It looks like the code was written expecting that getframe returns a 2D image instead of the structure it returns.
The error tells you that one of the cdata field of M is not the same size as the others. So look through that structure array, see which frame has a different size, then find out why. Since we don't see how you initialise M, it's possible that you're using a M from a previous run that had a different size.
Inferring from the code you show, it looks like you never preallocate M, just let it grow to 100, then clear it. That's very inefficient and error prone. Your loop should be more something like:
%naming the variable frames instead of M since the name M doesn't say anything about the variable content
frames = struct('cdata', cell(1, 100), 'colormap', cell(1, 100)); %preallocate structure with 100 elements
count = 1;
while ... %whatever the loop code is
%code to read the image and display it. Unchanged
frames(count) = getframe(fig); %acquire frame
if count == 100
vw = VideoWriter(sprintf('filename%d.avi', videoId)); %taking a guess that you intend to modify the filename each time you write a video
videoId = videoId + 1;
count = mod(count, 100) + 1;
その他の回答 (3 件)
Harish Ramachandran 2018 年 10 月 29 日
As you mentioned, movie2avi has been deprecated and instead replaced with VideoWriter.
Can you verify if getframe CDATA is consistent in dimensions? The error message points to an issue there?
Also, a sample example code would be:
v = VideoWriter ('test.avi');
II = 0;
for I = 0: 1: 50
II = II + 1;
X = 0: 0.1: 10;% X coordinate
XWT = X + 0.2 * I;% X + 0.2 I
Y = sin (XWT);
plot (X, Y);
frame = getframe (gcf);
writeVideo (v, frame);
Dominique 2022 年 2 月 12 日
編集済み: Walter Roberson 2022 年 2 月 12 日
% 2022-02-11 : copié-collé par Dominique.Beaulieu@gmail.com
% Source : aide Matlab.
% But : pour compenser la disparition de movie2avi.
% Programmé en mode "quick and dirty".
% Entrées :
% StrMovie : structure Matlab contenant le "movie"
% Exemple :
% StrMov = MonMovie
% MonMovie ==> 1×124 struct array with fields:
% Champs :
% cdata: [428×531×3 uint8]
% colormap: 
% sAvi : chaîne de caractères (s pour string) contenant le nom du fichier
% Exemple :
% sAvi = 'MonAnimation.avi'
% Fichier : Mov2Avi.m
function Mov2Avi(StrMov, sAvi)
N = size(StrMov,2);
% Prepare the new file.
vidObj = VideoWriter(sAvi);
% Create an animation.
axis tight manual;
for k = 1:N
currFrame = getframe(h);
% Close the file.
Sergio Ramirez Seañez 2022 年 12 月 2 日
編集済み: Walter Roberson 2022 年 12 月 2 日
Hi, im trying to use this code: https://la.mathworks.com/matlabcentral/fileexchange/27212-animated-double-pendulum?s_tid=srchtitle_double%2520pendulum_2 in Matlab 2020, but only this window appears like this:(