背景
最近由于處理數(shù)據(jù)集的需要姚炕,需要截取一段視頻歧焦,并將其中的視頻畫面縮小為原圖1/4。
代碼
%read the video
inputVideo = VideoReader('G:/nordland/spring.mp4');
%set the output video parameter
startFrame = 5000;
endFrame = 5010;
outputvideoName = 'G:/nordland/spring5000_6000.avi';
if(exist(outputvideoName,'file'))
delete(outputvideoName);
end
outputVideo=VideoWriter(outputvideoName);
outputVideo.FrameRate=inputVideo.FrameRate;
%handle and output the video
open(outputVideo);
for i = startFrame:endFrame
inputFrame = read(inputVideo,i);
%resize the origin size to 1/4
frame = imresize(inputFrame,0.25);
writeVideo(outputVideo,frame);
end
%close
close(outputVideo);