writing multiple video files in a folder

조회 수: 6 (최근 30일)
NAVNEET NAYAN
NAVNEET NAYAN 2020년 11월 11일
편집: Ameer Hamza 2020년 11월 11일
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.

채택된 답변

Ameer Hamza
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개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by