Skip to content

Commit 8677f76

Browse files
nnegreyjabubake
authored andcommitted
Update samples to v1 (#935)
1 parent b724502 commit 8677f76

File tree

2 files changed

+43
-47
lines changed

2 files changed

+43
-47
lines changed

video/cloud-client/src/main/java/com/example/video/Detect.java

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,21 @@
1717
package com.example.video;
1818

1919
import com.google.api.gax.longrunning.OperationFuture;
20-
import com.google.cloud.videointelligence.v1beta2.AnnotateVideoProgress;
21-
import com.google.cloud.videointelligence.v1beta2.AnnotateVideoRequest;
22-
import com.google.cloud.videointelligence.v1beta2.AnnotateVideoResponse;
23-
import com.google.cloud.videointelligence.v1beta2.Entity;
24-
import com.google.cloud.videointelligence.v1beta2.ExplicitContentFrame;
25-
import com.google.cloud.videointelligence.v1beta2.FaceAnnotation;
26-
import com.google.cloud.videointelligence.v1beta2.FaceFrame;
27-
import com.google.cloud.videointelligence.v1beta2.FaceSegment;
28-
import com.google.cloud.videointelligence.v1beta2.Feature;
29-
import com.google.cloud.videointelligence.v1beta2.LabelAnnotation;
30-
import com.google.cloud.videointelligence.v1beta2.LabelDetectionConfig;
31-
import com.google.cloud.videointelligence.v1beta2.LabelDetectionMode;
32-
import com.google.cloud.videointelligence.v1beta2.LabelSegment;
33-
import com.google.cloud.videointelligence.v1beta2.NormalizedBoundingBox;
34-
import com.google.cloud.videointelligence.v1beta2.VideoAnnotationResults;
35-
import com.google.cloud.videointelligence.v1beta2.VideoContext;
36-
import com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient;
37-
import com.google.cloud.videointelligence.v1beta2.VideoSegment;
38-
import com.google.longrunning.Operation;
20+
import com.google.cloud.videointelligence.v1.AnnotateVideoProgress;
21+
import com.google.cloud.videointelligence.v1.AnnotateVideoRequest;
22+
import com.google.cloud.videointelligence.v1.AnnotateVideoResponse;
23+
import com.google.cloud.videointelligence.v1.Entity;
24+
import com.google.cloud.videointelligence.v1.ExplicitContentFrame;
25+
import com.google.cloud.videointelligence.v1.FaceAnnotation;
26+
import com.google.cloud.videointelligence.v1.FaceFrame;
27+
import com.google.cloud.videointelligence.v1.FaceSegment;
28+
import com.google.cloud.videointelligence.v1.Feature;
29+
import com.google.cloud.videointelligence.v1.LabelAnnotation;
30+
import com.google.cloud.videointelligence.v1.LabelSegment;
31+
import com.google.cloud.videointelligence.v1.NormalizedBoundingBox;
32+
import com.google.cloud.videointelligence.v1.VideoAnnotationResults;
33+
import com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient;
34+
import com.google.cloud.videointelligence.v1.VideoSegment;
3935
import com.google.protobuf.ByteString;
4036
import java.io.IOException;
4137
import java.nio.file.Files;
@@ -105,17 +101,18 @@ public static void argsHelper(String[] args) throws Exception {
105101
*/
106102
public static void analyzeFaces(String gcsUri) throws Exception {
107103
// [START detect_faces]
108-
// Instantiate a com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient
104+
// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
109105
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
110106
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
111107
.setInputUri(gcsUri)
112108
.addFeatures(Feature.FACE_DETECTION)
113109
.build();
114110

115111
// asynchronously perform facial analysis on videos
116-
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response
117-
= client.annotateVideoAsync(request);
112+
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
113+
client.annotateVideoAsync(request);
118114

115+
System.out.println("Waiting for operation to complete...");
119116
boolean faceFound = false;
120117
for (VideoAnnotationResults results : response.get().getAnnotationResultsList()) {
121118
int faceCount = 0;
@@ -166,19 +163,19 @@ public static void analyzeFaces(String gcsUri) throws Exception {
166163
*/
167164
public static void analyzeLabels(String gcsUri) throws Exception {
168165
// [START detect_labels_gcs]
169-
// Instantiate a com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient
166+
// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
170167
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
171168
// Provide path to file hosted on GCS as "gs://bucket-name/..."
172169
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
173170
.setInputUri(gcsUri)
174171
.addFeatures(Feature.LABEL_DETECTION)
175172
.build();
176173
// Create an operation that will contain the response when the operation completes.
177-
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> operation =
174+
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
178175
client.annotateVideoAsync(request);
179176

180177
System.out.println("Waiting for operation to complete...");
181-
for (VideoAnnotationResults results : operation.get().getAnnotationResultsList()) {
178+
for (VideoAnnotationResults results : response.get().getAnnotationResultsList()) {
182179
// process video / segment level label annotations
183180
System.out.println("Locations: ");
184181
for (LabelAnnotation labelAnnotation : results.getSegmentLabelAnnotationsList()) {
@@ -248,7 +245,7 @@ public static void analyzeLabels(String gcsUri) throws Exception {
248245
*/
249246
public static void analyzeLabelsFile(String filePath) throws Exception {
250247
// [START detect_labels_file]
251-
// Instantiate a com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient
248+
// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
252249
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
253250
// Read file and encode into Base64
254251
Path path = Paths.get(filePath);
@@ -261,11 +258,11 @@ public static void analyzeLabelsFile(String filePath) throws Exception {
261258
.build();
262259

263260
// Create an operation that will contain the response when the operation completes.
264-
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> operation =
261+
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
265262
client.annotateVideoAsync(request);
266263

267264
System.out.println("Waiting for operation to complete...");
268-
for (VideoAnnotationResults results : operation.get().getAnnotationResultsList()) {
265+
for (VideoAnnotationResults results : response.get().getAnnotationResultsList()) {
269266
// process video / segment level label annotations
270267
System.out.println("Locations: ");
271268
for (LabelAnnotation labelAnnotation : results.getSegmentLabelAnnotationsList()) {
@@ -335,7 +332,7 @@ public static void analyzeLabelsFile(String filePath) throws Exception {
335332
*/
336333
public static void analyzeShots(String gcsUri) throws Exception {
337334
// [START detect_shots]
338-
// Instantiate a com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient
335+
// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
339336
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
340337
// Provide path to file hosted on GCS as "gs://bucket-name/..."
341338
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
@@ -344,12 +341,12 @@ public static void analyzeShots(String gcsUri) throws Exception {
344341
.build();
345342

346343
// Create an operation that will contain the response when the operation completes.
347-
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> operation =
344+
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
348345
client.annotateVideoAsync(request);
349-
System.out.println("Waiting for operation to complete...");
350346

347+
System.out.println("Waiting for operation to complete...");
351348
// Print detected shot changes and their location ranges in the analyzed video.
352-
for (VideoAnnotationResults result : operation.get().getAnnotationResultsList()) {
349+
for (VideoAnnotationResults result : response.get().getAnnotationResultsList()) {
353350
if (result.getShotAnnotationsCount() > 0) {
354351
System.out.println("Shots: ");
355352
for (VideoSegment segment : result.getShotAnnotationsList()) {
@@ -374,21 +371,20 @@ public static void analyzeShots(String gcsUri) throws Exception {
374371
*/
375372
public static void analyzeExplicitContent(String gcsUri) throws Exception {
376373
// [START detect_explicit_content]
377-
// Instantiate a com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient
374+
// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
378375
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
379376
// Create an operation that will contain the response when the operation completes.
380377
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
381378
.setInputUri(gcsUri)
382379
.addFeatures(Feature.EXPLICIT_CONTENT_DETECTION)
383380
.build();
384381

385-
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> operation =
382+
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
386383
client.annotateVideoAsync(request);
387384

388385
System.out.println("Waiting for operation to complete...");
389-
390386
// Print detected annotations and their positions in the analyzed video.
391-
for (VideoAnnotationResults result : operation.get().getAnnotationResultsList()) {
387+
for (VideoAnnotationResults result : response.get().getAnnotationResultsList()) {
392388
for (ExplicitContentFrame frame : result.getExplicitAnnotation().getFramesList()) {
393389
double frameTime =
394390
frame.getTimeOffset().getSeconds() + frame.getTimeOffset().getNanos() / 1e9;

video/cloud-client/src/main/java/com/example/video/QuickstartSample.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
// [START videointelligence_quickstart]
2020

2121
import com.google.api.gax.longrunning.OperationFuture;
22-
import com.google.cloud.videointelligence.v1beta2.AnnotateVideoProgress;
23-
import com.google.cloud.videointelligence.v1beta2.AnnotateVideoRequest;
24-
import com.google.cloud.videointelligence.v1beta2.AnnotateVideoResponse;
25-
import com.google.cloud.videointelligence.v1beta2.Entity;
26-
import com.google.cloud.videointelligence.v1beta2.Feature;
27-
import com.google.cloud.videointelligence.v1beta2.LabelAnnotation;
28-
import com.google.cloud.videointelligence.v1beta2.LabelSegment;
29-
import com.google.cloud.videointelligence.v1beta2.VideoAnnotationResults;
30-
import com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient;
22+
import com.google.cloud.videointelligence.v1.AnnotateVideoProgress;
23+
import com.google.cloud.videointelligence.v1.AnnotateVideoRequest;
24+
import com.google.cloud.videointelligence.v1.AnnotateVideoResponse;
25+
import com.google.cloud.videointelligence.v1.Entity;
26+
import com.google.cloud.videointelligence.v1.Feature;
27+
import com.google.cloud.videointelligence.v1.LabelAnnotation;
28+
import com.google.cloud.videointelligence.v1.LabelSegment;
29+
import com.google.cloud.videointelligence.v1.VideoAnnotationResults;
30+
import com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient;
3131
import java.util.List;
3232

3333
public class QuickstartSample {
@@ -47,12 +47,12 @@ public static void main(String[] args) throws Exception {
4747
.addFeatures(Feature.LABEL_DETECTION)
4848
.build();
4949

50-
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> operation =
50+
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
5151
client.annotateVideoAsync(request);
5252

5353
System.out.println("Waiting for operation to complete...");
5454

55-
List<VideoAnnotationResults> results = operation.get().getAnnotationResultsList();
55+
List<VideoAnnotationResults> results = response.get().getAnnotationResultsList();
5656
if (results.isEmpty()) {
5757
System.out.println("No labels detected in " + gcsUri);
5858
return;

0 commit comments

Comments
 (0)