| 15 | 'use strict'; |
| 16 | |
| 17 | async function analyzeLabelsGCS(gcsUri) { |
| 18 | // [START video_analyze_labels_gcs] |
| 19 | // Imports the Google Cloud Video Intelligence library |
| 20 | const video = require('@google-cloud/video-intelligence').v1; |
| 21 | |
| 22 | // Creates a client |
| 23 | const client = new video.VideoIntelligenceServiceClient(); |
| 24 | |
| 25 | /** |
| 26 | * TODO(developer): Uncomment the following line before running the sample. |
| 27 | */ |
| 28 | // const gcsUri = 'GCS URI of the video to analyze, e.g. gs://my-bucket/my-video.mp4'; |
| 29 | |
| 30 | const request = { |
| 31 | inputUri: gcsUri, |
| 32 | features: ['LABEL_DETECTION'], |
| 33 | }; |
| 34 | |
| 35 | // Detects labels in a video |
| 36 | const [operation] = await client.annotateVideo(request); |
| 37 | console.log('Waiting for operation to complete...'); |
| 38 | const [operationResult] = await operation.promise(); |
| 39 | |
| 40 | // Gets annotations for video |
| 41 | const annotations = operationResult.annotationResults[0]; |
| 42 | |
| 43 | const labels = annotations.segmentLabelAnnotations; |
| 44 | labels.forEach(label => { |
| 45 | console.log(`Label ${label.entity.description} occurs at:`); |
| 46 | label.segments.forEach(segment => { |
| 47 | const time = segment.segment; |
| 48 | if (time.startTimeOffset.seconds === undefined) { |
| 49 | time.startTimeOffset.seconds = 0; |
| 50 | } |
| 51 | if (time.startTimeOffset.nanos === undefined) { |
| 52 | time.startTimeOffset.nanos = 0; |
| 53 | } |
| 54 | if (time.endTimeOffset.seconds === undefined) { |
| 55 | time.endTimeOffset.seconds = 0; |
| 56 | } |
| 57 | if (time.endTimeOffset.nanos === undefined) { |
| 58 | time.endTimeOffset.nanos = 0; |
| 59 | } |
| 60 | console.log( |
| 61 | `\tStart: ${time.startTimeOffset.seconds}` + |
| 62 | `.${(time.startTimeOffset.nanos / 1e6).toFixed(0)}s` |
| 63 | ); |
| 64 | console.log( |
| 65 | `\tEnd: ${time.endTimeOffset.seconds}.` + |
| 66 | `${(time.endTimeOffset.nanos / 1e6).toFixed(0)}s` |
| 67 | ); |
| 68 | console.log(`\tConfidence: ${segment.confidence}`); |
| 69 | }); |
| 70 | }); |
| 71 | // [END video_analyze_labels_gcs] |
| 72 | } |
| 73 | |
| 74 | async function analyzeLabelsLocal(path) { |