Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 7bf59c3

Browse files
irataxysofisl
andauthored
feat(samples): add Transcoder samples (#8)
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
1 parent 39d9785 commit 7bf59c3

17 files changed

+982
-3
lines changed

.kokoro/pre-samples-test.sh

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.kokoro/samples-test.sh

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"jsdoc-fresh": "^1.0.2",
5252
"jsdoc-region-tag": "^1.0.4",
5353
"linkinator": "^2.1.2",
54-
"mocha": "^8.1.2",
54+
"mocha": "^8.2.1",
5555
"null-loader": "^4.0.0",
5656
"pack-n-play": "^1.0.0-2",
5757
"sinon": "^9.0.3",

samples/createJobFromAdHoc.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright 2020, 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, outputUri) {
19+
// [START transcoder_create_job_from_ad_hoc]
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+
// outputUri = 'gs://my-bucket/my-output-folder/';
27+
28+
// Imports the Transcoder library
29+
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
30+
31+
// Instantiates a client
32+
const transcoderServiceClient = new TranscoderServiceClient();
33+
34+
async function createJobFromAdHoc() {
35+
// Construct request
36+
const request = {
37+
parent: transcoderServiceClient.locationPath(projectId, location),
38+
job: {
39+
inputUri: inputUri,
40+
outputUri: outputUri,
41+
config: {
42+
elementaryStreams: [
43+
{
44+
key: 'video-stream0',
45+
videoStream: {
46+
codec: 'h264',
47+
heightPixels: 360,
48+
widthPixels: 640,
49+
bitrateBps: 550000,
50+
frameRate: 60,
51+
},
52+
},
53+
{
54+
key: 'video-stream1',
55+
videoStream: {
56+
codec: 'h264',
57+
heightPixels: 720,
58+
widthPixels: 1280,
59+
bitrateBps: 2500000,
60+
frameRate: 60,
61+
},
62+
},
63+
{
64+
key: 'audio-stream0',
65+
audioStream: {
66+
codec: 'aac',
67+
bitrateBps: 64000,
68+
},
69+
},
70+
],
71+
muxStreams: [
72+
{
73+
key: 'sd',
74+
container: 'mp4',
75+
elementaryStreams: ['video-stream0', 'audio-stream0'],
76+
},
77+
{
78+
key: 'hd',
79+
container: 'mp4',
80+
elementaryStreams: ['video-stream1', 'audio-stream0'],
81+
},
82+
],
83+
},
84+
},
85+
};
86+
87+
// Run request
88+
const [response] = await transcoderServiceClient.createJob(request);
89+
console.log(`Job: ${response.name}`);
90+
}
91+
92+
createJobFromAdHoc();
93+
// [END transcoder_create_job_from_ad_hoc]
94+
}
95+
96+
// node createJobFromAdHoc.js <projectId> <location> <inputUri> <outputUri>
97+
process.on('unhandledRejection', err => {
98+
console.error(err.message);
99+
process.exitCode = 1;
100+
});
101+
main(...process.argv.slice(2));

samples/createJobFromPreset.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2020, 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, outputUri, preset) {
19+
// [START transcoder_create_job_from_preset]
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+
// outputUri = 'gs://my-bucket/my-output-folder/';
27+
// preset = 'preset/web-hd';
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 createJobFromPreset() {
36+
// Construct request
37+
const request = {
38+
parent: transcoderServiceClient.locationPath(projectId, location),
39+
job: {
40+
inputUri: inputUri,
41+
outputUri: outputUri,
42+
templateId: preset,
43+
},
44+
};
45+
46+
// Run request
47+
const [response] = await transcoderServiceClient.createJob(request);
48+
console.log(`Job: ${response.name}`);
49+
}
50+
51+
createJobFromPreset();
52+
// [END transcoder_create_job_from_preset]
53+
}
54+
55+
// node createJobFromPreset.js <projectId> <location> <inputUri> <outputUri> <preset>
56+
process.on('unhandledRejection', err => {
57+
console.error(err.message);
58+
process.exitCode = 1;
59+
});
60+
main(...process.argv.slice(2));

samples/createJobFromTemplate.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2020, 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, outputUri, templateId) {
19+
// [START transcoder_create_job_from_template]
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+
// outputUri = 'gs://my-bucket/my-output-folder/';
27+
// templateId = 'my-job-template';
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 createJobFromTemplate() {
36+
// Construct request
37+
const request = {
38+
parent: transcoderServiceClient.locationPath(projectId, location),
39+
job: {
40+
inputUri: inputUri,
41+
outputUri: outputUri,
42+
templateId: templateId,
43+
},
44+
};
45+
46+
// Run request
47+
const [response] = await transcoderServiceClient.createJob(request);
48+
console.log(`Job: ${response.name}`);
49+
}
50+
51+
createJobFromTemplate();
52+
// [END transcoder_create_job_from_template]
53+
}
54+
55+
// node createJobFromTemplate.js <projectId> <location> <inputUri> <outputUri> <templateId>
56+
process.on('unhandledRejection', err => {
57+
console.error(err.message);
58+
process.exitCode = 1;
59+
});
60+
main(...process.argv.slice(2));

samples/createJobTemplate.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright 2020, 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, templateId) {
19+
// [START transcoder_create_job_template]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// templateId = 'my-job-template';
26+
27+
// Imports the Transcoder library
28+
const {TranscoderServiceClient} = require('@google-cloud/video-transcoder');
29+
30+
// Instantiates a client
31+
const transcoderServiceClient = new TranscoderServiceClient();
32+
33+
async function createJobTemplate() {
34+
// Construct request
35+
const request = {
36+
parent: transcoderServiceClient.locationPath(projectId, location),
37+
jobTemplateId: templateId,
38+
jobTemplate: {
39+
config: {
40+
elementaryStreams: [
41+
{
42+
key: 'video-stream0',
43+
videoStream: {
44+
codec: 'h264',
45+
heightPixels: 360,
46+
widthPixels: 640,
47+
bitrateBps: 550000,
48+
frameRate: 60,
49+
},
50+
},
51+
{
52+
key: 'video-stream1',
53+
videoStream: {
54+
codec: 'h264',
55+
heightPixels: 720,
56+
widthPixels: 1280,
57+
bitrateBps: 2500000,
58+
frameRate: 60,
59+
},
60+
},
61+
{
62+
key: 'audio-stream0',
63+
audioStream: {
64+
codec: 'aac',
65+
bitrateBps: 64000,
66+
},
67+
},
68+
],
69+
muxStreams: [
70+
{
71+
key: 'sd',
72+
container: 'mp4',
73+
elementaryStreams: ['video-stream0', 'audio-stream0'],
74+
},
75+
{
76+
key: 'hd',
77+
container: 'mp4',
78+
elementaryStreams: ['video-stream1', 'audio-stream0'],
79+
},
80+
],
81+
},
82+
},
83+
};
84+
85+
// Run request
86+
const [jobTemplate] = await transcoderServiceClient.createJobTemplate(
87+
request
88+
);
89+
console.log(`Job template: ${jobTemplate.name}`);
90+
}
91+
92+
createJobTemplate();
93+
// [END transcoder_create_job_template]
94+
}
95+
96+
// node createJobTemplate.js <projectId> <location> <templateId>
97+
process.on('unhandledRejection', err => {
98+
console.error(err.message);
99+
process.exitCode = 1;
100+
});
101+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)