movie2avi has been removed
Mostrar comentarios más antiguos
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
imageData=data';
imshow(uint8(imageData), 'Border', 'tight');
set(fig,'Position',[1,1,1692,480]);
M(:,:,count)=getframe(fig);%getframe(data);
frame=frame+1;
if(count==100)
count=1;
%movie2avi(M,'framefile.avi','fps', 15, 'compression', 'None');
%movie2avi(M,'filename.avi','fps', 35, 'compression', 'Cinepak');
vw = VideoWriter('filename.avi');
open(vw);
writeVideo(vw,M);
close(vw);
%fileName = sprintf('video%d.avi',videoId);
%movefile('filename.avi',fileName);
videoId=videoId+1;
clear M;
else
Respuesta aceptada
Más respuestas (3)
Harish Ramachandran
el 29 de Oct. de 2018
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');
open (v);
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);
hold on
drawnow;
frame = getframe (gcf);
writeVideo (v, frame);
hold off;
end
close (v)
2 comentarios
Siddharth Kurkure
el 30 de Oct. de 2018
Guillaume
el 30 de Oct. de 2018
The error message is telling you that one of the image you're trying to write to the video has a different size than the previous one(s). Whether it's VideoWriter or movie2avi all the frames you write to the video must be the same size.
The image acquired by getframe is stored in the cdata field of the structure it retuns. So some of the M.cdata images in your code do not have the same size.
Dominique
el 12 de Feb. de 2022
Editada: Walter Roberson
el 12 de Feb. de 2022
% 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);
open(vidObj);
% Create an animation.
axis tight manual;
set(gca,'nextplot','replacechildren');
for k = 1:N
h=figure;
imshow(StrMov(k).cdata);
currFrame = getframe(h);
writeVideo(vidObj,currFrame);
close(h);
end
% Close the file.
close(vidObj);
1 comentario
Walter Roberson
el 12 de Feb. de 2022
Displaying the movie and capturing frames is unnecessary and will degrade the images.
function Mov2Avi(StrMov, sAvi)
N = size(StrMov,2);
% Prepare the new file.
vidObj = VideoWriter(sAvi);
open(vidObj);
for k = 1:N
currFrame = StrMov(k).cdata;
cmap = StrMov(k).colormap;
if ~isempty(cmap); currFrame = ind2rgb(currFrame, cmap); end
writeVideo(vidObj,currFrame);
end
% Close the file.
close(vidObj);
Sergio Ramirez Seañez
el 2 de Dic. de 2022
Editada: Walter Roberson
el 2 de Dic. de 2022
0 votos
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:(

1 comentario
Walter Roberson
el 2 de Dic. de 2022
function movie2avi(StrMov, sAvi, varargin)
N = size(StrMov,2);
% Prepare the new file.
vidObj = VideoWriter(sAvi, varargin{:});
open(vidObj);
for k = 1:N
currFrame = StrMov(k).cdata;
cmap = StrMov(k).colormap;
if ~isempty(cmap); currFrame = ind2rgb(currFrame, cmap); end
writeVideo(vidObj,currFrame);
end
% Close the file.
close(vidObj);
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!