PHP code example of google / cloud-videointelligence
1. Go to this page and download the library: Download google/cloud-videointelligence library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
google / cloud-videointelligence example snippets
use Google\Cloud\VideoIntelligence\V1\VideoIntelligenceServiceClient;
use Google\Cloud\VideoIntelligence\V1\Feature;
$videoIntelligenceServiceClient = new VideoIntelligenceServiceClient();
$inputUri = "gs://example-bucket/example-video.mp4";
$features = [
Feature::LABEL_DETECTION,
];
$operationResponse = $videoIntelligenceServiceClient->annotateVideo([
'inputUri' => $inputUri,
'features' => $features
]);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$results = $operationResponse->getResult();
foreach ($results->getAnnotationResults() as $result) {
echo 'Segment labels' . PHP_EOL;
foreach ($result->getSegmentLabelAnnotations() as $labelAnnotation) {
echo "Label: " . $labelAnnotation->getEntity()->getDescription()
. PHP_EOL;
}
echo 'Shot labels' . PHP_EOL;
foreach ($result->getShotLabelAnnotations() as $labelAnnotation) {
echo "Label: " . $labelAnnotation->getEntity()->getDescription()
. PHP_EOL;
}
echo 'Frame labels' . PHP_EOL;
foreach ($result->getFrameLabelAnnotations() as $labelAnnotation) {
echo "Label: " . $labelAnnotation->getEntity()->getDescription()
. PHP_EOL;
}
}
} else {
$error = $operationResponse->getError();
echo "error: " . $error->getMessage() . PHP_EOL;
}