-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metadata helper to generate metadata and keyframes preview image (#…
…59) * Add metadata helper to generate metadata and keyframes preview image * fix MediaInfo type issue, add metadata support, thumbnail and keyframes support * resume disabled tests * update actions
- Loading branch information
1 parent
36fa4cc
commit 5f5bdc6
Showing
25 changed files
with
1,434 additions
and
706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2023 IROHA LAB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const {familySync, GLIBC} = require('detect-libc'); | ||
|
||
module.exports = { | ||
extensions: [ | ||
"ts" | ||
], | ||
files: [ | ||
"src/utils/*.spec.ts", | ||
"src/services/*.spec.ts", | ||
"src/processors/*.spec.ts", | ||
"src/api-service/controller/*.spec.ts", | ||
"src/JobManager/*.spec.ts", | ||
"src/domains/*.spec.ts" | ||
], | ||
require: [ | ||
"ts-node/register" | ||
], | ||
verbose: true, | ||
workerThreads: familySync() !== GLIBC | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2023 IROHA LAB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import 'reflect-metadata'; | ||
import { Container } from 'inversify'; | ||
import test from 'ava'; | ||
import { Sentry, TYPES } from '@irohalab/mira-shared'; | ||
import { FakeSentry } from '@irohalab/mira-shared/test-helpers/FakeSentry'; | ||
import { join } from 'path'; | ||
import { projectRoot } from '../test-helpers/helpers'; | ||
import { JobMetadataHelperImpl } from './JobMetadataHelperImpl'; | ||
import { Vertex } from '../entity/Vertex'; | ||
import { copyFile, mkdir, readdir, stat, unlink } from 'fs/promises'; | ||
import { getStdLogger } from '../utils/Logger'; | ||
import { JobMetadataHelper } from './JobMetadataHelper'; | ||
import { TYPES_VM } from '../TYPES'; | ||
|
||
type Cxt = { container: Container }; | ||
const testVideoDir = join(projectRoot, 'tests'); | ||
const videoTemp = join(projectRoot, 'temp/metadata'); | ||
|
||
test.before(async (t) => { | ||
try { | ||
await stat(videoTemp); | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
await mkdir(videoTemp); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
}); | ||
|
||
test.beforeEach((t) => { | ||
const context = t.context as Cxt; | ||
const container = new Container({ autoBindInjectable: true }); | ||
context.container = container; | ||
container.bind<Sentry>(TYPES.Sentry).to(FakeSentry).inSingletonScope(); | ||
container.bind<JobMetadataHelper>(TYPES_VM.JobMetadataHelper).to(JobMetadataHelperImpl).inSingletonScope(); | ||
}); | ||
|
||
test.afterEach(async (t) => { | ||
const files = await readdir(videoTemp); | ||
for (const file of files) { | ||
await unlink(join(videoTemp, file)); | ||
} | ||
}); | ||
|
||
test('test generate metadata', async (t) => { | ||
const context = t.context as Cxt; | ||
const container = context.container; | ||
const jobMetaDataHelper = container.get(JobMetadataHelperImpl); | ||
const vertex = new Vertex(); | ||
const testVideoFilename = 'test-video-1.mp4'; | ||
vertex.outputPath = join(videoTemp, testVideoFilename); | ||
await copyFile(join(testVideoDir, testVideoFilename), vertex.outputPath); | ||
const verticesMap = {[vertex.id]: vertex}; | ||
const logger = getStdLogger(); | ||
const metadata = await jobMetaDataHelper.processMetaData(verticesMap, logger); | ||
t.true(!!metadata, 'metadata should not be null'); | ||
t.true(/^#[0-9a-f]{6}/i.test(metadata.dominantColorOfThumbnail), 'dominant color should be a string'); | ||
t.true(Number.isInteger(metadata.duration), `duration should be integer, ${metadata.duration}`); | ||
t.true(metadata.frameWidth > 0, `frameSize should be greater than 0, ${metadata.frameWidth}`); | ||
t.true(metadata.height > 0, `height should be greater than 0 ${metadata.height}`); | ||
const f = await stat(metadata.keyframeImagePathList[0]); | ||
t.true(f.isFile() && f.size > 0, 'keyframeImage should exists'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2023 IROHA LAB | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { VideoOutputMetadata } from '../domains/VideoOutputMetadata'; | ||
import { VertexMap } from '../domains/VertexMap'; | ||
import pino from 'pino'; | ||
|
||
export interface JobMetadataHelper { | ||
processMetaData(vertexMap: VertexMap, jobLogger: pino.Logger): Promise<VideoOutputMetadata>; | ||
generatePreviewImage(videoPath: string, metaData: VideoOutputMetadata, jobLogger: pino.Logger): Promise<void>; | ||
} |
Oops, something went wrong.