This page explains how to generate a spritesheet that contains frames from a
video you transcode. These reduced-sized frames, also known as thumbnails, are
useful for organizing and previewing content. To generate the spritesheet, use
the
spriteSheets
array in the JobConfig
template.
You have two options for generating the spritesheet:
- Generate a set number of thumbnail images distributed evenly across the input video timeline.
- Generate a thumbnail image periodically, that is, every n seconds, across the input video timeline.
Generate a set number of thumbnail images
The following configuration generates a 10x10 spritesheet of large
images and a 10x10 spritesheet of small images, each with 100
thumbnails. Note that spritesheets require at least one VideoStream
in the job
configuration.
You can add this configuration to a job template or include it in an ad-hoc job configuration:
REST
Before using any of the request data, make the following replacements:
PROJECT_ID
: Your Google Cloud project ID listed in the IAM Settings.LOCATION
: The location where your job will run. Use one of the supported regions.Show locationsus-central1
us-west1
us-west2
us-east1
us-east4
southamerica-east1
northamerica-northeast1
asia-east1
asia-northeast1
asia-northeast3
asia-south1
asia-southeast1
australia-southeast1
europe-west1
europe-west2
europe-west4
STORAGE_BUCKET_NAME
: The name of the Cloud Storage bucket you created.STORAGE_INPUT_VIDEO
: The name of the video in your Cloud Storage bucket that you are transcoding, such asmy-vid.mp4
. This field should take into account any folders that you created in the bucket (for example,input/my-vid.mp4
).STORAGE_OUTPUT_FOLDER
: The Cloud Storage folder name where you want to save the encoded video outputs.
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID", "config": { ... }, "state": "PENDING", "createTime": CREATE_TIME, "ttlAfterCompletionDays": 30 }
gcloud
- Create a
request.json
file that defines the job fields. Make the following replacements for thegcloud
command:- STORAGE_BUCKET_NAME: The name of the Cloud Storage bucket you created.
- STORAGE_INPUT_VIDEO: The
name of the video in your Cloud Storage bucket that you are
transcoding, such as
my-vid.mp4
. This field should take into account any folders that you created in the bucket (for example,input/my-vid.mp4
). - LOCATION: The location where
your job will run. Use a location from the following list.
Show locations
us-central1
us-west1
us-west2
us-east1
us-east4
southamerica-east1
northamerica-northeast1
asia-east1
asia-northeast1
asia-northeast3
asia-south1
asia-southeast1
australia-southeast1
europe-west1
europe-west2
europe-west4
- STORAGE_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
{ "config": { "inputs": [ { "key": "input0", "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" } ], "elementaryStreams": [ { "key": "video-stream0", "videoStream": { "h264": { "heightPixels": 360, "widthPixels": 640, "bitrateBps": 550000, "frameRate": 60 } } }, { "key": "audio-stream0", "audioStream": { "codec": "aac", "bitrateBps": 64000 } } ], "muxStreams": [ { "key": "sd", "container": "mp4", "elementaryStreams": [ "video-stream0", "audio-stream0" ] } ], "output": { "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/" }, "spriteSheets": [ { "filePrefix": "small-sprite-sheet", "spriteHeightPixels": 32, "spriteWidthPixels": 64, "columnCount": 10, "rowCount": 10, "totalCount": 100 }, { "filePrefix": "large-sprite-sheet", "spriteHeightPixels": 72, "spriteWidthPixels": 128, "columnCount": 10, "rowCount": 10, "totalCount": 100 } ] } }
- Run the following command:
You should see a response similar to the following:gcloud transcoder jobs create --location=LOCATION --file="request.json"
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID", "config": { ... }, "state": "PENDING", "createTime": CREATE_TIME, "ttlAfterCompletionDays": 30 }
C#
Before trying this sample, follow the C# setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API C# API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
Before trying this sample, follow the Go setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Go API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Java API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Node.js API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
Before trying this sample, follow the PHP setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API PHP API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Python API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Ruby API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Use this configuration on the sample video to generate the following spritesheets:
Figure 1. Small image spritesheet (100 thumbnails)
Figure 2. Large image spritesheet (100 thumbnails)
Generate a thumbnail image periodically
The following configuration generates a spritesheet of small images
and a spritesheet of large images. Each spritesheet contains
thumbnails that were generated every 7 seconds from the input video. Note that spritesheets require at least one VideoStream
in the job
configuration.
You can add this configuration to a job template or include it in an ad-hoc job configuration:
REST
Before using any of the request data, make the following replacements:
PROJECT_ID
: Your Google Cloud project ID listed in the IAM Settings.LOCATION
: The location where your job will run. Use one of the supported regions.Show locationsus-central1
us-west1
us-west2
us-east1
us-east4
southamerica-east1
northamerica-northeast1
asia-east1
asia-northeast1
asia-northeast3
asia-south1
asia-southeast1
australia-southeast1
europe-west1
europe-west2
europe-west4
STORAGE_BUCKET_NAME
: The name of the Cloud Storage bucket you created.STORAGE_INPUT_VIDEO
: The name of the video in your Cloud Storage bucket that you are transcoding, such asmy-vid.mp4
. This field should take into account any folders that you created in the bucket (for example,input/my-vid.mp4
).STORAGE_OUTPUT_FOLDER
: The Cloud Storage folder name where you want to save the encoded video outputs.
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID", "config": { ... }, "state": "PENDING", "createTime": CREATE_TIME, "ttlAfterCompletionDays": 30 }
gcloud
- Create a
request.json
file that defines the job fields. Make the following replacements for thegcloud
command:- STORAGE_BUCKET_NAME: The name of the Cloud Storage bucket you created.
- STORAGE_INPUT_VIDEO: The
name of the video in your Cloud Storage bucket that you are
transcoding, such as
my-vid.mp4
. This field should take into account any folders that you created in the bucket (for example,input/my-vid.mp4
). - LOCATION: The location where
your job will run. Use a location from the following list.
Show locations
us-central1
us-west1
us-west2
us-east1
us-east4
southamerica-east1
northamerica-northeast1
asia-east1
asia-northeast1
asia-northeast3
asia-south1
asia-southeast1
australia-southeast1
europe-west1
europe-west2
europe-west4
- STORAGE_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
{ "config": { "inputs": [ { "key": "input0", "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO" } ], "elementaryStreams": [ { "key": "video-stream0", "videoStream": { "h264": { "heightPixels": 360, "widthPixels": 640, "bitrateBps": 550000, "frameRate": 60 } } }, { "key": "audio-stream0", "audioStream": { "codec": "aac", "bitrateBps": 64000 } } ], "muxStreams": [ { "key": "sd", "container": "mp4", "elementaryStreams": [ "video-stream0", "audio-stream0" ] } ], "output": { "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_OUTPUT_FOLDER/" }, "spriteSheets": [ { "filePrefix": "small-sprite-sheet", "spriteHeightPixels": 32, "spriteWidthPixels": 64, "interval": "7s" }, { "filePrefix": "large-sprite-sheet", "spriteHeightPixels": 72, "spriteWidthPixels": 128, "interval": "7s" } ] } }
- Run the following command:
You should see a response similar to the following:gcloud transcoder jobs create --location=LOCATION --file="request.json"
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION/jobs/JOB_ID", "config": { ... }, "state": "PENDING", "createTime": CREATE_TIME, "ttlAfterCompletionDays": 30 }
C#
Before trying this sample, follow the C# setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API C# API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
Before trying this sample, follow the Go setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Go API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Java API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Node.js API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
Before trying this sample, follow the PHP setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API PHP API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Python API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Transcoder API quickstart using client libraries. For more information, see the Transcoder API Ruby API reference documentation.
To authenticate to Transcoder API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Use this configuration on the sample video to generate the following spritesheets:
Figure 3. Small image spritesheet (1 thumbnail every 7 seconds)
Figure 4. Large image spritesheet (1 thumbnail every 7 seconds)
Eight thumbnails are generated from the sample video, which is 60 seconds in length.