如何从 matlab 生成没有编解码器错误的视频?

发布于 2024-10-18 07:31:38 字数 531 浏览 1 评论 0原文

使用我的 Windows 7 64 位机器,我尝试使用以下序列从 Matlab 生成 avi 文件

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

但是,生成的文件已损坏 - 使用 VLC 时,它看起来被剪切并且颜色很差,使用媒体播放器时它是黑屏,并且使用Divx Plus 播放器看起来不错,但会生成警告。

我尝试指定其他编解码器类型(通过 avifile('test.avi', 'fps', 25, 'compression', 'TYPE'),但 Matlab 似乎永远无法找到该编解码器- 我尝试过 Indeo、cvid、MSVC 和 MRLE 等,但 Matlab 只是生成“不支持的压缩方法”警告,然后在调用 addframe 时彻底失败

。我可以解决上述问题吗?或者,是否有一种不同的、简单的方法通过一次添加一帧来生成 avi?

Using my Windows 7 64bit machine, I'm trying to generate an avi file from Matlab using 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

蒗幽 2024-10-25 07:31:38

如何从 matlab 生成没有编解码器错误的视频?

尝试使用 mmwrite

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

How to generate a video from matlab without codec errors?

try to use mmwrite

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

清醇 2024-10-25 07:31:38

经过几次在线搜索和实验后,看起来其他人也遇到了这个问题,并建议使用不同的程序来压缩它,这也应该修复文件,所以这就是我所做的:

  1. 生成一个未压缩的文件
  2. 打开它在 VirtualDub(不错的开源视频软件,不需要安装)中,
  3. 我从视频菜单中选择了“压缩” ”并选择“Microsoft Video 1”选项
  4. 通过“另存为”菜单选项保存文件

现在在我尝试过的所有播放器中看起来都是正确的,并且文件大小更小。

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.

不奢求什么 2024-10-25 07:31:38

您所描述的 VLC 中发生的情况可能与编解码器不支持的分辨率有关。尝试使用 2,4,8,16 倍数的分辨率,看看效果如何。 VirtualDub 可能会以某种方式解决这个问题。

否则真的很简单。你所要做的就是:

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);

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);
柏拉图鍀咏恒 2024-10-25 07:31:38

我知道我正在回复一个非常旧的帖子,但我帮助了我的兄弟,并学到了一些可能对其他人有帮助的东西:

我的兄弟有一个非常小的视频,是 MRI 扫描的结果,51x51 像素。使用具有“未压缩 AVI”配置文件的 VideoWriter 可以工作,但在 VLC 中播放效果不佳。 Virtualdub 也抛出错误。

解决这个问题的方法是确保视频尺寸是 2 的倍数。
96x96 视频播放效果良好,还可以在 virtualdub 中转码为 XVID。

另外,对于非常小的视频,请在 VLC 中将视频输出模式设置为 wingdi。使用 OpenGL 或 Direct3D 和叠加模式,GPU 将进行缩放并在其间插入像素。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文