MATLAB: How to convert the video (>2 GB) to uncompressed AVI grayscale in MATLAB 7.12 (R2011a)

aviconvertMATLABvideowriter

I need to convert my video that is greater than 2 GB to an uncompressed AVI. I want the video to be in grayscale. How can I go this in MATLAB?

Best Answer

In order to use the VideoWriter to create an uncompressed AVI in grayscale, you need to create a VideoWriter object with the profile set to 'Uncompressed AVI'. Then create a movie structure that has grayscale frames by using the RGB2GRAY function and use the WRITEVIDEO function to write the frames in the movie to the AVI file. Then close the VideoWriter object using the CLOSE function.
Please refer to the following sample code:
% Read sample video.
xyloObj = VideoReader('xylophone.mpg');
% Get details.
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
% Define colormap
map = [(0:255)' (0:255)' (0:255)']/255;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 'uint8'),'colormap', map);
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = rgb2gray(read(xyloObj, k));
end
% Prepare the new file.
vidObj = VideoWriter('videowrite.avi','Uncompressed AVI');
open(vidObj);
% Write video
writeVideo(vidObj, mov);
% Close video writer object
close(vidObj);
Related Question