Skip to content

Commit 1378702

Browse files
author
Ace Nassri
authored
Switch to faster videos + update print statements (#395)
1 parent c23a06e commit 1378702

2 files changed

Lines changed: 38 additions & 25 deletions

File tree

packages/google-cloud-videointelligence/samples/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
"scripts": {
1515
"lint": "samples lint",
1616
"pretest": "npm run lint",
17-
"system-test": "ava -T 10m --verbose system-test/*.test.js",
17+
"system-test": "ava -T 5m --verbose system-test/*.test.js",
1818
"test": "npm run system-test"
1919
},
2020
"dependencies": {
21-
"@google-cloud/videointelligence": "https://storage.googleapis.com/videointelligence-alpha/videointelligence-nodejs.tar.gz",
21+
"@google-cloud/video-intelligence": "0.1.0",
2222
"googleapis": "19.0.0",
23+
"long": "^3.2.0",
2324
"safe-buffer": "5.0.1",
2425
"yargs": "7.1.0"
2526
},

packages/google-cloud-videointelligence/samples/quickstart.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

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

2222
// Instantiates a client
23-
const video = Video.videoIntelligenceServiceClient({
23+
const video = Video({
2424
projectId: process.env.GCLOUD_PROJECT // Replace with your Google Cloud project ID
2525
});
2626

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

3030
// Construct request
3131
const request = {
@@ -48,42 +48,54 @@ video.annotateVideo(request)
4848
const faces = annotations.faceAnnotations;
4949
faces.forEach((face, faceIdx) => {
5050
console.log('Thumbnail size:', face.thumbnail.length);
51-
face.segments.forEach((segment, segmentIdx) => {
52-
console.log(`Face #${faceIdx}, appearance #${segmentIdx}:`);
53-
if (segment.startTimeOffset === -1 && segment.endTimeOffset === -1) {
54-
console.log(`\tEntire video`);
55-
} else {
51+
52+
const isEntireVideo = face.segments.some((segment) =>
53+
segment.startTimeOffset.toNumber() === -1 &&
54+
segment.endTimeOffset.toNumber() === -1
55+
);
56+
57+
if (isEntireVideo) {
58+
console.log(`Face #${faceIdx}`);
59+
console.log(`\tEntire video`);
60+
} else {
61+
face.segments.forEach((segment, segmentIdx) => {
62+
console.log(`Face #${faceIdx}, appearance #${segmentIdx}:`);
5663
console.log(`\tStart: ${segment.startTimeOffset / 1e6}s`);
5764
console.log(`\tEnd: ${segment.endTimeOffset / 1e6}s`);
58-
}
59-
});
65+
});
66+
}
6067
});
6168

6269
// Gets labels for video from its annotations
6370
const labels = annotations.labelAnnotations;
6471
labels.forEach((label) => {
6572
console.log(`Label ${label.description} occurs at:`);
66-
label.locations.forEach((location) => {
67-
if (location.segment.startTimeOffset === -1 && location.segment.endTimeOffset === -1) {
68-
console.log(`\tEntire video`);
69-
} else {
73+
const isEntireVideo = label.locations.some((location) =>
74+
location.segment.startTimeOffset.toNumber() === -1 &&
75+
location.segment.endTimeOffset.toNumber() === -1
76+
);
77+
78+
if (isEntireVideo) {
79+
console.log(`\tEntire video`);
80+
} else {
81+
label.locations.forEach((location) => {
7082
console.log(`\tStart: ${location.segment.startTimeOffset / 1e6}s`);
7183
console.log(`\tEnd: ${location.segment.endTimeOffset / 1e6}s`);
72-
}
73-
});
84+
});
85+
}
7486
});
7587

7688
// Gets shot changes for video from its annotations
7789
const shotChanges = annotations.shotAnnotations;
78-
shotChanges.forEach((shot, shotIdx) => {
79-
console.log(`Scene ${shotIdx} occurs from:`);
80-
if (shot.startTimeOffset === -1 && shot.endTimeOffset === -1) {
81-
console.log(`\tEntire video`);
82-
} else {
90+
if (shotChanges.length === 1) {
91+
console.log(`The entire video is one scene.`);
92+
} else {
93+
shotChanges.forEach((shot, shotIdx) => {
94+
console.log(`Scene ${shotIdx} occurs from:`);
8395
console.log(`\tStart: ${shot.startTimeOffset / 1e6}s`);
8496
console.log(`\tEnd: ${shot.endTimeOffset / 1e6}s`);
85-
}
86-
});
97+
});
98+
}
8799
})
88100
.catch((err) => {
89101
console.error('ERROR:', err);

0 commit comments

Comments
 (0)