Skip to content

Commit

Permalink
Video update (#476)
Browse files Browse the repository at this point in the history
* Speed up video tests

* Update video libraries WIP

* Make tests serial to reduce flakiness

* Remove old TODOs

* Fixes endpoint for faces

* Updates to new client library version

* update endpoint.

* Upgrades to new client library version
  • Loading branch information
Ace Nassri authored and gguuss committed Sep 21, 2017
1 parent 4f2d0fa commit 3e5f921
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 55 deletions.
14 changes: 7 additions & 7 deletions packages/google-cloud-videointelligence/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,17 +44,17 @@ Commands:
Intelligence API.
labels-gcs <gcsUri> Labels objects in a video stored in Google Cloud Storage using the Cloud Video Intelligence API.
labels-file <gcsUri> Labels objects in a video stored locally using the Cloud Video Intelligence API.
safe-search <gcsUri> Detects adult content in a video stored in Google Cloud Storage.
safe-search <gcsUri> 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
```
Expand Down
9 changes: 4 additions & 5 deletions packages/google-cloud-videointelligence/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
67 changes: 24 additions & 43 deletions packages/google-cloud-videointelligence/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 3e5f921

Please sign in to comment.