【问题标题】:Converting image files to AVI video in MATLAB在 MATLAB 中将图像文件转换为 AVI 视频
【发布时间】:2014-02-21 06:31:31
【问题描述】:

在这里,我正在尝试将图像帧转换为视频。图像帧包含在文件夹“folder_1”中。每当我尝试运行它时,我都会收到错误消息:''RIFF' 没有按预期出现'。下面是代码。这里可能有什么问题?是的,图像采用高动态范围格式。

files = dir('folder_1');
aviobj = avifile('a.avi'); %creating a movie object
for i=1:numel(files) %number of images to be read
    a = hdrread(file(i));  
    a = uint8(a);%convert the images into unit8 type
    M = im2frame(a);%convert the images into frames
    aviobj = addframe(aviobj,M);%add the frames to the avi object created previously
    fprintf('adding frame = %i\n', i);
end
disp('Closing movie file...')
aviobj = close(aviobj);
disp('Playing movie file...')
implay('a.avi');

【问题讨论】:

  • 平台和版本?
  • Matlab R2013a 学生版
  • 尝试videowriter 而不是avifile。另外,您能否确认错误发生在什么时候?在尝试创建对象时?在添加框架?在关闭对象?只有当你尝试播放它?如果是最后一个,如果在 MATLAB 之外打开 *.avi 可以播放吗?

标签: matlab video


【解决方案1】:
% Create a video writer object
writerObj = VideoWriter('Video.avi');

% Set frame rate
writerObj.FrameRate = 30;

% Open video writer object and write frames sequentially
open(writerObj)

for i = 1:30                   % Some number of frames
     % Read frame
     frame = sprintf('frame %d.jpg', i);
     input = imread(frame);

     % Write frame now
     writeVideo(writerObj, input);
end

% Close the video writer object
close(writerObj);

% 'Video.avi' will be created in the folder that contains the code.

此代码将起作用。

【讨论】:

    【解决方案2】:
    files = dir('folder_1');
    N=10;
    nframe=3000;
    writerObj = VideoWriter( 'MINALIVE .avi' );
    writerObj.FrameRate = N;
    open(writerObj);
    figure;
    for i=1:numel(files) %number of images to be read
        a = hdrread(file(i));  
        a = uint8(a);%convert the images into unit8 type
        f.cdata = a;
        f.colormap = [];
        writeVideo(writerObj,f);
    end
    close(writerObj);
    

    你可以试试这个,也许它有效!

    【讨论】:

    • 你是什么意思'也许它有效' - 你尝试过你发布的代码吗?
    猜你喜欢
    • 2023-03-04
    • 2013-05-12
    • 2015-06-14
    • 2010-09-09
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 2017-05-21
    相关资源
    最近更新 更多