diff --git a/media/transcoder/createJobFromPresetBatchMode.js b/media/transcoder/createJobFromPresetBatchMode.js new file mode 100644 index 0000000000..4802041035 --- /dev/null +++ b/media/transcoder/createJobFromPresetBatchMode.js @@ -0,0 +1,63 @@ +/** + * Copyright 2023 Google LLC + * 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, inputUri, outputUri, preset) { + // [START transcoder_create_job_from_preset_batch_mode] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // inputUri = 'gs://my-bucket/my-video-file'; + // outputUri = 'gs://my-bucket/my-output-folder/'; + // preset = 'preset/web-hd'; + + // Imports the Transcoder library + const {TranscoderServiceClient} = + require('@google-cloud/video-transcoder').v1; + + // Instantiates a client + const transcoderServiceClient = new TranscoderServiceClient(); + + async function createJobFromPresetBatchMode() { + // Construct request + const request = { + parent: transcoderServiceClient.locationPath(projectId, location), + job: { + inputUri: inputUri, + outputUri: outputUri, + templateId: preset, + mode: 'PROCESSING_MODE_BATCH', + batchModePriority: 10, + }, + }; + + // Run request + const [response] = await transcoderServiceClient.createJob(request); + console.log(`Job: ${response.name}`); + } + + createJobFromPresetBatchMode(); + // [END transcoder_create_job_from_preset_batch_mode] +} + +// node createJobFromPresetBatchMode.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/transcoder/package.json b/media/transcoder/package.json index 8559b895e5..6860715b1a 100644 --- a/media/transcoder/package.json +++ b/media/transcoder/package.json @@ -14,7 +14,7 @@ "test": "c8 mocha --timeout 600000 test/*.js" }, "dependencies": { - "@google-cloud/video-transcoder": "^2.2.3" + "@google-cloud/video-transcoder": "^2.7.0" }, "devDependencies": { "@google-cloud/storage": "^6.0.0", diff --git a/media/transcoder/test/transcoder.test.js b/media/transcoder/test/transcoder.test.js index 358df3ad91..ba70224ff1 100644 --- a/media/transcoder/test/transcoder.test.js +++ b/media/transcoder/test/transcoder.test.js @@ -47,6 +47,7 @@ const captionsUri = `gs://${bucketName}/${testCaptionFileName}`; const subtitles1Uri = `gs://${bucketName}/${testSubtitles1FileName}`; const subtitles2Uri = `gs://${bucketName}/${testSubtitles2FileName}`; const outputUriForPreset = `gs://${bucketName}/test-output-preset/`; +const outputUriForPresetBatchMode = `gs://${bucketName}/test-output-preset-batch-mode/`; const outputUriForTemplate = `gs://${bucketName}/test-output-template/`; const outputUriForAdHoc = `gs://${bucketName}/test-output-adhoc/`; const outputUriForStaticOverlay = `gs://${bucketName}/test-output-static-overlay/`; @@ -383,6 +384,63 @@ describe('Job functions adhoc', () => { }); }); +describe('Job functions preset batch mode', () => { + before(function () { + const output = execSync( + `node createJobFromPresetBatchMode.js ${projectId} ${location} ${inputUri} ${outputUriForPresetBatchMode} ${preset}`, + {cwd} + ); + assert.ok(output.includes(`/locations/${location}/jobs/`)); + this.presetBatchModeJobId = output.toString().split('/').pop(); + }); + + after(function () { + const output = execSync( + `node deleteJob.js ${projectId} ${location} ${this.presetBatchModeJobId}`, + {cwd} + ); + assert.ok(output.includes('Deleted job')); + }); + + it('should get a job', function () { + const output = execSync( + `node getJob.js ${projectId} ${location} ${this.presetBatchModeJobId}`, + {cwd} + ); + const jobName = `/locations/${location}/jobs/${this.presetBatchModeJobId}`; + assert.ok(output.includes(jobName)); + }); + + it('should show a list of jobs', function () { + const output = execSync(`node listJobs.js ${projectId} ${location}`, { + cwd, + }); + const jobName = `/locations/${location}/jobs/${this.presetBatchModeJobId}`; + assert.ok(output.includes(jobName)); + }); + + it('should check that the job succeeded', async function () { + this.retries(5); + await delay(this.test, 30000); + + let getAttempts = 0; + while (getAttempts < 5) { + const ms = Math.pow(2, getAttempts + 1) * 10000 + Math.random() * 1000; + await wait(ms); + const output = execSync( + `node getJobState.js ${projectId} ${location} ${this.presetBatchModeJobId}`, + {cwd} + ); + if (output.includes('Job state: SUCCEEDED')) { + assert.ok(true); + return; + } + getAttempts++; + } + assert.ok(false); + }); +}); + describe('Job with static overlay functions', () => { before(function () { const output = execSync(