子视频子视频以保存每第N帧

我有数千个30秒/ 20fps / .avi视频(每个视频总共600帧)。 我需要自动对这些视频进行二次采样,以便每隔100帧(每5秒)保存一次。 任何图片格式都没问题。

有没有一种简单的方法可以在Matlab(R2015b)或Python +库中执行此操作?

author: austin
采纳答案:

在MATLAB中:

你可以使用VideoWriter对象或imwrite ,取决于所需的输出格式:

vin = VideoReader('vid1.mp4');
vout = VideoWriter('vid-out.mp4');
framenum = 0;
everyNframe = 100;
vout.open();
while vin.hasFrame
    frame = vin.readFrame;
    if rem(framenum,everyNframe) == 0
        vout.writeVideo(frame);
        % OR
        imwrite(frame, [num2str(framenum,'%04i') '.jpg']);
        disp(framenum)
    end
    framenum = framenum + 1;
end
vout.close();

另一种选择ffwd输入视频到下一个所需的帧是通过设置vin.CurrentTime ,但由于某种原因它比简单读取100帧慢。

author: user2999345

参考更多解答: Subsampling videos to save every Nth frame ,转载请保留出处子视频子视频以保存每第N帧及作者信息

Statement: We respect knowledge and authors. Since the content comes from the Internet and is intended for scientific research, any reprinters should retain the author's signature and origin. If you are the author of the content and feel in dispute, please contact email: 1076545519@qq.com. We will find out the situation and deal with it in time. We sincerely thank the author for his hard work.


更多:subsampling