Joining jpg files to make a video

2 ビュー (過去 30 日間)
Rishav
Rishav 2014 年 3 月 10 日
回答済み: Image Analyst 2014 年 3 月 20 日
I have a certain number of sequential images in a folder named "Snaps". I want a source code in matlab so that i can join them together to make a video. Please help. p.s. I am using matlab 2010a

採用された回答

Marta Salas
Marta Salas 2014 年 3 月 10 日
編集済み: Marta Salas 2014 年 3 月 20 日
I use MATLAB2012a, you can try if this function works for you. The input arguments are: the path to the images (vide_dir), extention of the images (extension), path and name of the video with extension (aviname), and the frame rate (fps)
For example: make_video('/home/user/myImages/','jpg','myvideo.avi',5)
function make_video(video_dirs,extension,aviname,fps)
resnames=dir(fullfile(video_dirs,['*.' extension]));
aviobj=VideoWriter(aviname);
aviobj.FrameRate=fps;
open(aviobj);
for i=1:length(resnames)
img=imread(fullfile(video_dirs,resnames(i).name));
F=im2frame(img);
if sum(F.cdata(:))==0
error('black');
end
writeVideo(aviobj,F);
end
close(aviobj);
end
  3 件のコメント
Rishav
Rishav 2014 年 3 月 10 日
And you have defined the function here. From where are you calling it?
Marta Salas
Marta Salas 2014 年 3 月 10 日
編集済み: Marta Salas 2014 年 3 月 10 日
You define the function on an M-file called "make_video.m", you have to make sure the name of the file and the name of the function is the same.
Then you call the function on the MATLAB prompt or from another M-file, as the example: make_video('/home/user/myImages/','jpg','myvideo.avi',5)

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 20 日
My attached demo shows that in the latter half. First it extracts and writes out all the frames, then it reads them back in and builds the movie from the individual still images.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by