开发者

How to generate a video from matlab without codec errors?

Using my Windows 7 64bit machine, I'm trying to generate an avi file from Matlab us开发者_StackOverflow社区ing the sequence

aviobj = avifile('test.avi', 'fps', 25);
% a loop of aviobj = addframe(aviobj, frame)
close(aviobj)

However, the file generated is corrupt - with VLC it looks sheared and with bad colors, with Media Player it was a black screen, and with Divx Plus player it looks okay but generates a warning.

I've tried specifying other codec types (via avifile('test.avi', 'fps', 25, 'compression', 'TYPE') but Matlab never seems to be able to find that codec - I've tried Indeo and cvid and MSVC and MRLE and many more, but Matlab just generates a "not a supported compression method" warning, and then outright fails when addframe is invoked.

How can I solve the above problem, or alternatively, is there a different, simple way to just generate an avi by adding a frame at a time?


How to generate a video from matlab without codec errors?

try to use mmwrite

http://www.mathworks.com/matlabcentral/fileexchange/15881-mmwrite


Well after a few more searches online and experimentation, looks like others have encountered this problem as well, and suggested just using a different program to compress it and that should also fix the file, so that's what I did:

  1. Generated an uncompressed file
  2. Opened it in VirtualDub(good open-source video software which doesn't require installation)
  3. From the video menu I chose "compression" and selected the "Microsoft Video 1" option
  4. Saved the file via the save-as menu option

It now looks correct in all the players I've tried, and the file is smaller in size.


What you are describing what happens in VLC is probably related to having a resolution that is not supported by the codec. Try resolutions that are multiples of 2,4,8,16 and see what works. VirtualDub probably takes care of that somehow.

Otherwise it's really simple. All you have to do:

aviobj = avifile('example.avi', 'compression', 'none', 'fps', 25);
for i=1:1000
    %generating the filenames
    filename = strcat(FolderName,'/frame', sprintf('%05d', i),'.bmp'); 
    I = imread(filename);
    aviobj = addframe(aviobj,I);                                               
end;
aviobj = close(aviobj);


I know I am replying to a very old thread, but I helped my brother with this and learned a few things that might help others:

My brother had a very small video, the result of an MRI scan, 51x51 pixels. Using VideoWriter with profile "Uncompressed AVI" worked, but did not play well in VLC. Virtualdub also threw errors.

What fixed it, is making sure that the video dimensions where a multiple of 2. A 96x96 video played fine and could also be transcoded to XVID in virtualdub.

Also, with very small videos, set the video output mode to wingdi in VLC. With OpenGL or Direct3D and overlay mode, the GPU will do the scaling and interpolate pixels in between.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜