小淼博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1. 转换mp4到jpg格式的图片:

% convert .mp4 to jpg picture
t='C:\Documents and Settings\luokh\桌面\Matlab编程\Matlab编程\数据资料\finger.mp4';
obj = VideoReader(t);
for i=1:20
    frame = read(obj,i);
    temp=strcat('C:\Documents and Settings\luokh\桌面\Matlab编程\Matlab编程\数据资料\fingerOUT\',num2str(i),'.','jpg');
    imwrite(frame,temp);
end
clear all
%end

2. jpg格式的图片转换到mp4:

% 读取文件夹中的所有图片
imgDir = 'path_to_images'; % 图片文件夹路径
imgFiles = dir(fullfile(imgDir, '*.png')); % 获取所有 PNG 图片文件

% 创建 VideoWriter 对象
outputVideo = VideoWriter('output_video.avi');
outputVideo.FrameRate = 30;
open(outputVideo);

% 将每一帧图片写入视频
for i = 1:length(imgFiles)
imgPath = fullfile(imgDir, imgFiles(i).name);
img = imread(imgPath);
writeVideo(outputVideo, img);
end

% 关闭视频文件
close(outputVideo);
posted on 2017-08-01 16:23  小淼博客  阅读(1777)  评论(0)    收藏  举报

大家转载请注明出处!谢谢! 在这里要感谢GISPALAB实验室的各位老师和学长学姐的帮助!谢谢~