Annota un video utilizzando la riga di comando
Questa pagina mostra come effettuare una richiesta API Video Intelligence con curl
per i progetti di tua proprietà.
Puoi seguire i passaggi in questa pagina o provare questa guida rapida come lab Formazione Google Cloud.
Prima di iniziare
- Accedi al tuo account Google Cloud. Se non conosci Google Cloud, crea un account per valutare le prestazioni dei nostri prodotti in scenari reali. I nuovi clienti ricevono anche 300 $di crediti gratuiti per l'esecuzione, il test e il deployment dei carichi di lavoro.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Assicurati che la fatturazione sia attivata per il tuo progetto Google Cloud.
-
Abilita l'API richiesta.
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Imposta la variabile di ambiente
GOOGLE_APPLICATION_CREDENTIALS
sul percorso del file JSON che contiene le tue credenziali. Questa variabile si applica solo alla sessione di shell attuale. Pertanto, se apri una nuova sessione, imposta di nuovo la variabile. - Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Assicurati che la fatturazione sia attivata per il tuo progetto Google Cloud.
-
Abilita l'API richiesta.
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Imposta la variabile di ambiente
GOOGLE_APPLICATION_CREDENTIALS
sul percorso del file JSON che contiene le tue credenziali. Questa variabile si applica solo alla sessione di shell attuale. Pertanto, se apri una nuova sessione, imposta di nuovo la variabile. - Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
Effettua una richiesta di annotazione video
gcloud
Usa gcloud CLI per chiamare il comandodetect-labels
sul percorso del video da analizzare.
gcloud ml video detect-labels gs://YOUR_BUCKET/YOUR_OBJECT
Riga di comando
Utilizza
curl
per effettuare una richiesta POST al metodovideos:annotate
, utilizzando il comandogcloud auth application-default print-access-token
per incollare un token di accesso nel tuo account di servizio:curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ --data '{"inputUri":"gs://YOUR_BUCKET/YOUR_OBJECT","features":["LABEL_DETECTION"]}'\ "https://videointelligence.googleapis.com/v1/videos:annotate"
L'API Video Intelligence crea un'operazione per elaborare la richiesta. La risposta include il nome dell'operazione:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID" }
Puoi richiedere informazioni sull'operazione chiamando l'endpoint
v1.operations
, sostituendo OPERATION_NAME nell'esempio seguente con il nome restituito nel passaggio precedente:curl -X GET \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ https://videointelligence.googleapis.com/v1/OPERATION_NAME
Vedrai le informazioni relative all'operazione. Se l'operazione è stata completata, viene incluso un campo
done
e impostato sutrue
:{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress", "annotationProgress": [ { "inputUri": "/YOUR_BUCKET/YOUR_OBJECT", "progressPercent": 100, "startTime": "2020-04-01T22:13:17.978847Z", "updateTime": "2020-04-01T22:13:29.576004Z" } ] }, "done": true, ... }
Dopo aver concesso alla richiesta un po' di tempo (in genere circa un minuto), la stessa richiesta restituisce i risultati dell'annotazione:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress", "annotationProgress": [ { "inputUri": "YOUR_BUCKET/YOUR_OBJECT", "progressPercent": 100, "startTime": "2020-04-01T22:13:17.978847Z", "updateTime": "2020-04-01T22:13:29.576004Z" } ] }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse", "annotationResults": [ { "inputUri": "/YOUR_BUCKET/YOUR_OBJECT", "segmentLabelAnnotations": [ { "entity": { "entityId": "/m/07bsy", "description": "transport", "languageCode": "en-US" }, "segments": [ { "segment": { "startTimeOffset": "0s", "endTimeOffset": "38.757872s" }, "confidence": 0.81231534 } ] }, { "entity": { "entityId": "/m/01n32", "description": "city", "languageCode": "en-US" }, "categoryEntities": [ { "entityId": "/m/043rvww", "description": "geographical feature", "languageCode": "en-US" } ], "segments": [ { "segment": { "startTimeOffset": "0s", "endTimeOffset": "38.757872s" }, "confidence": 0.3942462 } ] }, ... { "entity": { "entityId": "/m/06gfj", "description": "road", "languageCode": "en-US" }, "segments": [ { "segment": { "startTimeOffset": "0s", "endTimeOffset": "38.757872s" }, "confidence": 0.86698604 } ] } ] } ] } }
Complimenti! Hai inviato la tua prima richiesta all'API Video Intelligence.
Esegui la pulizia
Per evitare addebiti Google Cloud non necessari, utilizza la console Google Cloud per eliminare il progetto se non ti serve.
Passaggi successivi
- Consulta le Guide illustrative.
- Esamina Esempi e tutorial.
- Per informazioni complete su tutte le chiamate API, consulta i riferimenti API.