-
Notifications
You must be signed in to change notification settings - Fork 2
/
db_getFullVideoNames.m
48 lines (41 loc) · 1.52 KB
/
db_getFullVideoNames.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [ fullVideoNames, success, msg ] = db_getFullVideoNames( videoNames )
%READVIDEODBINDEXFILE Given videoNames, returns full name for the videos
% Assumes none of the given videoNames is greater than videoDbCount.
% videoNames is a horizontal vector.
%% Basic required input sanitation
videoNames = videoNames(videoNames>0);
len = length(videoNames);
%% Set initial output vars
fullVideoNames = cell(1, len);
success = true;
msg = 'getFullVideoNames: ';
%% Load dbConfig
load(db_getDbConfigFileURI());
%% Input Validation
if isempty(videoNames)
msg = [msg, 'Why was I called?'];
return;
end
%% Open videoDbRecordFile
fileID = fopen(videoDbRecordFile, 'r');
if fileID == -1
success = false;
msg = [msg, videoDbRecordFile, ': ', ferror(fileID)];
return;
end
%% For each video: Move read pointer to correct record position and retrieve fullName
for i = 1 : len
readBytePos = sizeof(headerIntType) + (videoNames(i)-1)*(videoDbRecordByteSize);
if fseek(fileID, readBytePos, 'bof') == -1
success = false;
msg = [msg, videoDbRecordFile, ': ', ferror(fileID)];
fclose(fileID);
return;
end
videoName = fread(fileID, 1, videoNameIntType);
extension = fread(fileID, maxExtensionChars, [extensionType,'=>',extensionType]);
extension = strrep(extension.', '0', '');
fullVideoNames{i} = sprintf('%d.%s', videoName, extension);
end
fclose(fileID);
end