diff --git a/packages/google-cloud-videointelligence/samples/README.md b/packages/google-cloud-videointelligence/samples/README.md index fca30dac830..05da66feb4f 100644 --- a/packages/google-cloud-videointelligence/samples/README.md +++ b/packages/google-cloud-videointelligence/samples/README.md @@ -26,7 +26,7 @@ The [Cloud Video Intelligence API](https://cloud.google.com/video-intelligence) yarn install -[prereq]: ../README.md#prerequisities +[prereq]: ../README.md#prerequisites [run]: ../README.md#how-to-run-a-sample ## Samples @@ -44,17 +44,17 @@ Commands: Intelligence API. labels-gcs Labels objects in a video stored in Google Cloud Storage using the Cloud Video Intelligence API. labels-file Labels objects in a video stored locally using the Cloud Video Intelligence API. - safe-search Detects adult content in a video stored in Google Cloud Storage. + safe-search Detects explicit content in a video stored in Google Cloud Storage. Options: --help Show help [boolean] Examples: - node analyze.js faces gs://demomaker/volleyball_court.mp4 - node analyze.js shots gs://demomaker/volleyball_court.mp4 - node analyze.js labels-gcs gs://demomaker/volleyball_court.mp4 - node analyze.js labels-file cat.mp4 - node analyze.js safe-search gs://demomaker/volleyball_court.mp4 + node analyze.js faces gs://demomaker/larry_sergey_ice_bucket_short.mp4 + node analyze.js shots gs://demomaker/sushi.mp4 + node analyze.js labels-gcs gs://demomaker/tomatoes.mp4 + node analyze.js labels-file resources/cat.mp4 + node analyze.js safe-search gs://demomaker/tomatoes.mp4 For more information, see https://cloud.google.com/video-intelligence/docs ``` diff --git a/packages/google-cloud-videointelligence/samples/package.json b/packages/google-cloud-videointelligence/samples/package.json index 6a4ff41ca5b..e17c092aa4f 100644 --- a/packages/google-cloud-videointelligence/samples/package.json +++ b/packages/google-cloud-videointelligence/samples/package.json @@ -17,15 +17,14 @@ "test": "samples test run --cmd ava -- -T 5m --verbose system-test/*.test.js" }, "dependencies": { - "@google-cloud/video-intelligence": "0.1.0", - "googleapis": "19.0.0", + "@google-cloud/video-intelligence": "^0.3.2", "long": "^3.2.0", - "safe-buffer": "5.1.0", + "safe-buffer": "5.1.1", "yargs": "8.0.2" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.15", - "ava": "0.19.1", + "@google-cloud/nodejs-repo-tools": "1.4.17", + "ava": "0.22.0", "proxyquire": "1.8.0" }, "cloud-repo-tools": { diff --git a/packages/google-cloud-videointelligence/samples/quickstart.js b/packages/google-cloud-videointelligence/samples/quickstart.js index 3aeec4334ce..bb40eafe9fa 100644 --- a/packages/google-cloud-videointelligence/samples/quickstart.js +++ b/packages/google-cloud-videointelligence/samples/quickstart.js @@ -20,17 +20,15 @@ const Video = require('@google-cloud/video-intelligence'); // Instantiates a client -const video = Video({ - projectId: process.env.GCLOUD_PROJECT // Replace with your Google Cloud project ID -}); +const video = Video(); // The GCS filepath of the video to analyze -const gcsUri = 'gs://demomaker/tomatoes.mp4'; +const gcsUri = 'gs://nodejs-docs-samples-video/quickstart_short.mp4'; // Construct request const request = { inputUri: gcsUri, - features: ['FACE_DETECTION', 'LABEL_DETECTION', 'SHOT_CHANGE_DETECTION'] + features: ['LABEL_DETECTION'] }; // Execute request @@ -44,47 +42,30 @@ video.annotateVideo(request) // Gets annotations for video const annotations = results[0].annotationResults[0]; - // Gets faces for video from its annotations - const faces = annotations.faceAnnotations; - faces.forEach((face, faceIdx) => { - console.log('Thumbnail size:', face.thumbnail.length); - face.segments.forEach((segment, segmentIdx) => { - console.log(`Face #${faceIdx}, appearance #${segmentIdx}:`); - console.log(`\tStart: ${segment.startTimeOffset / 1e6}s`); - console.log(`\tEnd: ${segment.endTimeOffset / 1e6}s`); - }); - }); - // Gets labels for video from its annotations - const labels = annotations.labelAnnotations; + const labels = annotations.segmentLabelAnnotations; labels.forEach((label) => { - console.log(`Label ${label.description} occurs at:`); - const isEntireVideo = label.locations.some((location) => - location.segment.startTimeOffset.toNumber() === -1 && - location.segment.endTimeOffset.toNumber() === -1 - ); - - if (isEntireVideo) { - console.log(`\tEntire video`); - } else { - label.locations.forEach((location) => { - console.log(`\tStart: ${location.segment.startTimeOffset / 1e6}s`); - console.log(`\tEnd: ${location.segment.endTimeOffset / 1e6}s`); - }); - } - }); - - // Gets shot changes for video from its annotations - const shotChanges = annotations.shotAnnotations; - if (shotChanges.length === 1) { - console.log(`The entire video is one scene.`); - } else { - shotChanges.forEach((shot, shotIdx) => { - console.log(`Scene ${shotIdx} occurs from:`); - console.log(`\tStart: ${shot.startTimeOffset / 1e6}s`); - console.log(`\tEnd: ${shot.endTimeOffset / 1e6}s`); + console.log(`Label ${label.entity.description} occurs at:`); + label.segments.forEach((segment) => { + segment = segment.segment; + if (segment.startTimeOffset.seconds === undefined) { + segment.startTimeOffset.seconds = 0; + } + if (segment.startTimeOffset.nanos === undefined) { + segment.startTimeOffset.nanos = 0; + } + if (segment.endTimeOffset.seconds === undefined) { + segment.endTimeOffset.seconds = 0; + } + if (segment.endTimeOffset.nanos === undefined) { + segment.endTimeOffset.nanos = 0; + } + console.log(`\tStart: ${segment.startTimeOffset.seconds}` + + `.${(segment.startTimeOffset.nanos / 1e6).toFixed(0)}s`); + console.log(`\tEnd: ${segment.endTimeOffset.seconds}.` + + `${(segment.endTimeOffset.nanos / 1e6).toFixed(0)}s`); }); - } + }); }) .catch((err) => { console.error('ERROR:', err);