Skip to content

Commit 28588db

Browse files
feat(samples): add samples and tests for adding captions to videos (#143)
* feat(samples): add samples and tests for adding captions to videos * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 4c3725a commit 28588db

File tree

4 files changed

+424
-1
lines changed

4 files changed

+424
-1
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/**
2+
* Copyright 2022, 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, inputVideoUri, inputCaptionsUri, outputUri) {
19+
// [START transcoder_create_job_with_embedded_captions]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// inputVideoUri = 'gs://my-bucket/my-video-file';
26+
// inputCaptionsUri = 'gs://my-bucket/my-captions-file';
27+
// outputUri = 'gs://my-bucket/my-output-folder/';
28+
29+
// Imports the Transcoder library
30+
const {TranscoderServiceClient} =
31+
require('@google-cloud/video-transcoder').v1;
32+
33+
// Instantiates a client
34+
const transcoderServiceClient = new TranscoderServiceClient();
35+
36+
async function createJobWithEmbeddedCaptions() {
37+
// Construct request
38+
const request = {
39+
parent: transcoderServiceClient.locationPath(projectId, location),
40+
job: {
41+
outputUri: outputUri,
42+
config: {
43+
inputs: [
44+
{
45+
key: 'input0',
46+
uri: inputVideoUri,
47+
},
48+
{
49+
key: 'caption_input0',
50+
uri: inputCaptionsUri,
51+
},
52+
],
53+
editList: [
54+
{
55+
key: 'atom0',
56+
inputs: ['input0', 'caption_input0'],
57+
},
58+
],
59+
elementaryStreams: [
60+
{
61+
key: 'video-stream0',
62+
videoStream: {
63+
h264: {
64+
heightPixels: 360,
65+
widthPixels: 640,
66+
bitrateBps: 550000,
67+
frameRate: 60,
68+
},
69+
},
70+
},
71+
{
72+
key: 'audio-stream0',
73+
audioStream: {
74+
codec: 'aac',
75+
bitrateBps: 64000,
76+
},
77+
},
78+
{
79+
key: 'cea-stream0',
80+
textStream: {
81+
codec: 'cea608',
82+
mapping: [
83+
{
84+
atomKey: 'atom0',
85+
inputKey: 'caption_input0',
86+
inputTrack: 0,
87+
},
88+
],
89+
},
90+
},
91+
],
92+
muxStreams: [
93+
{
94+
key: 'sd',
95+
container: 'mp4',
96+
elementaryStreams: ['video-stream0', 'audio-stream0'],
97+
},
98+
{
99+
key: 'sd-hls',
100+
container: 'ts',
101+
elementaryStreams: ['video-stream0', 'audio-stream0'],
102+
},
103+
{
104+
key: 'sd-dash',
105+
container: 'fmp4',
106+
elementaryStreams: ['video-stream0'],
107+
},
108+
{
109+
key: 'audio-dash',
110+
container: 'fmp4',
111+
elementaryStreams: ['audio-stream0'],
112+
},
113+
],
114+
manifests: [
115+
{
116+
fileName: 'manifest.m3u8',
117+
type: 'HLS',
118+
muxStreams: ['sd-hls'],
119+
},
120+
{
121+
fileName: 'manifest.mpd',
122+
type: 'DASH',
123+
muxStreams: ['sd-dash', 'audio-dash'],
124+
},
125+
],
126+
},
127+
},
128+
};
129+
130+
// Run request
131+
const [response] = await transcoderServiceClient.createJob(request);
132+
console.log(`Job: ${response.name}`);
133+
}
134+
135+
createJobWithEmbeddedCaptions();
136+
// [END transcoder_create_job_with_embedded_captions]
137+
}
138+
139+
// node createJobWithEmbeddedCaptions.js <projectId> <location> <inputVideoUri> <inputCaptionsUri> <outputUri>
140+
process.on('unhandledRejection', err => {
141+
console.error(err.message);
142+
process.exitCode = 1;
143+
});
144+
main(...process.argv.slice(2));
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/**
2+
* Copyright 2022, 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, inputVideoUri, inputCaptionsUri, outputUri) {
19+
// [START transcoder_create_job_with_standalone_captions]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// projectId = 'my-project-id';
24+
// location = 'us-central1';
25+
// inputVideoUri = 'gs://my-bucket/my-video-file';
26+
// inputCaptionsUri = 'gs://my-bucket/my-captions-file';
27+
// outputUri = 'gs://my-bucket/my-output-folder/';
28+
29+
// Imports the Transcoder library
30+
const {TranscoderServiceClient} =
31+
require('@google-cloud/video-transcoder').v1;
32+
33+
// Instantiates a client
34+
const transcoderServiceClient = new TranscoderServiceClient();
35+
36+
async function createJobWithStandaloneCaptions() {
37+
// Construct request
38+
const request = {
39+
parent: transcoderServiceClient.locationPath(projectId, location),
40+
job: {
41+
outputUri: outputUri,
42+
config: {
43+
inputs: [
44+
{
45+
key: 'input0',
46+
uri: inputVideoUri,
47+
},
48+
{
49+
key: 'caption_input0',
50+
uri: inputCaptionsUri,
51+
},
52+
],
53+
editList: [
54+
{
55+
key: 'atom0',
56+
inputs: ['input0', 'caption_input0'],
57+
},
58+
],
59+
elementaryStreams: [
60+
{
61+
key: 'video-stream0',
62+
videoStream: {
63+
h264: {
64+
heightPixels: 360,
65+
widthPixels: 640,
66+
bitrateBps: 550000,
67+
frameRate: 60,
68+
},
69+
},
70+
},
71+
{
72+
key: 'audio-stream0',
73+
audioStream: {
74+
codec: 'aac',
75+
bitrateBps: 64000,
76+
},
77+
},
78+
{
79+
key: 'vtt-stream0',
80+
textStream: {
81+
codec: 'webvtt',
82+
mapping: [
83+
{
84+
atomKey: 'atom0',
85+
inputKey: 'caption_input0',
86+
inputTrack: 0,
87+
},
88+
],
89+
},
90+
},
91+
],
92+
muxStreams: [
93+
{
94+
key: 'sd-hls-fmp4',
95+
container: 'fmp4',
96+
elementaryStreams: ['video-stream0'],
97+
},
98+
{
99+
key: 'audio-hls-fmp4',
100+
container: 'fmp4',
101+
elementaryStreams: ['audio-stream0'],
102+
},
103+
{
104+
key: 'text-vtt',
105+
container: 'vtt',
106+
elementaryStreams: ['vtt-stream0'],
107+
segmentSettings: {
108+
segmentDuration: {
109+
seconds: 6,
110+
},
111+
individualSegments: true,
112+
},
113+
},
114+
],
115+
manifests: [
116+
{
117+
fileName: 'manifest.m3u8',
118+
type: 'HLS',
119+
muxStreams: ['sd-hls-fmp4', 'audio-hls-fmp4', 'text-vtt'],
120+
},
121+
],
122+
},
123+
},
124+
};
125+
126+
// Run request
127+
const [response] = await transcoderServiceClient.createJob(request);
128+
console.log(`Job: ${response.name}`);
129+
}
130+
131+
createJobWithStandaloneCaptions();
132+
// [END transcoder_create_job_with_standalone_captions]
133+
}
134+
135+
// node createJobWithStandaloneCaptions.js <projectId> <location> <inputVideoUri> <inputCaptionsUri> <outputUri>
136+
process.on('unhandledRejection', err => {
137+
console.error(err.message);
138+
process.exitCode = 1;
139+
});
140+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)