简体   繁体   English

在Matlab中逐帧循环播放视频文件

[英]Loop through video file frame by frame in matlab

I need to loop through a video file in matlab frame by frame manipulate every frame (for image background substracting) and save the result to a new file, I cant figure out how to do that though because i am using VideoReader and VideoWriter libs and I cant figure out how to do that. 我需要逐帧循环遍历matlab中的视频文件,处理每一帧(用于图像背景扣除),然后将结果保存到新文件中,尽管我使用的是VideoReader和VideoWriter库,但我不知道该怎么做无法弄清楚该怎么做。 DISCLAIMER - this is for a hw assignment I would like to get only the answer of how to use the VideoReader and VideoWriter in a for loop (for the whole movie) as for the image substraction - I will handle this myself... thanks in advance... 免责声明-这是针对硬件作业的,我只想了解如何在for循环中(针对整个电影)使用VideoReader和VideoWriter(针对整个电影)以及图像减法-我将自己处理...谢谢预先...

I have never needed to work on videos, but looking at the Mathworks documentation for VideoReader and VideoWriter I came up with the following code to read from an mp4 file, optionally change the video, and write to an avi file. 我从来不需要处理视频,但是在查看VideoReaderVideoWriter的Mathworks文档时,我VideoWriter了以下代码来从mp4文件中读取,可选地更改视频并写入avi文件。

vidIn = VideoReader('sample_mpeg4.mp4');
vidOut = VideoWriter('sample_out');
open(vidOut)
for ii = 1:vidIn.NumberOfFrames;
  pic = read(vidIn, ii);
  % Optional processing of 'pic' here
  writeVideo( vidOut, pic);
end
close(vidOut)

I want to note that I could not get MATLAB to read my original .avi file, however, it wrote the video just fine, and I was able to play it without a problem. 我想指出,我无法让MATLAB读取我的原始.avi文件,但是,它可以很好地编写视频,并且可以正常播放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM