Skip to content

Commit a146568

Browse files
authored
feat(samples): add code samples and tests for overlay creation (#39)
1 parent 14fd613 commit a146568

File tree

5 files changed

+355
-8
lines changed

5 files changed

+355
-8
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* Copyright 2021, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, inputUri, overlayImageUri, outputUri) {
19+
// [START transcoder_create_job_with_animated_overlay]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// inputUri = 'gs://my-bucket/my-video-file';
26+
// overlayImageUri = 'gs://my-bucket/my-overlay-image-file'; // Must be a JPEG
27+
// outputUri = 'gs://my-bucket/my-output-folder/';
28+
29+
// Imports the Transcoder library
30+
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
31+
32+
// Instantiates a client
33+
const transcoderServiceClient = new TranscoderServiceClient();
34+
35+
async function createJobFromAnimatedOverlay() {
36+
// Construct request
37+
const request = {
38+
parent: transcoderServiceClient.locationPath(projectId, location),
39+
job: {
40+
inputUri: inputUri,
41+
outputUri: outputUri,
42+
config: {
43+
elementaryStreams: [
44+
{
45+
key: 'video-stream0',
46+
videoStream: {
47+
codec: 'h264',
48+
heightPixels: 360,
49+
widthPixels: 640,
50+
bitrateBps: 550000,
51+
frameRate: 60,
52+
},
53+
},
54+
{
55+
key: 'audio-stream0',
56+
audioStream: {
57+
codec: 'aac',
58+
bitrateBps: 64000,
59+
},
60+
},
61+
],
62+
muxStreams: [
63+
{
64+
key: 'sd',
65+
container: 'mp4',
66+
elementaryStreams: ['video-stream0', 'audio-stream0'],
67+
},
68+
],
69+
overlays: [
70+
{
71+
image: {
72+
uri: overlayImageUri,
73+
resolution: {
74+
x: 0,
75+
y: 0,
76+
},
77+
alpha: 1.0,
78+
},
79+
animations: [
80+
{
81+
animationFade: {
82+
fadeType: 'FADE_IN',
83+
xy: {
84+
x: 0.5,
85+
y: 0.5,
86+
},
87+
startTimeOffset: {
88+
seconds: 5,
89+
},
90+
endTimeOffset: {
91+
seconds: 10,
92+
},
93+
},
94+
},
95+
{
96+
animationFade: {
97+
fadeType: 'FADE_OUT',
98+
xy: {
99+
x: 0.5,
100+
y: 0.5,
101+
},
102+
startTimeOffset: {
103+
seconds: 12,
104+
},
105+
endTimeOffset: {
106+
seconds: 15,
107+
},
108+
},
109+
},
110+
],
111+
},
112+
],
113+
},
114+
},
115+
};
116+
117+
// Run request
118+
const [response] = await transcoderServiceClient.createJob(request);
119+
console.log(`Job: ${response.name}`);
120+
}
121+
122+
createJobFromAnimatedOverlay();
123+
// [END transcoder_create_job_with_animated_overlay]
124+
}
125+
126+
// node createJobFromAnimatedOverlay.js <projectId> <location> <inputUri> <overlayImageUri> <outputUri>
127+
process.on('unhandledRejection', err => {
128+
console.error(err.message);
129+
process.exitCode = 1;
130+
});
131+
main(...process.argv.slice(2));
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* Copyright 2021, Google, Inc.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
function main(projectId, location, inputUri, overlayImageUri, outputUri) {
19+
// [START transcoder_create_job_with_static_overlay]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// inputUri = 'gs://my-bucket/my-video-file';
26+
// overlayImageUri = 'gs://my-bucket/my-overlay-image-file'; // Must be a JPEG
27+
// outputUri = 'gs://my-bucket/my-output-folder/';
28+
29+
// Imports the Transcoder library
30+
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
31+
32+
// Instantiates a client
33+
const transcoderServiceClient = new TranscoderServiceClient();
34+
35+
async function createJobFromStaticOverlay() {
36+
// Construct request
37+
const request = {
38+
parent: transcoderServiceClient.locationPath(projectId, location),
39+
job: {
40+
inputUri: inputUri,
41+
outputUri: outputUri,
42+
config: {
43+
elementaryStreams: [
44+
{
45+
key: 'video-stream0',
46+
videoStream: {
47+
codec: 'h264',
48+
heightPixels: 360,
49+
widthPixels: 640,
50+
bitrateBps: 550000,
51+
frameRate: 60,
52+
},
53+
},
54+
{
55+
key: 'audio-stream0',
56+
audioStream: {
57+
codec: 'aac',
58+
bitrateBps: 64000,
59+
},
60+
},
61+
],
62+
muxStreams: [
63+
{
64+
key: 'sd',
65+
container: 'mp4',
66+
elementaryStreams: ['video-stream0', 'audio-stream0'],
67+
},
68+
],
69+
overlays: [
70+
{
71+
image: {
72+
uri: overlayImageUri,
73+
resolution: {
74+
x: 1,
75+
y: 0.5,
76+
},
77+
alpha: 1.0,
78+
},
79+
animations: [
80+
{
81+
animationStatic: {
82+
xy: {
83+
x: 0,
84+
y: 0,
85+
},
86+
startTimeOffset: {
87+
seconds: 0,
88+
},
89+
},
90+
},
91+
{
92+
animationEnd: {
93+
startTimeOffset: {
94+
seconds: 10,
95+
},
96+
},
97+
},
98+
],
99+
},
100+
],
101+
},
102+
},
103+
};
104+
105+
// Run request
106+
const [response] = await transcoderServiceClient.createJob(request);
107+
console.log(`Job: ${response.name}`);
108+
}
109+
110+
createJobFromStaticOverlay();
111+
// [END transcoder_create_job_with_static_overlay]
112+
}
113+
114+
// node createJobFromStaticOverlay.js <projectId> <location> <inputUri> <overlayImageUri> <outputUri>
115+
process.on('unhandledRejection', err => {
116+
console.error(err.message);
117+
process.exitCode = 1;
118+
});
119+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)