使用ffmpeg从视频序列中删除帧

时间:2014-07-02 14:35:19

标签: matlab video ffmpeg frame-rate

我有一个视频序列,比方说seq.mp4。该序列由帧f_1,f_2,...,f_n组成,我希望使用ffmpeg对序列进行重新编码,使得新序列仅由帧的子集组成,特别是,新序列应仅由帧f_组成( u * k),其中u = 1,...,m和m max,使得k * m <= n。这里,k> = 1是自然数。

我怎么能用ffmpeg做到这一点?

所以在Matlab中我会做以下事情:

[str_file,str_path] =  uigetfile('*','choose video file');
filename_video_in=fullfile(strcat(str_path,str_file));
sFrames=  newid('Sub Frames','Subsequence of Frames',1);
k=str2num(sFrames{1});
tmpFolder=tempname;
mkdir(tmpFolder);
video_in=VideoReader(filename_video_in);
for frame_idx=1:video_in.NumberOfFrames
   if mod(frame_idx,k) == 0
    img=read(video_in,frame_idx); 
    fileNumber=frame_idx / k;
    imwrite(img,fullfile(tmpFolder,sprintf('img%d.jpg',fileNumber))); 
   end
end

filename_video_out=strcat(filename_video_in(1:end-4),'_',num2str(k),'-    th_frame.',filename_video_in(end-3:end));
video_out=VideoWriter(filename_video_out);
open(video_out);

images=dir(fullfile(tmpFolder,'*.jpg'));
images={images.name}';
images=sort_nat(images,'ascend');


for frame_idx = 1:length(images)
     img=imread(fullfile(tmpFolder,images{frame_idx}));
     writeVideo(video_out,img);
end


close(video_out);
rmdir(tmpFolder,'s');

0 个答案:

没有答案