2014-02-21 97 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. 

此代碼將工作。

相關問題