Skip to content

Commit

Permalink
wip rekognition
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlevy0 committed Dec 2, 2023
1 parent 50c66c3 commit 0e45bca
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 311 deletions.
3 changes: 3 additions & 0 deletions amplify/backend/function/S3Trigger52a3ac74/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { EQuality } from './types'

export const conf = {
rekognitionWidth: 1920,
rekognitionHeight: 1080,
rekognition: true,
region: 'eu-west-3',
nameModifier: '_edited',
batchModifier: '_batch_',
Expand Down
30 changes: 28 additions & 2 deletions amplify/backend/function/S3Trigger52a3ac74/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Handler } from 'aws-lambda'
import * as fs from 'fs/promises'
import { processVideo } from './video'
import { download, upload } from './s3'
import { getData } from './getData'
import StatusUploader from './StatusUploader'
import { EStatus, LambdaS3Event } from './types'
import { EStatus, LambdaS3Event, IShot } from './types'
import { cleanTempFiles } from './utils'
import { conf } from './config'
import { analyzeVideo } from './rekognition'

export const handler: Handler = async (event: LambdaS3Event) => {
const statusUploader = StatusUploader.getInstance()
Expand All @@ -18,8 +21,31 @@ export const handler: Handler = async (event: LambdaS3Event) => {
processedObjectKey: newKey,
objectKey: objKey,
} = await getData(event)

let shots: IShot[]

if (conf.rekognition) {
try {
const _shots = await analyzeVideo(
objKey,
bK,
conf.rekognitionWidth,
conf.rekognitionHeight,
)
console.log({ _shots })
if (shots) {
shots = _shots
}
} catch (error) {
console.log(`analyzeVideo ERROR : ${error}`);
}
} else {
const cropData = JSON.parse(await fs.readFile(conf.cropFile, 'utf-8'))
shots = cropData.shots
}

await download(bK, objKey, tmpFP)
await processVideo(tmpFP, outputFP)
await processVideo(tmpFP, outputFP, shots)
await upload(outputFP, bK, newKey)
await cleanTempFiles(tmpFP, outputFP)
await statusUploader.setStatus(EStatus.Succeded)
Expand Down
Loading

0 comments on commit 0e45bca

Please sign in to comment.