From ab88ed6a992e1beb3033ffc899b255d33f794e8b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 20 Jul 2023 22:22:20 -0700 Subject: [PATCH] fix video intelligence samples --- video/composer.json | 2 +- video/quickstart.php | 8 ++++++-- video/src/analyze_explicit_content.php | 11 ++++++----- video/src/analyze_labels_file.php | 11 ++++++----- video/src/analyze_labels_gcs.php | 11 ++++++----- video/src/analyze_object_tracking.php | 11 ++++++----- video/src/analyze_object_tracking_file.php | 11 ++++++----- video/src/analyze_shots.php | 11 ++++++----- video/src/analyze_text_detection.php | 11 ++++++----- video/src/analyze_text_detection_file.php | 11 ++++++----- video/src/analyze_transcription.php | 15 ++++++++------- 11 files changed, 63 insertions(+), 50 deletions(-) diff --git a/video/composer.json b/video/composer.json index b9107ccffb..37e39e3a85 100644 --- a/video/composer.json +++ b/video/composer.json @@ -2,7 +2,7 @@ "name": "google/video-sample", "type": "project", "require": { - "google/cloud-videointelligence": "^1.5" + "google/cloud-videointelligence": "^1.14" }, "require-dev": { "google/cloud-core": "^1.23" diff --git a/video/quickstart.php b/video/quickstart.php index 3997f87889..589df8a746 100644 --- a/video/quickstart.php +++ b/video/quickstart.php @@ -19,7 +19,8 @@ require __DIR__ . '/vendor/autoload.php'; # [START video_quickstart] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; use Google\Cloud\VideoIntelligence\V1\Feature; # Instantiate a client. @@ -31,7 +32,10 @@ 'inputUri' => 'gs://cloud-samples-data/video/cat.mp4', 'features' => $features ]; -$operation = $video->annotateVideo($options); +$request = (new AnnotateVideoRequest()) + ->setInputUri($options['inputUri']) + ->setFeatures($options['features']); +$operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete(); diff --git a/video/src/analyze_explicit_content.php b/video/src/analyze_explicit_content.php index 4612798b65..0e57de9a96 100644 --- a/video/src/analyze_explicit_content.php +++ b/video/src/analyze_explicit_content.php @@ -25,7 +25,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_analyze_explicit_content] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; use Google\Cloud\VideoIntelligence\V1\Likelihood; @@ -39,10 +40,10 @@ function analyze_explicit_content(string $uri, int $pollingIntervalSeconds = 0) # Execute a request. $features = [Feature::EXPLICIT_CONTENT_DETECTION]; - $operation = $video->annotateVideo([ - 'inputUri' => $uri, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputUri($uri) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_labels_file.php b/video/src/analyze_labels_file.php index 0803bfc9c4..d0c1e7fc1a 100644 --- a/video/src/analyze_labels_file.php +++ b/video/src/analyze_labels_file.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_analyze_labels] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -36,10 +37,10 @@ function analyze_labels_file(string $path, int $pollingIntervalSeconds = 0) # Execute a request. $features = [Feature::LABEL_DETECTION]; - $operation = $video->annotateVideo([ - 'inputContent' => $inputContent, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputContent($inputContent) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_labels_gcs.php b/video/src/analyze_labels_gcs.php index 00eb2cf8e7..88dad68ad8 100644 --- a/video/src/analyze_labels_gcs.php +++ b/video/src/analyze_labels_gcs.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_analyze_labels_gcs] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -33,10 +34,10 @@ function analyze_labels_gcs(string $uri, int $pollingIntervalSeconds = 0) # Execute a request. $features = [Feature::LABEL_DETECTION]; - $operation = $video->annotateVideo([ - 'inputUri' => $uri, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputUri($uri) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_object_tracking.php b/video/src/analyze_object_tracking.php index ca342696c2..cbf7d0f744 100644 --- a/video/src/analyze_object_tracking.php +++ b/video/src/analyze_object_tracking.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_object_tracking_gcs] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -33,10 +34,10 @@ function analyze_object_tracking(string $uri, int $pollingIntervalSeconds = 0) # Execute a request. $features = [Feature::OBJECT_TRACKING]; - $operation = $video->annotateVideo([ - 'inputUri' => $uri, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputUri($uri) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_object_tracking_file.php b/video/src/analyze_object_tracking_file.php index 1b1866c11e..3ba3fa4e58 100644 --- a/video/src/analyze_object_tracking_file.php +++ b/video/src/analyze_object_tracking_file.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_object_tracking] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -36,10 +37,10 @@ function analyze_object_tracking_file(string $path, int $pollingIntervalSeconds # Execute a request. $features = [Feature::OBJECT_TRACKING]; - $operation = $video->annotateVideo([ - 'inputContent' => $inputContent, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputContent($inputContent) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_shots.php b/video/src/analyze_shots.php index bf031f453a..f695bb6d33 100644 --- a/video/src/analyze_shots.php +++ b/video/src/analyze_shots.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_analyze_shots] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -33,10 +34,10 @@ function analyze_shots(string $uri, int $pollingIntervalSeconds = 0) # Execute a request. $features = [Feature::SHOT_CHANGE_DETECTION]; - $operation = $video->annotateVideo([ - 'inputUri' => $uri, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputUri($uri) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_text_detection.php b/video/src/analyze_text_detection.php index d7de743ff3..25a66fe27e 100644 --- a/video/src/analyze_text_detection.php +++ b/video/src/analyze_text_detection.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_detect_text_gcs] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -33,10 +34,10 @@ function analyze_text_detection(string $uri, int $pollingIntervalSeconds = 0) # Execute a request. $features = [Feature::TEXT_DETECTION]; - $operation = $video->annotateVideo([ - 'inputUri' => $uri, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputUri($uri) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_text_detection_file.php b/video/src/analyze_text_detection_file.php index 1c557e3993..08f05aa85e 100644 --- a/video/src/analyze_text_detection_file.php +++ b/video/src/analyze_text_detection_file.php @@ -19,7 +19,8 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_detect_text] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; /** @@ -36,10 +37,10 @@ function analyze_text_detection_file(string $path, int $pollingIntervalSeconds = # Execute a request. $features = [Feature::TEXT_DETECTION]; - $operation = $video->annotateVideo([ - 'inputContent' => $inputContent, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputContent($inputContent) + ->setFeatures($features); + $operation = $video->annotateVideo($request); # Wait for the request to complete. $operation->pollUntilComplete([ diff --git a/video/src/analyze_transcription.php b/video/src/analyze_transcription.php index a829defa09..733cb0236f 100644 --- a/video/src/analyze_transcription.php +++ b/video/src/analyze_transcription.php @@ -19,10 +19,11 @@ namespace Google\Cloud\Samples\VideoIntelligence; // [START video_speech_transcription_gcs] -use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient; +use Google\Cloud\VideoIntelligence\V1\AnnotateVideoRequest; +use Google\Cloud\VideoIntelligence\V1\Client\VideoIntelligenceServiceClient; use Google\Cloud\VideoIntelligence\V1\Feature; -use Google\Cloud\VideoIntelligence\V1\VideoContext; use Google\Cloud\VideoIntelligence\V1\SpeechTranscriptionConfig; +use Google\Cloud\VideoIntelligence\V1\VideoContext; /** * @param string $uri The cloud storage object to analyze (gs://your-bucket-name/your-object-name) @@ -42,11 +43,11 @@ function analyze_transcription(string $uri, int $pollingIntervalSeconds = 0) # execute a request. $features = [Feature::SPEECH_TRANSCRIPTION]; - $operation = $client->annotateVideo([ - 'inputUri' => $uri, - 'videoContext' => $videoContext, - 'features' => $features, - ]); + $request = (new AnnotateVideoRequest()) + ->setInputUri($uri) + ->setVideoContext($videoContext) + ->setFeatures($features); + $operation = $client->annotateVideo($request); print('Processing video for speech transcription...' . PHP_EOL); # Wait for the request to complete.