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
3131const 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