Anotar un vídeo mediante la línea de comandos
En esta página se muestra cómo hacer una solicitud a la API Video Intelligence con curl
para proyectos de tu propiedad.
Puedes seguir los pasos de esta página o probar esta guía de inicio rápido como laboratorio de formación de Google Cloud.
Antes de empezar
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the required API.
-
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.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
Install the Google Cloud CLI.
-
Si utilizas un proveedor de identidades (IdP) externo, primero debes iniciar sesión en la CLI de gcloud con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the required API.
-
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.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
Install the Google Cloud CLI.
-
Si utilizas un proveedor de identidades (IdP) externo, primero debes iniciar sesión en la CLI de gcloud con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
Usa
curl
para enviar una solicitud POST al métodovideos:annotate
con el comandogcloud auth application-default print-access-token
para pegar un token de acceso en tu cuenta de servicio: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"
La API Video Intelligence crea una operación para procesar tu solicitud. La respuesta incluye el nombre de la operación:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID" }
Para solicitar información sobre la operación, llama al
v1.operations
endpoint y sustituye OPERATION_NAME en el ejemplo de abajo por el nombre devuelto en el paso anterior:curl -X GET \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ https://videointelligence.googleapis.com/v1/OPERATION_NAME
Verás información relacionada con tu operación. Si la operación se ha completado, se incluye el campo
done
y se le asigna el valortrue
:{ "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, ... }
- Consulta las guías prácticas.
- Consulta los ejemplos y tutoriales.
- Consulta la referencia de la API para obtener información completa sobre todas las llamadas a la API.
Realizar una petición de vídeo de anotación
gcloud
Usa la CLI de gcloud para llamar al comandodetect-labels
en la ruta del vídeo que quieras analizar.
gcloud ml video detect-labels gs://YOUR_BUCKET/YOUR_OBJECT
Línea de comandos
Después de esperar un poco (normalmente, un minuto), la misma solicitud devuelve los resultados de la anotación:
{ "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 } ] } ] } ] } }
¡Enhorabuena! Has enviado tu primera solicitud a la API Video Intelligence.
Limpieza
Para evitar cargos innecesarios, usa la Google Cloud Google Cloud console para eliminar tu proyecto si no lo necesitas.