Skip to content

Commit

Permalink
Merge remote-tracking branch 'dpe/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sneeringer committed Oct 24, 2017
2 parents 949fe31 + 3e5f921 commit e16799c
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 0 deletions.
77 changes: 77 additions & 0 deletions packages/google-cloud-videointelligence/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Google Cloud Video Intelligence API Node.js Samples

[![Build](https://storage.googleapis.com/cloud-docs-samples-badges/GoogleCloudPlatform/nodejs-docs-samples/nodejs-docs-samples-videointelligence.svg)]()

The [Cloud Video Intelligence API](https://cloud.google.com/video-intelligence) allows developers to use Google video analysis technology as part of their applications.

## Table of Contents

* [Setup](#setup)
* [Samples](#samples)
* [Video Intelligence](#video-intelligence)
* [Running the tests](#running-the-tests)

## Setup

1. Read [Prerequisites][prereq] and [How to run a sample][run] first.
1. Install dependencies:

With **npm**:

npm install

With **yarn**:

yarn install

[prereq]: ../README.md#prerequisites
[run]: ../README.md#how-to-run-a-sample

## Samples

### Video Intelligence

View the [documentation][video_0_docs] or the [source code][video_0_code].

__Usage:__ `node analyze.js --help`

```
Commands:
faces <gcsUri> Analyzes faces in a video stored in Google Cloud Storage using the Cloud Video Intelligence API.
shots <gcsUri> Analyzes shot angles in a video stored in Google Cloud Storage using the Cloud Video
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 explicit content in a video stored in Google Cloud Storage.
Options:
--help Show help [boolean]
Examples:
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
```

[video_0_docs]: https://cloud.google.com/video-intelligence/docs
[video_0_code]: analyze.js

## Running the tests

1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables.

1. Run the tests:

With **npm**:

npm test

With **yarn**:

yarn test
44 changes: 44 additions & 0 deletions packages/google-cloud-videointelligence/samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "nodejs-docs-samples-videointelligence",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"engines": {
"node": ">=4.3.2"
},
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"test": "samples test run --cmd ava -- -T 5m --verbose system-test/*.test.js"
},
"dependencies": {
"@google-cloud/video-intelligence": "^0.3.2",
"long": "^3.2.0",
"safe-buffer": "5.1.1",
"yargs": "8.0.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.22.0",
"proxyquire": "1.8.0"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
"requiresProjectId": true,
"product": "video",
"samples": [
{
"id": "video",
"name": "Video Intelligence",
"file": "analyze.js",
"docs_link": "https://cloud.google.com/video-intelligence/docs",
"usage": "node analyze.js --help"
}
]
}
}
73 changes: 73 additions & 0 deletions packages/google-cloud-videointelligence/samples/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright 2017, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// [START videointelligence_quickstart]
// Imports the Google Cloud Video Intelligence library
const Video = require('@google-cloud/video-intelligence');

// Instantiates a client
const video = Video();

// The GCS filepath of the video to analyze
const gcsUri = 'gs://nodejs-docs-samples-video/quickstart_short.mp4';

// Construct request
const request = {
inputUri: gcsUri,
features: ['LABEL_DETECTION']
};

// Execute request
video.annotateVideo(request)
.then((results) => {
const operation = results[0];
console.log('Waiting for operation to complete... (this may take a few minutes)');
return operation.promise();
})
.then((results) => {
// Gets annotations for video
const annotations = results[0].annotationResults[0];

// Gets labels for video from its annotations
const labels = annotations.segmentLabelAnnotations;
labels.forEach((label) => {
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);
});
// [END videointelligence_quickstart]

0 comments on commit e16799c

Please sign in to comment.