The Video Intelligence API Face detection feature looks for faces in a video.
Face detection from a file in Cloud Storage
The following samples demonstrate face detection on a file located in Cloud Storage.
REST & CMD LINE
Send video annotation request
The following shows how to send a POST request to the
videos:annotate
method. The example uses the access token for a service account set up for the
project using the Cloud SDK. For instructions on installing the
Cloud SDK, setting up a project with a service account, and obtaining
an access token, see the
Video Intelligence API Quickstart.
Download annotation results
Copy the annotation from the source to the destination bucket: (see Copy files and objects)
gsutil cp gcs_uri gs://my-bucket
Note: If the output gcs uri is provided by the user, then the annotation is stored in that gcs uri.
Before using any of the request data below, make the following replacements:
- input-uri: a Cloud Storage bucket that contains the file you want to
annotate, including the file name. Must start with gs://.
For example: `"inputUri": "gs://cloud-samples-data/video/googlework_short.mp4"`
HTTP method and URL:
POST https://videointelligence.googleapis.com/v1p3beta1/videos:annotate
Request JSON body:
{ "inputUri": "input-uri", "features": ["FACE_DETECTION"] }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
If the response is successful, the Video Intelligence API returns the name
for your
operation. The above shows an example of such a response, where:
- project-number: the number of your project
- location-id: the Cloud region where annotation should take
place. Supported cloud regions are:
us-east1
,us-west1
,europe-west1
,asia-east1
. If no region is specified, a region is selected based on video file location. - operation-id: the ID of the long running operation created
for the request and provided in the response when you started the
operation, for example
12345...
Get annotation results
To retrieve the result of the operation, make a GET request, using the operation name returned from the call to videos:annotate, as shown in the following example.
Before using any of the request data below, make the following replacements:
- operation-name: the name of the operation as
returned by Video Intelligence API. The operation name has the format
projects/project-number/locations/location-id/operations/operation-id
HTTP method and URL:
GET https://videointelligence.googleapis.com/v1/operation-name
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
Shot detection annotations are returned as a shotAnnotations
list.
Note: The done field is only returned when its value is True.
It's not included in responses for which the operation has not completed.
Java
Node.js
Python
Face detection from a local file
The following example uses face detection to find entities in a video from a video file uploaded from your local machine.
REST & CMD LINE
Send the process request
To perform face detection on a local video file, base64-encode the contents
of the video file. For information on how to base64-encode the contents of a
video file, see Base64 Encoding. Then, make a POST request to the
videos:annotate
method. Include the base64-encoded contents in the inputContent
field of the request and specify the FACE_DETECTION
feature.
The following is an example of a POST request using curl. This example uses the access token for a service account set up for the project using the Cloud SDK. For instructions on installing the Cloud SDK, setting up a project with a service account, and obtaining an access token, see the Video Intelligence API Quickstart
Before using any of the request data below, make the following replacements:
- inputContent: Local video file in binary format
For example: 'AAAAGGZ0eXBtcDQyAAAAAGlzb21tcDQyAAGVYW1vb3YAAABsbXZoZAAAAADWvhlR1r4ZUQABX5ABCOxo AAEAAAEAAAAAAA4...'
HTTP method and URL:
POST https://videointelligence.googleapis.com/v1p3beta1/videos:annotate
Request JSON body:
{ inputContent: "Local video file in binary format", "features": ["FACE_DETECTION"] }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
If the request is successful, Video Intelligence the name
for your operation. The
above shows an example of such a response, where project-number
is the number of your project and operation-id
is the ID of the long-running operation created for the request.
{
"name": "us-west1.17122464255125931980"
}
Get the results
To retrieve the result of the operation, make a GET request to the
operations
endpoint and specify the name of your operation.
Before using any of the request data below, make the following replacements:
- operation-name: the name of the operation as
returned by Video Intelligence API. The operation name has the format
projects/project-number/locations/location-id/operations/operation-id
HTTP method and URL:
GET https://videointelligence.googleapis.com/v1/operation-name
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
Java
Node.js
Python