writing multiple video files in a folder
1 次查看(过去 30 天)
显示 更早的评论
I have some videos suppose 10 in number like 1.avi, 2.avi,...,9.avi,10.avi. I am reading those videos, then extracting their frames and then doing some processing on the frames using a for loop. Using these processed frames of the input videos, I want to write these 10 videos (these will be containing the processed frames) again with the name out1.avi, out2.avi,..., out9.avi,out10.avi. I am trying to write the videos using VideoWriter object but it is not changing with every loop. How can I get these outputs? For eg. I am writing this piece of code. In Folder I have 10 videos. I want to write output videos similarly in an other folder.
clc;
clear all;
close all;
Folder='/media/splab1/HDD_P21/codes/ISOGD/train';
s=dir(Folder);
for m=003:length(s)
vid=VideoReader(fullfile(Folder));
numframe=vid.NumberOfFrames;
for iFrame = 1:1:numframe
frames = read(vid, iFrame);
img1=rgb2lab(frames);
outputVideo = VideoWriter('m.avi');
outputVideo.FrameRate = vid.FrameRate;
open(outputVideo);
writeVideo(outputVideo,img1);
close(outputVideo)
end
end
If the question is not clear, feel free to comment.
0 个评论
采纳的回答
Ameer Hamza
2020-11-11
编辑:Ameer Hamza
2020-11-11
This shows a general method to manipulate multiple files: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html. For your case, you can do something like this
files = dir('*.avi');
for i = 1:numel(files)
vi = VideoReader(files(i).name);
outFilename = sprintf('out%d.avi', i);
vo = VideoWriter(outFilename, 'Uncompressed AVI');
open(vo)
while hasFrame(vi)
frame = readFrame(vi);
% process the frame
writeVideo(vo, frame);
end
close(vo);
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!