Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"moment": "^2.29.1",
"mousetrap": "^1.6.5",
"semver": "^7.3.5",
"sharp": "^0.32.6",
"vue": "^2.7.16",
"vue-gtag": "^1.9.1",
"vue-router": "^3.0.3",
Expand Down Expand Up @@ -111,6 +112,7 @@
"express": "^4.17.1",
"ffmpeg-ffprobe-static": "^4.4.0-rc.11",
"fs-extra": "^9.0.1",
"geotiff": "^2.1.3",
"git-describe": "^4.0.4",
"jest": "^27.0.4",
"jest-transform-stub": "^2.0.0",
Expand Down
64 changes: 60 additions & 4 deletions client/platform/desktop/backend/native/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import kpf from 'platform/desktop/backend/serializers/kpf';
import { checkMedia } from 'platform/desktop/backend/native/mediaJobs';
import {
websafeImageTypes, websafeVideoTypes, otherImageTypes, otherVideoTypes, MultiType, JsonMetaRegEx,
largeImageTypes,
} from 'dive-common/constants';
import {
JsonMeta, Settings, JsonMetaCurrentVersion, DesktopMetadata,
Expand Down Expand Up @@ -153,6 +154,33 @@ async function findImagesInFolder(path: string, glob?: string) {
};
}

/**
* findLargeImagesInFolder
* Finds TIFF/GeoTIFF/NITF files in a directory based on MIME type.
*/
async function findLargeImagesInFolder(path: string) {
const stat = await fs.stat(path);
let filePaths: string[];
if (stat.isDirectory()) {
filePaths = (await fs.readdir(path))
.map((name) => npath.join(path, name));
} else {
filePaths = [path];
}
const filteredPaths: string[] = [];
filePaths.forEach((absPath) => {
const mimetype = mime.lookup(absPath);
if (mimetype && largeImageTypes.includes(mimetype)) {
filteredPaths.push(absPath);
}
});
filteredPaths.sort(strNumericCompare);
return {
imagePaths: filteredPaths,
imageNames: filteredPaths.map((absPath) => npath.basename(absPath)),
};
}

async function _acquireLock(dir: string, resource: string, lockname: 'meta' | 'tracks') {
const release = await lockfile.lock(resource, {
stale: 5000, // 5 seconds
Expand Down Expand Up @@ -300,6 +328,13 @@ async function loadMetadata(
};
});
}
} else if (projectMetaData.type === 'large-image') {
const basePath = projectMetaData.originalBasePath;
imageData = projectMetaData.originalImageFiles.map((filename: string) => ({
url: '',
filename,
id: npath.join(basePath, filename),
} as FrameImage));
} else {
throw new Error(`unexpected project type for id="${datasetId}" type="${projectMetaData.type}"`);
}
Expand Down Expand Up @@ -925,11 +960,18 @@ async function beginMediaImport(path: string): Promise<DesktopMediaImportRespons

const stat = await fs.stat(path);
if (stat.isDirectory()) {
datasetType = 'image-sequence';
const largeImages = await findLargeImagesInFolder(path);
if (largeImages.imagePaths.length > 0) {
datasetType = 'large-image';
} else {
datasetType = 'image-sequence';
}
} else if (stat.isFile()) {
const mimetype = mime.lookup(path);
if (mimetype && mimetype === 'text/plain') {
datasetType = 'image-sequence';
} else if (mimetype && largeImageTypes.includes(mimetype)) {
datasetType = 'large-image';
} else {
datasetType = 'video';
}
Expand Down Expand Up @@ -960,8 +1002,8 @@ async function beginMediaImport(path: string): Promise<DesktopMediaImportRespons

/* TODO: Look for an EXISTING meta.json file to override the above */

if (datasetType === 'video') {
// get parent folder, since videos reference a file directly
if (datasetType === 'video' || (datasetType === 'large-image' && stat.isFile())) {
// get parent folder, since videos and single files reference a file directly
jsonMeta.originalBasePath = npath.dirname(path);
}

Expand Down Expand Up @@ -1009,8 +1051,21 @@ async function beginMediaImport(path: string): Promise<DesktopMediaImportRespons
relatedDataSearchPath = npath.dirname(path);
}
mediaConvertList = found.mediaConvertList;
} else if (datasetType === 'large-image') {
if (stat.isFile()) {
jsonMeta.originalVideoFile = npath.basename(path);
jsonMeta.originalImageFiles = [npath.basename(path)];
} else {
const found = await findLargeImagesInFolder(path);
if (found.imagePaths.length === 0) {
throw new Error(`no large image files found in ${path}`);
}
jsonMeta.originalImageFiles = found.imageNames;
}
jsonMeta.fps = 1;
jsonMeta.originalFps = 1;
} else {
throw new Error('only video and image-sequence types are supported');
throw new Error('only video, image-sequence, and large-image types are supported');
}

const { trackFileAbsPath, metaFileAbsPath } = await
Expand Down Expand Up @@ -1332,6 +1387,7 @@ export {
saveAttributes,
saveAttributeTrackFilters,
findImagesInFolder,
findLargeImagesInFolder,
findTrackandMetaFileinFolder,
getLastCalibrationPath,
saveLastCalibration,
Expand Down
Loading
Loading