Why do uncompressed AVI movies created from images using MOVIE2AVI in MATLAB 7.13 (R2011b) appear skewed and in grayscale with certain media players?

1 view (last 30 days)
I am writing image frames to a video file using the MOVIE2AVI function in MATLAB 7.13 (R2011b). I am reading images (such as PNGs) with IMREAD then capturing the frame using GETFRAME and writing to an uncompressed video using MOVIE2AVI.
The movie generates without any errors or warnings, but it is not playable using VLC Media Player on a Linux system. Opening the same file in Windows Media Player (on a Windows system) works fine, however.
I tried using alternative approaches such as using IM2FRAME or IMMOVIE, but the results are the same.
The only time this works is if the image was originally saved from MATLAB using PRINT, or the frame captured by GETFRAME comes directly from a figure generated from within MATLAB.
How can I resolve this? My code is below, for an image "my_image.png":
img = imread('my_image.png');
for i = 1:20
imshow(img);
mov(i) = getframe(gcf);
end
movie2avi(mov,'test.avi','compression','none');

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Jan 2012
In MATLAB, it is easy to create a file with a non-standard size width. For uncompressed AVI files, there are special rules for videos with a non-even width, and all media players have to follow these rules. VLC Media Player, for example, currently does not. This is generally not an issue because most video files come in standard sized resolutions like 640x480, 1280x720, etc.
There are two workarounds for this:
1. Pad their images with black pixels to get a movie in a standard resolution.
2. Use the VIDEOWRITER class to write Motion Jpeg AVI files instead of Uncompressed AVIs.
For an image "my_image.png", this can be done as follows:
img = imread('my_image.png');
vidObj = VideoWriter('test3.avi','Motion JPEG AVI');
open(vidObj);
for k = 1:20
imshow(img);
currFrame = getframe;
writeVideo(vidObj,currFrame);
end
close(vidObj);

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2011b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!