ffmpeg从视频提取图片序列

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuluhui123/article/details/81138123

ffmpeg for windows下载地址:

https://pan.baidu.com/s/1e7ijrcu1wRWUANjNj4S00g

下载完后,将ffmpeg可执行文件所在的目录添加到环境变量中。

下面给出的是利用matlab调用ffmpeg进行批量处理的代码:


exe_cmd = 'ffmpeg';
root_path = 'E:/eclipse_workplace/test1/src/test/lstm_activity_recognition/UCF-101';
speed = '30';

activity_class_list = dir(root_path);
activity_class_list = activity_class_list(3:end); % remove '.' and '..'
nclass = length(activity_class_list);
class_names = cell(nclass,1);
for i = 1:length(activity_class_list)
    class_names{i} =  activity_class_list(i).name;
    each_class_set = dir([root_path '/' class_names{i} '/*.avi']);
    for j = 1:length(each_class_set)
        avi_name = each_class_set(j).name;
        s = strfind(avi_name,'.avi');
        avi_name_pre = avi_name(1:s-1);
        img_path = [root_path '/' class_names{i} '/' avi_name_pre];
        if ~exist(img_path,'dir')
            mkdir(img_path);
        end
        avi_input = [root_path '/' class_names{i} '/' each_class_set(j).name];
        img_output = [img_path '/' avi_name_pre '.%4d.jpg'];

        cmd_line = [exe_cmd ' -i ' avi_input ' -r ' speed ' ' img_output];
        system(cmd_line);
        disp([num2str(i) ':'  num2str(j)]);
    end

end

% imgpath = 'v_ApplyEyeMakeup_g01_c01/';
% imglist = dir([imgpath '/*.jpg']);
% disp([num2str(length(imglist)) '张图像!']);
% for i = 1:length(imglist)
%     imgname = [imgpath imglist(i).name];
%     img = imread(imgname);
%     imshow(img);
%     pause(0.01);
%
% end

猜你喜欢

转载自blog.csdn.net/xuluhui123/article/details/81138123