You must call
open(writerObj) before calling
When creating AVI or MPEG-4 files,
When creating Motion JPEG 2000 files,
For grayscale, monochrome, or indexed data,
Four-dimensional array of grayscale (height-by-width-by-1-by-frames) or RGB (height-by-width-by-3-by-frames) images.
Structure typically returned by the
Write a sequence of frames to a compressed
Prepare the new file.
writerObj = VideoWriter('peaks.avi'); open(writerObj);
Generate initial data and set axes and figure properties.
Z = peaks; surf(Z); axis tight set(gca,'nextplot','replacechildren'); set(gcf,'Renderer','zbuffer');
Renderer property to
around limitations of
getframe with the OpenGL® renderer
on some Windows® systems.
Create a set of frames and write each frame to the file.
for k = 1:20 surf(sin(2*pi*k/20)*Z,Z) frame = getframe; writeVideo(writerObj,frame); end close(writerObj);
Convert an example file,
to an uncompressed AVI file:
Create objects to read and write the video, and open the AVI file for writing.
readerObj = VideoReader('xylophone.mp4'); writerObj = VideoWriter('transcoded_xylophone.avi', ... 'Uncompressed AVI'); open(writerObj);
Read and write each frame.
for k = 1:readerObj.NumberOfFrames img = read(readerObj,k); writeVideo(writerObj,img); end close(writerObj);