gpt4 book ai didi

matlab - 在 MATLAB 中将图像文件转换为 AVI 视频

转载 作者:行者123 更新时间:2023-12-02 04:36:13 24 4
gpt4 key购买 nike

在这里,我正在尝试将图像帧转换为视频。图像帧包含在文件夹“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');

最佳答案

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

此代码将起作用。

关于matlab - 在 MATLAB 中将图像文件转换为 AVI 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21926957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com