How do I convert my video (>2 GB) to uncompressed AVI grayscale in MATLAB 7.12 (R2011a)?
11 views (last 30 days)
Show older comments
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?
Accepted Answer
MathWorks Support Team
on 26 Jul 2011
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);
0 Comments
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!