UNPKG

@eyevinn/iaf-plugin-aws

Version:

Eyevinn Ingest Application Framework (IAF) plugin for upload and transcode in AWS

112 lines 5.55 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MediaConvertDispatcher = void 0; const client_mediaconvert_1 = require("@aws-sdk/client-mediaconvert"); const stringManipulations_1 = require("./utils/stringManipulations"); const fs = __importStar(require("fs")); const path = __importStar(require("path")); class MediaConvertDispatcher { /** * Initializes a MediaConvertDispatcher * @param mediaConvertEndpoint the unique part of the endpoint to the mediaconvert instance * @param region the AWS region * @param inputLocation the S3 bucket containing the input files * @param outputDestination the S3 bucket where the results should be placed * @param roleArn the role ARN string for AWS * @param playlistName the name of the playlist to be created * @param encodeParams the parameters to be used for the transcoding job * @param logger a logger object */ constructor(mediaConvertEndpoint, region, inputLocation, outputDestination, roleArn, playlistName, encodeParams, logger) { this.inputLocation = inputLocation; this.outputDestination = outputDestination; this.mediaConverterEndpoint = { endpoint: `https://${mediaConvertEndpoint}.mediaconvert.${region}.amazonaws.com` }; this.roleArn = roleArn; this.playlistName = playlistName; this.logger = logger; this.mediaConverterClient = new client_mediaconvert_1.MediaConvertClient(this.mediaConverterEndpoint); if (encodeParams) { this.encodeParams = JSON.parse(encodeParams); } else { this.encodeParams = this.loadEncodeParams(path.join(__dirname, "..", "resources", "exampleJob.json")); } } /** * Dispatches a transcode job to a MediaConvert instance * @param fileName the name of the file to transcode * @returns the response from AWS. */ dispatch(fileName) { return __awaiter(this, void 0, void 0, function* () { // start by setting the correct input and destination this.encodeParams["Role"] = this.roleArn; this.encodeParams["Settings"]["Inputs"].map(input => input["FileInput"] = `s3://${this.inputLocation}/${fileName}`); this.encodeParams["Settings"]["OutputGroups"].map(group => { const groupName = group["OutputGroupSettings"]["Type"]; const pascaledGroupName = (0, stringManipulations_1.toPascalCase)(groupName); group["OutputGroupSettings"][pascaledGroupName]["Destination"] = `s3://${this.outputDestination}/${fileName}/${this.playlistName}`; }); try { const data = yield this.mediaConverterClient.send(new client_mediaconvert_1.CreateJobCommand(this.encodeParams)); this.logger.info(`Transcoding job created for ${fileName}. Job ID: ${data.Job.Id}`); return data; } catch (err) { this.logger.error(`Failed to create a transcoding job for ${fileName}!`); throw err; } }); } /** * Get a transcode job from a MediaConvert instance * @param jobId the ID of the job to get * @returns the response from AWS. */ getJob(jobId) { return __awaiter(this, void 0, void 0, function* () { try { const resp = yield this.mediaConverterClient.send(new client_mediaconvert_1.GetJobCommand({ Id: jobId })); return resp.Job; } catch (err) { this.logger.error(`Failed to get the transcoding job for ID ${jobId} from MediaConvert!`); throw err; } }); } loadEncodeParams(templateFileName) { const encodeData = JSON.parse(fs.readFileSync(templateFileName, "utf-8")); return encodeData; } } exports.MediaConvertDispatcher = MediaConvertDispatcher; //# sourceMappingURL=mediaConvertDispatcher.js.map