How do you format file names in a Mac?
8 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Kelly Kearney
2018 年 11 月 28 日
移動済み: Voss
2024 年 1 月 2 日
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));
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!