Matlab:图片合成视频,视频分解成图片

图片合成视频

clc;
clear;

temp1 = 'D:\仿真程序\result_xingren\'; %图片路径
temp2 = '.jpg'; %图片后缀
WriterObj = VideoWriter('XingRen_Video.avi');   %当前文件路径合成视频
%WriterObj.FrameRate = 10;%調整幀率,這個可以改變合成視頻的長短
n_frames = 73; % 图像帧的总数
open(WriterObj);
for i=1:n_frames 
   frame = imread(strcat(temp1, num2str(i), temp2)); % 读取图片,放在变量frame中
   writeVideo(WriterObj, frame);% frame放到变量WriteObj中
end
close(WriterObj);

视频分解成图片

clc;
clear;

video_file = 'D:\XingRen.avi';
video = VideoReader(video_file);% 读取视频
frame_number = video.NumberOfFrames;% 得到帧数

for i=1:frame_number
   image_name = strcat('D:\实验使用图片\XingRen_video\', num2str(i-1));
   img_name = strcat(image_name,'.jpg');
   I = read(video, i);% 读出图片
   if i~=1
       imwrite(I, img_name, 'jpg');%写图片。保存
   end


   % imwrite(I, img_name, 'jpg');%写图片。保存
   I = [];

end

你可能感兴趣的:(MATLAB系列)