1. 程式人生 > >matlab讀mp4截圖或轉gif

matlab讀mp4截圖或轉gif

從mp4裡面匯出圖片的暫行辦法。。。

clear
close all
clc

videoObj=VideoReader('x:\DCIM\2016.mp4');
%gifFileName='test01.gif';
vo=VideoReader('x:\DCIM\2016.mp4');
videoFrames=get(vo,'NumberOfFrames');
clear vo;
disp(['This video has ',num2str(videoFrames),' frames in total.']);
videoDuration=get(videoObj,'Duration');
disp
(['Total duration : ',num2str(videoDuration),' seconds.']); pickFrameTime=12.5; disp(['Time of the choosed frame: ',num2str(pickFrameTime)]); videoObj.CurrentTime=min(pickFrameTime,videoObj.Duration); img=readFrame(videoObj); figure, image(img) axis image pickFrameTime=8.5; disp(['Time of the choosed frame: '
,num2str(pickFrameTime)]
); videoObj.CurrentTime=min(pickFrameTime,videoObj.Duration); img=readFrame(videoObj); figure, image(img) axis image % imwrite(img,'test01.png','png') % % scrsz = get(0,'ScreenSize'); % hb=figure(1);%'Position',[150 50 scrsz(3)-200 scrsz(4)-200],'color','white'); % % % Preallocate movie structure.
% nFrames=450+80; % mov(1:nFrames) = struct('cdata', [],'colormap', []); % % ki=200; % k=ki-1; % while k<=nFrames % k=k+1; % img=readFrame(videoObj);%(videoObj,k);%Frame % if k==ki || mod(k,5)==1 % [ind,mapi]=rgb2ind(img,64); % imagesc(imrotate(ind,-90)); % axis image % colormap(mapi) % box off % set(gca,'xtick',[],'ytick',[]) % % ax = gca; % ax.Units = 'pixels'; % pos = ax.Position; % ti = ax.TightInset; % rect = [123-ti(1), -ti(2), pos(3)+ti(1)+ti(3)-243, pos(4)+ti(2)+ti(4)]; % % mov(k) = getframe(ax,rect);%getframe;%(hb);%,[165 80 scrsz(3)-590 scrsz(4)-330]); % [Inx,cmap]=rgb2ind(mov(k).cdata,256); % end % % if k==ki % imwrite(Inx,cmap,gifFileName,'gif','DelayTime',0.25,'LoopCount',Inf) % else % if mod(k,5)==1 % imwrite(Inx,cmap,gifFileName,'gif','WriteMode','append','DelayTime',0.15) % end % end % %pause(0.1) % end % %