2014-02-21 69 views
2

在这里,我试图将图像帧转换为视频。图像帧包含在文件夹'folder_1'中。无论何时我试图运行它,我都会收到错误信息:''RIFF'没有按预期显示'。以下是代码。这里有什么可能是错的?是的,图像是高动态范围格式。在MATLAB中将图像文件转换为AVI视频

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'); 
+0

平台和版本? – chappjc

+0

Matlab R2013a学生版 – user7715

+0

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

回答

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

你也许可以试试这个工作!

+0

你是什么意思'也许它有效' - 你是否尝试过你发布的代码? – acutesoftware

2
% 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. 

此代码将工作。

相关问题