Small skills sharing-how to convert JPG/PNG and other format picture collections into mp4/avi and other formats video

Small skills sharing-how to convert continuous sequence picture collections in various formats such as jpg/png into videos in mp4/avi and other formats

Skill description:

Convert continuous picture sequences in various formats into video files in various formats, one sentence summary is how to convert pictures into videos

Tools needed:

MATLAB

Not much to say directly on the code:

framesPath = 'C:\Users\Du\Desktop\VisualPerception\caltech-lanes\washington2\';%图像序列所在路径,同时要保证图像大小相同
videoName = 'washington2.avi';%表示将要创建的视频文件的名字
fps = 5; %帧率
startFrame = 1; %从哪一帧开始
endFrame = 231; %哪一帧结束

if(exist('videoName','file'))
    delete videoName.avi
end

%生成视频的参数设定
aviobj=VideoWriter(videoName);  %创建一个avi视频文件对象,开始时其为空
aviobj.FrameRate=fps;

open(aviobj);%Open file for writing video data
%读入图片
for i=startFrame:endFrame
    fileName=sprintf('f%05d',i);    %根据文件名而定 我这里文件名是0001.jpg 0002.jpg ....
    frames=imread([framesPath,fileName,'.png']);
    writeVideo(aviobj,frames);
end
close(aviobj);% 关闭创建视频

Guess you like

Origin blog.csdn.net/m0_45388819/article/details/109017451