This page explains how to combine multiple input videos into a single output video. You can also trim the timelines of the input videos.
For each input video, add an
Input
object to the
inputs
array.
Each Input
object
defines the key and URI for the associated input video. You can add an optional
PreprocessingConfig
object to an Input
to
crop, pad, or perform other preprocessing
on the input video. The inputs
array is not ordered; you can add input videos in any order.
To add an input video to the output video timeline, add an
EditAtom
object to
the editList
array. The
editList
array is ordered. The first input designated in this array will be used first in
the output video, the second input will be used next, and so on. You identify an
input video by its key.
You can also designate a startTimeOffset
and endTimeOffset
to trim the
input video. These fields are optional. If you don't specify these fields, the
entire input video is used.
The following configuration concatenates two input videos into a single output video.
"inputs": [
{
"key": "input1",
"uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO1"
},
{
"key": "input2",
"uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO2"
}
],
"editList": [
{
"key": "atom1",
"inputs": [
"input1"
],
"startTimeOffset": "START_TIME_OFFSET1s",
"endTimeOffset": "END_TIME_OFFSET1s"
},
{
"key": "atom2",
"inputs": [
"input2"
],
"startTimeOffset": "START_TIME_OFFSET2s",
"endTimeOffset": "END_TIME_OFFSET2s"
}
],
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_VIDEO1
: The name of a 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
). This video will be used first in the output video timeline.START_TIME_OFFSET1
: The start time, in fractional seconds (for example,0.0
), relative to the first input video timeline. Use this field to trim content from the beginning of the video.END_TIME_OFFSET1
: The end time, in fractional seconds (for example,8.1
), relative to the first input video timeline. Use this field to trim content from the end of the video.STORAGE_INPUT_VIDEO2
: The name of a 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
). This video will be used second in the output video timeline.START_TIME_OFFSET2
: The start time, in fractional seconds (for example,3.5
), relative to the second input video timeline. Use this field to trim content from the beginning of the second video.END_TIME_OFFSET2
: The end time, in fractional seconds (for example,15
), relative to the second input video timeline. Use this field to trim content from the end of the second video.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:- LOCATION: The location where your
job will run. Use one of the supported regions.
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_BUCKET_NAME: The name of the Cloud Storage bucket you created.
- STORAGE_INPUT_VIDEO1:
The name of a 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
). This video will be used first in the output video timeline. - START_TIME_OFFSET1: The
start time, in fractional seconds (for example,
0.0
), relative to the first input video timeline. Use this field to trim content from the beginning of the video. - END_TIME_OFFSET1: The end
time, in fractional seconds (for example,
8.1
), relative to the first input video timeline. Use this field to trim content from the end of the video. - STORAGE_INPUT_VIDEO2:
The name of a 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
). This video will be used second in the output video timeline. - START_TIME_OFFSET2: The
start time, in fractional seconds (for example,
3.5
), relative to the second input video timeline. Use this field to trim content from the beginning of the second video. - END_TIME_OFFSET2: The end
time, in fractional seconds (for example,
15
), relative to the second input video timeline. Use this field to trim content from the end of the second video. - STORAGE_OUTPUT_FOLDER: The Cloud Storage folder name where you want to save the encoded video outputs.
{ "config": { "inputs": [ { "key": "input1", "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO1" }, { "key": "input2", "uri": "gs://STORAGE_BUCKET_NAME/STORAGE_INPUT_VIDEO2" } ], "editList": [ { "key": "atom1", "inputs": [ "input1" ], "startTimeOffset": "START_TIME_OFFSET1s", "endTimeOffset": "END_TIME_OFFSET1s" }, { "key": "atom2", "inputs": [ "input2" ], "startTimeOffset": "START_TIME_OFFSET2s", "endTimeOffset": "END_TIME_OFFSET2s" } ], "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/" } } }
- LOCATION: The location where your
job will run. Use one of the supported regions.
- 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.
Example
Consider the following sample videos:
Both videos are similar in that they contain three parts:
- Watching a movie or game on a mobile device
- Watching the same content on a big screen
- Show brief ad copy for the product
As an example, you can concatenate these two videos together such that the output video shows parts one and two from the first video, and then parts two and three from the second video. You can accomplish this concatenation using the following time offsets:
- ForBiggerEscapes.mp4
startTimeOffset
:0s
endTimeOffset
:8.1s
- ForBiggerJoyrides.mp4
startTimeOffset
:3.5s
endTimeOffset
:15s
Use the preceding code along with these two videos and their time offsets to see an action-packed result video.