Skip to content

Commit

Permalink
Switch to faster videos + update print statements (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri authored May 18, 2017
1 parent c23a06e commit 1378702
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
5 changes: 3 additions & 2 deletions packages/google-cloud-videointelligence/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"system-test": "ava -T 10m --verbose system-test/*.test.js",
"system-test": "ava -T 5m --verbose system-test/*.test.js",
"test": "npm run system-test"
},
"dependencies": {
"@google-cloud/videointelligence": "https://storage.googleapis.com/videointelligence-alpha/videointelligence-nodejs.tar.gz",
"@google-cloud/video-intelligence": "0.1.0",
"googleapis": "19.0.0",
"long": "^3.2.0",
"safe-buffer": "5.0.1",
"yargs": "7.1.0"
},
Expand Down
58 changes: 35 additions & 23 deletions packages/google-cloud-videointelligence/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

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

// Instantiates a client
const video = Video.videoIntelligenceServiceClient({
const video = Video({
projectId: process.env.GCLOUD_PROJECT // Replace with your Google Cloud project ID
});

// The GCS filepath of the video to analyze
const gcsUri = 'gs://demomaker/volleyball_court.mp4';
const gcsUri = 'gs://demomaker/tomatoes.mp4';

// Construct request
const request = {
Expand All @@ -48,42 +48,54 @@ video.annotateVideo(request)
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}:`);
if (segment.startTimeOffset === -1 && segment.endTimeOffset === -1) {
console.log(`\tEntire video`);
} else {

const isEntireVideo = face.segments.some((segment) =>
segment.startTimeOffset.toNumber() === -1 &&
segment.endTimeOffset.toNumber() === -1
);

if (isEntireVideo) {
console.log(`Face #${faceIdx}`);
console.log(`\tEntire video`);
} else {
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;
labels.forEach((label) => {
console.log(`Label ${label.description} occurs at:`);
label.locations.forEach((location) => {
if (location.segment.startTimeOffset === -1 && location.segment.endTimeOffset === -1) {
console.log(`\tEntire video`);
} else {
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;
shotChanges.forEach((shot, shotIdx) => {
console.log(`Scene ${shotIdx} occurs from:`);
if (shot.startTimeOffset === -1 && shot.endTimeOffset === -1) {
console.log(`\tEntire video`);
} else {
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`);
}
});
});
}
})
.catch((err) => {
console.error('ERROR:', err);
Expand Down

0 comments on commit 1378702

Please sign in to comment.