1. 程式人生 > >ffmpeg從視訊提取圖片序列

ffmpeg從視訊提取圖片序列

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