| 14 | |
| 15 | 'use strict'; |
| 16 | async function main() { |
| 17 | // [START video_quickstart] |
| 18 | // Imports the Google Cloud Video Intelligence library |
| 19 | const videoIntelligence = require('@google-cloud/video-intelligence'); |
| 20 | |
| 21 | // Creates a client |
| 22 | const client = new videoIntelligence.VideoIntelligenceServiceClient(); |
| 23 | |
| 24 | // The GCS uri of the video to analyze |
| 25 | const gcsUri = 'gs://cloud-samples-data/video/cat.mp4'; |
| 26 | |
| 27 | // Construct request |
| 28 | const request = { |
| 29 | inputUri: gcsUri, |
| 30 | features: ['LABEL_DETECTION'], |
| 31 | }; |
| 32 | |
| 33 | // Execute request |
| 34 | const [operation] = await client.annotateVideo(request); |
| 35 | |
| 36 | console.log( |
| 37 | 'Waiting for operation to complete... (this may take a few minutes)' |
| 38 | ); |
| 39 | |
| 40 | const [operationResult] = await operation.promise(); |
| 41 | |
| 42 | // Gets annotations for video |
| 43 | const annotations = operationResult.annotationResults[0]; |
| 44 | |
| 45 | // Gets labels for video from its annotations |
| 46 | const labels = annotations.segmentLabelAnnotations; |
| 47 | labels.forEach(label => { |
| 48 | console.log(`Label ${label.entity.description} occurs at:`); |
| 49 | label.segments.forEach(segment => { |
| 50 | segment = segment.segment; |
| 51 | console.log( |
| 52 | `\tStart: ${segment.startTimeOffset.seconds}` + |
| 53 | `.${(segment.startTimeOffset.nanos / 1e6).toFixed(0)}s` |
| 54 | ); |
| 55 | console.log( |
| 56 | `\tEnd: ${segment.endTimeOffset.seconds}.` + |
| 57 | `${(segment.endTimeOffset.nanos / 1e6).toFixed(0)}s` |
| 58 | ); |
| 59 | }); |
| 60 | }); |
| 61 | // [END video_quickstart] |
| 62 | } |
| 63 | |
| 64 | main().catch(console.error); |