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

feat(samples): add samples and tests for adding captions to videos #143

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-video-trans
| Create Job Template | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobTemplate.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobTemplate.js,samples/README.md) |
| Create Job With Animated Overlay | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithAnimatedOverlay.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithAnimatedOverlay.js,samples/README.md) |
| Create Job With Concatenated Inputs | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithConcatenatedInputs.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithConcatenatedInputs.js,samples/README.md) |
| Create Job With Embedded Captions | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithEmbeddedCaptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithEmbeddedCaptions.js,samples/README.md) |
| Create Job With Periodic Images Spritesheet | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithPeriodicImagesSpritesheet.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithPeriodicImagesSpritesheet.js,samples/README.md) |
| Create Job With Set Number Images Spritesheet | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithSetNumberImagesSpritesheet.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithSetNumberImagesSpritesheet.js,samples/README.md) |
| Create Job With Standalone Captions | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithStandaloneCaptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithStandaloneCaptions.js,samples/README.md) |
| Create Job With Static Overlay | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithStaticOverlay.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithStaticOverlay.js,samples/README.md) |
| Delete Job | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/deleteJob.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/deleteJob.js,samples/README.md) |
| Delete Job Template | [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/deleteJobTemplate.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/deleteJobTemplate.js,samples/README.md) |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test": "c8 mocha build/test"
},
"dependencies": {
"@google-cloud/video-transcoder": "^1.8.0",
"@google-cloud/video-transcoder": "^1.8.1",
"google-gax": "^2.24.1"
},
"devDependencies": {
Expand Down
36 changes: 36 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
* [Create Job Template](#create-job-template)
* [Create Job With Animated Overlay](#create-job-with-animated-overlay)
* [Create Job With Concatenated Inputs](#create-job-with-concatenated-inputs)
* [Create Job With Embedded Captions](#create-job-with-embedded-captions)
* [Create Job With Periodic Images Spritesheet](#create-job-with-periodic-images-spritesheet)
* [Create Job With Set Number Images Spritesheet](#create-job-with-set-number-images-spritesheet)
* [Create Job With Standalone Captions](#create-job-with-standalone-captions)
* [Create Job With Static Overlay](#create-job-with-static-overlay)
* [Delete Job](#delete-job)
* [Delete Job Template](#delete-job-template)
Expand Down Expand Up @@ -147,6 +149,23 @@ __Usage:__



### Create Job With Embedded Captions

View the [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithEmbeddedCaptions.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithEmbeddedCaptions.js,samples/README.md)

__Usage:__


`node samples/createJobWithEmbeddedCaptions.js`


-----




### Create Job With Periodic Images Spritesheet

View the [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithPeriodicImagesSpritesheet.js).
Expand Down Expand Up @@ -181,6 +200,23 @@ __Usage:__



### Create Job With Standalone Captions

View the [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithStandaloneCaptions.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-video-transcoder&page=editor&open_in_editor=samples/createJobWithStandaloneCaptions.js,samples/README.md)

__Usage:__


`node samples/createJobWithStandaloneCaptions.js`


-----




### Create Job With Static Overlay

View the [source code](https://github.com/googleapis/nodejs-video-transcoder/blob/main/samples/createJobWithStaticOverlay.js).
Expand Down
144 changes: 144 additions & 0 deletions samples/createJobWithEmbeddedCaptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, inputVideoUri, inputCaptionsUri, outputUri) {
// [START transcoder_create_job_with_embedded_captions]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// inputVideoUri = 'gs://my-bucket/my-video-file';
// inputCaptionsUri = 'gs://my-bucket/my-captions-file';
// outputUri = 'gs://my-bucket/my-output-folder/';

// Imports the Transcoder library
const {TranscoderServiceClient} =
require('@google-cloud/video-transcoder').v1;

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function createJobWithEmbeddedCaptions() {
// Construct request
const request = {
parent: transcoderServiceClient.locationPath(projectId, location),
job: {
outputUri: outputUri,
config: {
inputs: [
{
key: 'input0',
uri: inputVideoUri,
},
{
key: 'caption_input0',
uri: inputCaptionsUri,
},
],
editList: [
{
key: 'atom0',
inputs: ['input0', 'caption_input0'],
},
],
elementaryStreams: [
{
key: 'video-stream0',
videoStream: {
h264: {
heightPixels: 360,
widthPixels: 640,
bitrateBps: 550000,
frameRate: 60,
},
},
},
{
key: 'audio-stream0',
audioStream: {
codec: 'aac',
bitrateBps: 64000,
},
},
{
key: 'cea-stream0',
textStream: {
codec: 'cea608',
mapping: [
{
atomKey: 'atom0',
inputKey: 'caption_input0',
inputTrack: 0,
},
],
},
},
],
muxStreams: [
{
key: 'sd',
container: 'mp4',
elementaryStreams: ['video-stream0', 'audio-stream0'],
},
{
key: 'sd-hls',
container: 'ts',
elementaryStreams: ['video-stream0', 'audio-stream0'],
},
{
key: 'sd-dash',
container: 'fmp4',
elementaryStreams: ['video-stream0'],
},
{
key: 'audio-dash',
container: 'fmp4',
elementaryStreams: ['audio-stream0'],
},
],
manifests: [
{
fileName: 'manifest.m3u8',
type: 'HLS',
muxStreams: ['sd-hls'],
},
{
fileName: 'manifest.mpd',
type: 'DASH',
muxStreams: ['sd-dash', 'audio-dash'],
},
],
},
},
};

// Run request
const [response] = await transcoderServiceClient.createJob(request);
console.log(`Job: ${response.name}`);
}

createJobWithEmbeddedCaptions();
// [END transcoder_create_job_with_embedded_captions]
}

// node createJobWithEmbeddedCaptions.js <projectId> <location> <inputVideoUri> <inputCaptionsUri> <outputUri>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
140 changes: 140 additions & 0 deletions samples/createJobWithStandaloneCaptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Copyright 2022, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(projectId, location, inputVideoUri, inputCaptionsUri, outputUri) {
// [START transcoder_create_job_with_standalone_captions]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// projectId = 'my-project-id';
// location = 'us-central1';
// inputVideoUri = 'gs://my-bucket/my-video-file';
// inputCaptionsUri = 'gs://my-bucket/my-captions-file';
// outputUri = 'gs://my-bucket/my-output-folder/';

// Imports the Transcoder library
const {TranscoderServiceClient} =
require('@google-cloud/video-transcoder').v1;

// Instantiates a client
const transcoderServiceClient = new TranscoderServiceClient();

async function createJobWithStandaloneCaptions() {
// Construct request
const request = {
parent: transcoderServiceClient.locationPath(projectId, location),
job: {
outputUri: outputUri,
config: {
inputs: [
{
key: 'input0',
uri: inputVideoUri,
},
{
key: 'caption_input0',
uri: inputCaptionsUri,
},
],
editList: [
{
key: 'atom0',
inputs: ['input0', 'caption_input0'],
},
],
elementaryStreams: [
{
key: 'video-stream0',
videoStream: {
h264: {
heightPixels: 360,
widthPixels: 640,
bitrateBps: 550000,
frameRate: 60,
},
},
},
{
key: 'audio-stream0',
audioStream: {
codec: 'aac',
bitrateBps: 64000,
},
},
{
key: 'vtt-stream0',
textStream: {
codec: 'webvtt',
mapping: [
{
atomKey: 'atom0',
inputKey: 'caption_input0',
inputTrack: 0,
},
],
},
},
],
muxStreams: [
{
key: 'sd-hls-fmp4',
container: 'fmp4',
elementaryStreams: ['video-stream0'],
},
{
key: 'audio-hls-fmp4',
container: 'fmp4',
elementaryStreams: ['audio-stream0'],
},
{
key: 'text-vtt',
container: 'vtt',
elementaryStreams: ['vtt-stream0'],
segmentSettings: {
segmentDuration: {
seconds: 6,
},
individualSegments: true,
},
},
],
manifests: [
{
fileName: 'manifest.m3u8',
type: 'HLS',
muxStreams: ['sd-hls-fmp4', 'audio-hls-fmp4', 'text-vtt'],
},
],
},
},
};

// Run request
const [response] = await transcoderServiceClient.createJob(request);
console.log(`Job: ${response.name}`);
}

createJobWithStandaloneCaptions();
// [END transcoder_create_job_with_standalone_captions]
}

// node createJobWithStandaloneCaptions.js <projectId> <location> <inputVideoUri> <inputCaptionsUri> <outputUri>
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
Loading