Skip to content

Commit

Permalink
Check for completed transcode job
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Sep 13, 2023
1 parent e21efab commit 0b10a02
Show file tree
Hide file tree
Showing 9 changed files with 7,263 additions and 3,235 deletions.
5,123 changes: 3,522 additions & 1,601 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions src/handlers/check-transcode-job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

const { GetJobCommand, MediaConvertClient } = require("@aws-sdk/client-mediaconvert");

module.exports.handler = async (event) => {

console.log("TRANSCODE COMPLETE LAMBDA")
console.log("event.jobId", event.jobId)
if(!event.jobId) return {success: false}

const status = await checkJobStatus(event.jobId)

return {status: status}
};

async function checkJobStatus(jobId){
const mediaConvertClient = new MediaConvertClient({endpoint: process.env.MEDIA_CONVERT_ENDPOINT});

// possible: "SUBMITTED" || "PROGRESSING" || "COMPLETE" || "CANCELED" || "ERROR"

try {
const data = await mediaConvertClient.send(new GetJobCommand({Id: jobId}));
console.log(data);
console.log("Job status: ", data.Job.Status)
return data.Job.Status;
} catch (err) {
console.log("Error", err);
return null;
}

}
20 changes: 14 additions & 6 deletions src/handlers/get-file-set-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getFileSet } = require("../api/opensearch");
const opensearchResponse = require("../api/response/opensearch");

/**
* A simple function to get a FileSet by id
* Handler for download file set endpoint
*/
exports.handler = wrap(async (event) => {
const id = event.pathParameters.id;
Expand Down Expand Up @@ -47,8 +47,16 @@ function processDownload(streaming_url, email) {

var params = {
stateMachineArn: 'arn:aws:states:us-east-1:123456789012:stateMachine:hlsStitcherStepFunction',
input: JSON.stringify({s3Location:s3Location(streaming_url), email: email })
};
input: JSON.stringify({
transcodeInput: {
source:s3Location(streaming_url)
},
sendMailInput: {
to: email,
}
})
}

stepfunctions.startExecution(params, function(err, data) {
if (err) {
console.log(err, err.stack);
Expand All @@ -67,9 +75,9 @@ function processDownload(streaming_url, email) {
};
}

function s3Location(_streaming_url){
// for now
return "s3://meadow-s-streaming/88/c1/59/6b/-8/02/2-/45/a3/-9/a4/e-/22/76/c3/f1/46/59/88c1596b-8022-45a3-9a4e-2276c3f14659.m3u8"
function s3Location(streaming_url){
const url = new URL(streaming_url)
return `s3://${process.env.STREAMING_BUCKET}${url.pathname}`
}

function invalidRequest(code, message) {
Expand Down
43 changes: 19 additions & 24 deletions src/handlers/media-transcode.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const AWS = require("aws-sdk");
const { CreateJobCommand, MediaConvertClient } = require("@aws-sdk/client-mediaconvert");

function template(fileInput) {
function template(fileInput, fileOutput) {
const jobQueueArn = process.env.MEDIA_CONVERT_JOB_QUEUE_ARN;
const iamRoleArn = process.env.MEDIA_CONVERT_ROLE_ARN;
const destination = `s3://${process.env.MEDIA_CONVERT_DESTINATION_BUCKET}/test`

return {
"Queue": jobQueueArn,
Expand Down Expand Up @@ -50,7 +49,7 @@ function template(fileInput) {
"OutputGroupSettings": {
"Type": "FILE_GROUP_SETTINGS",
"FileGroupSettings": {
"Destination": destination
"Destination": fileOutput
}
}
}
Expand All @@ -76,36 +75,32 @@ function template(fileInput) {
}
}


// should probably take source, destination and Settings?
module.exports.handler = async (event) => {

console.log("MEDIA CONVERT LAMBDA")
console.log(event)
console.log(event.s3Location)
console.log(event.email)
console.log(event.source)

const params = template(event.s3Location)
const destination = `s3://${process.env.MEDIA_CONVERT_DESTINATION_BUCKET}/test`
const params = template(event.source, destination)

createJob(params);
const jobId = await createJob(params);

return {statusCode: 200}
return {jobId: jobId, destination: destination}
};

function createJob(params){
const mediaConvertEndpoint = process.env.MEDIA_CONVERT_ENDPOINT
async function createJob(params){
const mediaConvertClient = new MediaConvertClient({endpoint: process.env.MEDIA_CONVERT_ENDPOINT});

AWS.config.mediaconvert = {endpoint : mediaConvertEndpoint};
var endpointPromise = new AWS.MediaConvert({apiVersion: '2017-08-29'}).createJob(params).promise();

endpointPromise.then(
function(data) {
console.log("Job created ", data);
},
function(err) {
console.log("Error", err);
}
);
return;
try {
const data = await mediaConvertClient.send(new CreateJobCommand(params));
console.log("Success! ", data);
return data.Job.Id;
} catch (err) {
console.log("Error", err);
return null;
}

}

10 changes: 10 additions & 0 deletions src/handlers/presigned-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


module.exports.handler = async (event) => {

console.log("PRESIGNED URL LAMBDA")
console.log(event)

};


Loading

0 comments on commit 0b10a02

Please sign in to comment.