1818function analyzeFaces ( gcsUri ) {
1919 // [START analyze_faces]
2020 // Imports the Google Cloud Video Intelligence library
21- const Video = require ( '@google-cloud/videointelligence ' ) ;
21+ const Video = require ( '@google-cloud/video-intelligence ' ) ;
2222
2323 // Instantiates a client
24- const video = Video ( ) . videoIntelligenceServiceClient ( ) ;
24+ const video = Video ( ) ;
2525
2626 // The GCS filepath of the video to analyze
2727 // const gcsUri = 'gs://my-bucket/my-video.mp4';
@@ -43,15 +43,23 @@ function analyzeFaces (gcsUri) {
4343 const faces = results [ 0 ] . annotationResults [ 0 ] . faceAnnotations ;
4444 console . log ( 'Faces:' ) ;
4545 faces . forEach ( ( face , faceIdx ) => {
46- console . log ( '\tThumbnail size:' , face . thumbnail . length ) ;
47- face . segments . forEach ( ( segment , segmentIdx ) => {
48- if ( segment . startTimeOffset === - 1 && segment . endTimeOffset === - 1 ) {
49- console . log ( `\tEntire video` ) ;
50- } else {
46+ console . log ( 'Thumbnail size:' , face . thumbnail . length ) ;
47+
48+ const isEntireVideo = face . segments . some ( ( segment ) =>
49+ segment . startTimeOffset . toNumber ( ) === - 1 &&
50+ segment . endTimeOffset . toNumber ( ) === - 1
51+ ) ;
52+
53+ if ( isEntireVideo ) {
54+ console . log ( `Face #${ faceIdx } ` ) ;
55+ console . log ( `\tEntire video` ) ;
56+ } else {
57+ face . segments . forEach ( ( segment , segmentIdx ) => {
58+ console . log ( `Face #${ faceIdx } , appearance #${ segmentIdx } :` ) ;
5159 console . log ( `\tStart: ${ segment . startTimeOffset / 1e6 } s` ) ;
5260 console . log ( `\tEnd: ${ segment . endTimeOffset / 1e6 } s` ) ;
53- }
54- } ) ;
61+ } ) ;
62+ }
5563 } ) ;
5664 } )
5765 . catch ( ( err ) => {
@@ -63,10 +71,10 @@ function analyzeFaces (gcsUri) {
6371function analyzeLabelsGCS ( gcsUri ) {
6472 // [START analyze_labels_gcs]
6573 // Imports the Google Cloud Video Intelligence library
66- const Video = require ( '@google-cloud/videointelligence ' ) ;
74+ const Video = require ( '@google-cloud/video-intelligence ' ) ;
6775
6876 // Instantiates a client
69- const video = Video ( ) . videoIntelligenceServiceClient ( ) ;
77+ const video = Video ( ) ;
7078
7179 // The GCS filepath of the video to analyze
7280 // const gcsUri = 'gs://my-bucket/my-video.mp4';
@@ -88,16 +96,20 @@ function analyzeLabelsGCS (gcsUri) {
8896 const labels = results [ 0 ] . annotationResults [ 0 ] . labelAnnotations ;
8997 console . log ( 'Labels:' ) ;
9098 labels . forEach ( ( label ) => {
91- console . log ( 'Label description:' , label . description ) ;
92- console . log ( 'Locations:' ) ;
93- label . locations . forEach ( ( location ) => {
94- if ( location . segment . startTimeOffset === - 1 && location . segment . endTimeOffset === - 1 ) {
95- console . log ( `\tEntire video` ) ;
96- } else {
99+ console . log ( `Label ${ label . description } occurs at:` ) ;
100+ const isEntireVideo = label . locations . some ( ( location ) =>
101+ location . segment . startTimeOffset . toNumber ( ) === - 1 &&
102+ location . segment . endTimeOffset . toNumber ( ) === - 1
103+ ) ;
104+
105+ if ( isEntireVideo ) {
106+ console . log ( `\tEntire video` ) ;
107+ } else {
108+ label . locations . forEach ( ( location ) => {
97109 console . log ( `\tStart: ${ location . segment . startTimeOffset / 1e6 } s` ) ;
98110 console . log ( `\tEnd: ${ location . segment . endTimeOffset / 1e6 } s` ) ;
99- }
100- } ) ;
111+ } ) ;
112+ }
101113 } ) ;
102114 } )
103115 . catch ( ( err ) => {
@@ -109,11 +121,11 @@ function analyzeLabelsGCS (gcsUri) {
109121function analyzeLabelsLocal ( path ) {
110122 // [START analyze_labels_local]
111123 // Imports the Google Cloud Video Intelligence library + Node's fs library
112- const Video = require ( '@google-cloud/videointelligence ' ) ;
124+ const Video = require ( '@google-cloud/video-intelligence ' ) ;
113125 const fs = require ( 'fs' ) ;
114126
115127 // Instantiates a client
116- const video = Video ( ) . videoIntelligenceServiceClient ( ) ;
128+ const video = Video ( ) ;
117129
118130 // The local filepath of the video to analyze
119131 // const path = 'my-file.mp4';
@@ -140,16 +152,20 @@ function analyzeLabelsLocal (path) {
140152 const labels = results [ 0 ] . annotationResults [ 0 ] . labelAnnotations ;
141153 console . log ( 'Labels:' ) ;
142154 labels . forEach ( ( label ) => {
143- console . log ( 'Label description:' , label . description ) ;
144- console . log ( 'Locations:' ) ;
145- label . locations . forEach ( ( location ) => {
146- if ( location . segment . startTimeOffset === - 1 && location . segment . endTimeOffset === - 1 ) {
147- console . log ( `\tEntire video` ) ;
148- } else {
155+ console . log ( `Label ${ label . description } occurs at:` ) ;
156+ const isEntireVideo = label . locations . some ( ( location ) =>
157+ location . segment . startTimeOffset . toNumber ( ) === - 1 &&
158+ location . segment . endTimeOffset . toNumber ( ) === - 1
159+ ) ;
160+
161+ if ( isEntireVideo ) {
162+ console . log ( `\tEntire video` ) ;
163+ } else {
164+ label . locations . forEach ( ( location ) => {
149165 console . log ( `\tStart: ${ location . segment . startTimeOffset / 1e6 } s` ) ;
150166 console . log ( `\tEnd: ${ location . segment . endTimeOffset / 1e6 } s` ) ;
151- }
152- } ) ;
167+ } ) ;
168+ }
153169 } ) ;
154170 } )
155171 . catch ( ( err ) => {
@@ -161,10 +177,10 @@ function analyzeLabelsLocal (path) {
161177function analyzeShots ( gcsUri ) {
162178 // [START analyze_shots]
163179 // Imports the Google Cloud Video Intelligence library
164- const Video = require ( '@google-cloud/videointelligence ' ) ;
180+ const Video = require ( '@google-cloud/video-intelligence ' ) ;
165181
166182 // Instantiates a client
167- const video = Video ( ) . videoIntelligenceServiceClient ( ) ;
183+ const video = Video ( ) ;
168184
169185 // The GCS filepath of the video to analyze
170186 // const gcsUri = 'gs://my-bucket/my-video.mp4';
@@ -185,15 +201,16 @@ function analyzeShots (gcsUri) {
185201 // Gets shot changes
186202 const shotChanges = results [ 0 ] . annotationResults [ 0 ] . shotAnnotations ;
187203 console . log ( 'Shot changes:' ) ;
188- shotChanges . forEach ( ( shot , shotIdx ) => {
189- console . log ( `Scene ${ shotIdx } :` ) ;
190- if ( shot . startTimeOffset === - 1 && shot . endTimeOffset === - 1 ) {
191- console . log ( `\tEntire video` ) ;
192- } else {
193- console . log ( `\tStart: ${ shot . startTimeOffset } ` ) ;
194- console . log ( `\tEnd: ${ shot . endTimeOffset } ` ) ;
195- }
196- } ) ;
204+
205+ if ( shotChanges . length === 1 ) {
206+ console . log ( `The entire video is one shot.` ) ;
207+ } else {
208+ shotChanges . forEach ( ( shot , shotIdx ) => {
209+ console . log ( `Shot ${ shotIdx } occurs from:` ) ;
210+ console . log ( `\tStart: ${ shot . startTimeOffset / 1e6 } s` ) ;
211+ console . log ( `\tEnd: ${ shot . endTimeOffset / 1e6 } s` ) ;
212+ } ) ;
213+ }
197214 } )
198215 . catch ( ( err ) => {
199216 console . error ( 'ERROR:' , err ) ;
@@ -204,10 +221,10 @@ function analyzeShots (gcsUri) {
204221function analyzeSafeSearch ( gcsUri ) {
205222 // [START analyze_safe_search]
206223 // Imports the Google Cloud Video Intelligence library
207- const Video = require ( '@google-cloud/videointelligence ' ) ;
224+ const Video = require ( '@google-cloud/video-intelligence ' ) ;
208225
209226 // Instantiates a client
210- const video = Video ( ) . videoIntelligenceServiceClient ( ) ;
227+ const video = Video ( ) ;
211228
212229 // The GCS filepath of the video to analyze
213230 // const gcsUri = 'gs://my-bucket/my-video.mp4';
@@ -278,11 +295,11 @@ require(`yargs`) // eslint-disable-line
278295 { } ,
279296 ( opts ) => analyzeSafeSearch ( opts . gcsUri )
280297 )
281- . example ( `node $0 faces gs://demomaker/volleyball_court .mp4` )
282- . example ( `node $0 shots gs://demomaker/volleyball_court .mp4` )
283- . example ( `node $0 labels-gcs gs://demomaker/volleyball_court .mp4` )
298+ . example ( `node $0 faces gs://demomaker/larry_sergey_ice_bucket_short .mp4` )
299+ . example ( `node $0 shots gs://demomaker/sushi .mp4` )
300+ . example ( `node $0 labels-gcs gs://demomaker/tomatoes .mp4` )
284301 . example ( `node $0 labels-file cat.mp4` )
285- . example ( `node $0 safe-search gs://demomaker/volleyball_court .mp4` )
302+ . example ( `node $0 safe-search gs://demomaker/tomatoes .mp4` )
286303 . wrap ( 120 )
287304 . recommendCommands ( )
288305 . epilogue ( `For more information, see https://cloud.google.com/video-intelligence/docs` )
0 commit comments