matlab 图片合成视频

分享一段图片合成视频的matlab代码

由两个文件组成:(1)pic2video.m(2)loadImgSequenceInfo.m

内容分别如下:

(1)pic2video.m

video_path = uigetdir('J:/','请选择图片所在文件夹');
video_path=strrep(video_path, '\', '/');
folderName=regexp(video_path, '/', 'split');
folderName=folderName{end};
video_path=[video_path '/'];
[img_files] =loadImgSequenceInfo(video_path);
dname=uigetdir('J:/','保存到');
savefile=[dname '\' folderName '.avi'];
aviobj = VideoWriter(savefile);
%aviobj.Quality = 100;
aviobj.FrameRate = 25;
open(aviobj);
%aviobj.compression='None';
upbound=numel(img_files) ;
for i=1:upbound  ;%此处修改成自己的范围,起始位置
    
    disp(['正在处理第' num2str(i) '帧,共' num2str(upbound) '帧']);
    adata=imread([video_path img_files{i}]);
    frame=im2frame(adata);
    writeVideo(aviobj,frame);
end
close(aviobj);
disp([folderName '.avi' 'done sucessfully']);
(2)loadImgSequenceInfo.m

function [img_files] = load_video_info(video_path)
text_files = dir([video_path '*_frames.txt']);
	if ~isempty(text_files),
		f = fopen([video_path text_files(1).name]);
		frames = textscan(f, '%f,%f');
		fclose(f);
		
		%see if they are in the 'imgs' subfolder or not
		if exist([video_path num2str(frames{1}, 'imgs/img%05i.png')], 'file'),
			video_path = [video_path 'imgs/'];
		elseif ~exist([video_path num2str(frames{1}, 'img%05i.png')], 'file'),
			error('No image files to load.')
		end
		
		%list the files
		img_files = num2str((frames{1} : frames{2})', 'img%05i.png');
		img_files = cellstr(img_files);
	else
		%no text file, just list all images
		img_files = dir([video_path '*.png']);
		if isempty(img_files),
			img_files = dir([video_path '*.jpg']);
			assert(~isempty(img_files), 'No image files to load.')
		end
		img_files = sort({img_files.name});
	end
end

点我去下载文件

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值