writing multiple video files in a folder

11 views (last 30 days)
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.

Accepted Answer

Ameer Hamza
Ameer Hamza on 11 Nov 2020
Edited: Ameer Hamza on 11 Nov 2020
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

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!