Reputation: 315
How can I convert a matrix to a video file? Specifically in the yuv format. Or convert it to .avi first then going to yuv. Does anyone have codes for this? It was originally an .avi file then I extracted all the frames into an array or structure.
I found this on stack overflow and used it. I created a 4D structure in Matble [height width Y/U/V numberOfFrames]. I'm using qcif so it's size is [176 144 3 150] but the video created was erroneous. (all white) Should I convert it to RGB first?
Orig; % 3D matrix
X = permute(Orig,[1 2 4 3]); % 4D matrix
movie = immovie(X,map); % map is the colormap you want to use
implay(movie);
Also, in my program, the original YUV file was first converted to avi. So my structure of frames are from an avi file.
Upvotes: 0
Views: 3096
Reputation: 45752
I think it should be something like this:
aviobj = avifile('example.avi','compression','None');
for frame = 1:size(M, 4)
aviobj = addframe(aviobj, M(:,:,:,frame); %// This is assuming your image is a vector of RGB images. If it's a vector of indexed images then drop one : and make the loop go to size(M,3)
end
aviobj = close(aviobj);
Upvotes: 1