in source/video-analysis/lib/rekognition/base.js [348:423]
async createTrack(...args) {
const data =
((this.stateData.input || {})[BaseRekognition.ServiceType] || {})[this.keyword] || {};
if (!data.output) {
throw new AnalysisError(`missing input.${BaseRekognition.ServiceType}.${this.keyword}.output`);
}
const mappings = await this.fetchMap();
const processed = [];
/* recursively process track until lambda timeout */
do {
const name = Object.keys(mappings || {}).shift();
if (!name) {
break;
}
const {
dir,
} = PATH.parse(data.output);
/*
const responses = await Promise.all(mappings[name].map(x =>
this.downloadJson(Environment.Proxy.Bucket, PATH.join(dir, x))));
*/
const responses = await Promise.all(mappings[name].map(x =>
this.downloadSelected(Environment.Proxy.Bucket, PATH.join(dir, x), name)));
const collection = this.createCollection(name, responses);
const vtt = this.createWebVtt(name, collection);
const timelines = this.createTimelines(name, collection);
const basename = name.toLowerCase().replace(/\s/g, '_');
const vttKey = PATH.join(this.makeVttPrefix(), `${basename}.vtt`);
const metadataKey = PATH.join(this.makeMetadataPrefix(), `${basename}.json`);
await Promise.all([
CommonUtils.upload({
Bucket: Environment.Proxy.Bucket,
Key: vttKey,
ContentType: 'text/vtt',
ContentDisposition: `attachment; filename="${basename}.vtt"`,
ServerSideEncryption: 'AES256',
Body: vtt,
}),
CommonUtils.upload({
Bucket: Environment.Proxy.Bucket,
Key: metadataKey,
ContentType: 'application/json',
ContentDisposition: `attachment; filename="${basename}.json"`,
ServerSideEncryption: 'AES256',
Body: JSON.stringify(timelines.map(x => x.toJSON()), null, 2),
}),
]);
delete mappings[name];
processed.push(name);
} while (!this.stateData.quitNow());
if (!Object.keys(mappings || {}).length) {
await this.purgeMap();
this.stateData.setData(BaseRekognition.ServiceType, {
[this.keyword]: Object.assign(data, {
vtt: this.makeVttPrefix(),
metadata: this.makeMetadataPrefix(),
}),
});
this.stateData.setCompleted();
} else {
await this.updateMap(mappings);
this.stateData.setProgress(this.stateData.progress + 1);
}
return this.stateData.toJSON();
}