MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

video-intelligence/quickstart.js:16–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15'use strict';
16async 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
64main().catch(console.error);

Callers 1

quickstart.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected