how to process multiple video files from a folder

I am in the process of processing numerous video files from a folder, so I need a sample support for processing one video file at a time. I am using the following snippet, but I am getting stuck with the following additional parameter when I look at the file name, which is halting my progress. Any assistance would be greatly appreciated.
folder = 'C:\Video_file\';
files = dir(folder)
files = 0×1 empty struct array with fields: name folder date bytes isdir datenum
files.name
numel(files.name)
Error using numel
Not enough input arguments.
ans =
162 % on my windows system
I see followig output
files.name
ans =
'.' % this is NOT required
ans =
'..' % this is NOT required
ans =
'dummy1.avi'
ans =
'dummy2.avi'
Thank you very much.

4 件のコメント

Stephen23
Stephen23 2023 年 8 月 21 日
By far the simplest approach is to specify the filename (using wildcards as required) and fileextension:
F = 'C:\Video_file\';
S = dir(fullfile(F,'*.avi'))
Life is Wonderful
Life is Wonderful 2023 年 8 月 21 日
That makes sense.
I can view the files and don't notice any new syntax. Aside from that, how can I process one file at a time? If I consider
numel(S.name)
, I observe return as 46 rather than two files since I want to loop through the files one by one. Could you please help me?
Thank you very much.
Stephen23
Stephen23 2023 年 8 月 21 日
編集済み: Stephen23 2023 年 8 月 21 日
numel(S.name) % this will throw an error if S has zero/multiple elements.
"I want to loop through the files one by one"
You can simply loop over the elements of S:
S = dir(..);
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
% do whatever you want with filename F
end
Life is Wonderful
Life is Wonderful 2023 年 8 月 22 日
Thank you very @Stephen23
I could implement my solution.

サインインしてコメントする。

回答 (2 件)

Chetan Bhavsar
Chetan Bhavsar 2023 年 8 月 21 日

1 投票

files = dir('C:\Video_file\*.avi')
Image Analyst
Image Analyst 2023 年 8 月 21 日

1 投票

This is one of the most common FAQ questions, so see the FAQ:

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2023a

質問済み:

2023 年 8 月 21 日

コメント済み:

2023 年 8 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by