Filter löschen
Filter löschen

How do you format file names in a Mac?

18 Ansichten (letzte 30 Tage)
Kathryn Liberman
Kathryn Liberman am 28 Nov. 2018
Verschoben: Voss am 2 Jan. 2024
I'm trying to format a code originally written for a Windows platform to a Mac platform. I changed the file names to make the code work with my specific video files, but the code returns with errors with the file names. I'm not familiar with coding syntax in general, but I realize that it may not be the same file separators or file path in a Mac as it is on Windows or Linux platforms. I did add my file folder and subsequent folders to the pathway, but am still receiving error messages. I think this might be because I do not list the file name correctly in the code. I've tried to define directories or build file names using the filesep command before the VideoReader loop, but I still received errors similar to the one below.
The error:
Error using VideoReader/init (line 442)
The filename specified was not found in the MATLAB path.
Error in VideoReader (line 146)
obj.init(fileName);
This is the section of code where the errors are. The complete file pathway for the first individual video (copied from the Mac) is '/Volumes/SeaLiceVideos2/11Oct18collection/Lice1/Lice1.MP4', but I need to access multiple sequential videos for the code loop to process all of them.
%% code for pulling out video frames
for i= 1:1
liceVideo=VideoReader(['/Volumes/SeaLiceVideos2/11Oct18collection/Lice1' num2str(i) '/' num2str(i) '.MP4']);
%% need to replace forward slashes with backslash?? Maybe use filesep command.
%% Need to access multiple sequential video files in separate folders, i.e. 'Lice1', 'Lice2', 'Lice3'... KAL
ii = 1;
while hasFrame(liceVideo)
img = readFrame(liceVideo);
filename = [sprintf('%03d',ii) '.jpg'];
fullname = fullfile(['Volumes', 'SeaLiceVideos2', '11Oct18collection', 'Lice1', 'Lice1.MP4' num2str(i) ''],'frames',filename);
imwrite(img,fullname) % Write out to a JPEG file (img1.jpg, img2.jpg, etc.)
ii = ii+1;
end
Thanks for any help, I appreciate it!

Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 28 Nov. 2018
Verschoben: Voss am 2 Jan. 2024
You've got a few typos in your filename generator not related to file separators... for example, when i = 1, you build the file name
'/Volumes/SeaLiceVideos2/11Oct18collection/Lice11/1.MP4'
To make this platform-independent, try fullfile. Also, sprintf is often a clearer option than lots of num2str concatenations:
liceFile = fullfile(filesep, 'Volumes', 'SeaLiceVideos2', '11Oct18collection', ...
sprintf('Lice%d', i), sprintf('Lice%d.MP4', i));
  1 Kommentar
Kathryn Liberman
Kathryn Liberman am 28 Nov. 2018
Verschoben: Voss am 2 Jan. 2024
Thanks! I tried this, and it seems to have resolved the filename issue. Now I just have to resolve a separate issue with my R2014a version not recognizing certain functions. I'll try running the code in R2018b and see if that resolves the issue. Thanks again! :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by