AWS Media Convert Connector
reshuffle-aws-connectors
Code | npm | Code sample
npm install reshuffle-aws-connectors
Reshuffle AWS Media Convert Connector
This Reshuffle connector can be used to transcode video and audio using Amazon's Elemental Media Convert service. Complete information about the service API can be found Elemental Media Convert.
The following example provides two API endpoints, one to initiate a transcoding job and another for tracking its progress:
const { HttpConnector, Reshuffle } = require('reshuffle')
const { AWSMediaConvertConnector } = require('reshuffle-aws-connectors')
;(async () => {
const bucket = process.env.AWS_DEFAULT_BUCKET
const app = new Reshuffle()
const awsMediaConvertConnector = new AWSMediaConvertConnector(app, {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_DEFAULT_REGION,
})
const httpConnector = new HttpConnector(app)
httpConnector.on({ method: 'GET', path:'/go' }, async (event) => {
const filename = event.req.query.filename
if (!filename) {
return event.res.status(400).json({ error: 'No filename' })
}
const job = await awsMediaConvertConnector.createSingleJob(
`s3://${bucket}/${filename}`,
`s3://${bucket}/${filename}-thumbnail`,
{
VideoDescription: {
Height: 200,
Width: 200,
CodecSettings: {
Codec: 'H_264',
H264Settings: {
Bitrate: 262144,
},
},
},
ContainerSettings: {
Container: 'MP4',
},
},
)
return event.res.json({ jobId: job.Id })
})
awsMediaConvertConnector.on({ type: 'JobStatusChanged' }, async (event) => {
console.log(`Job progress ${event.jobId}: ${
event.old.Status} -> ${event.current.Status}`)
})
app.start(8000)
})()
Table of Contents
Configuration Configuration options
Connector events:
jobStatusChanged Job status changed
Connector actions:
cancelJob Cancel a transcoding job
cancelJobById Cancel a transcoding job using its Id
createJob Create a new transcoding job
createSimpleJob Create a simple transcoding job
createSingleJob Create a job for transcoding a single file
getJobStatus Get the status of a transcoding job
getJobStatusById Get job status by its Id
listJobs List active and past transcoding jobs
listJobsById List jobs and index by job Id
SDK:
sdk Get direct SDK access
Configuration options
const app = new Reshuffle()
const awsMediaConvertConnector = new AWSMediaConvertConnector(app, {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_DEFAULT_REGION,
})
Connector events
Job Status Changed event
Example:
async (job) => {
console.log(`Media Convert job ${job.jobId}: ${job.current.Status}`);
}
This event is fired when the status of a transcoding job changes. The event object contains the followin information:
{
jobId: string,
current: {
Id: string,
Status: string,
},
old: {
Id: string,
Status: string,
},
}
Status is one of the following: NEW
, SUBMITTED
, PROGRESSING
,
COMPLETE
, CANCELED
or ERROR
.
Connector actions
<name="cancelJob">Cancel Job action
Definition:
(
job: Job,
) => void
Usage:
await awsMediaConvertConnector.cancelJob(job);
Cancel a transcoding job, using the job object returned when the job was created.
<name="cancelJobById">Cancel Job By Id action
Definition:
(
id: string,
) => void
Usage:
await awsMediaConvertConnector.cancelJobById('...');
Cancel a transcoding job, using its Id.
<name="createJob">Create Job action
Definition:
(
params: object,
) => Job
Usage:
const job = await awsMediaConvertConnector.createJob({
// ...
});
Create a new transcoding job using the parameters and returning the job information as defined by the AWS DSK.
<name="createSimpleJob">Create Simple Job action
Definition:
(
input: object,
outputGroup: object,
settings?: object,
) => Job
Usage:
const job = await awsMediaConvertConnector.createSimpleJob({
// ...
});
Create a simple transcoding job using the input
and outputGroup
arguments,
and returning the job information as defined by the
AWS DSK.
The optional settings
argument allows the caller to define additional
transcoding settings like Crop
, Position
or PsiControl
as defined by
the SDK.
<name="createSingleJob">Create Single Job action
Definition:
(
src: string,
dst: string,
output: object,
settings?: object,
) => Job
Usage:
const job = await awsMediaConvertConnector.createSingleJob(
`s3://<source-bucket>/<source-file>`,
`s3://<target-bucket>/<target-file>`,
{
VideoDescription: {
CodecSettings: {
Codec: 'H_264',
H264Settings: {
Bitrate: 10000,
},
},
},
ContainerSettings: {
Container: 'MP4',
},
},
);
Create a transcoding job for processing a single video file. The src
and
dst
arguments are S3 URLs poiting to the original and the transcoded video
files respectively. The output
aregument is a single out object as defined
by the
AWS DSK.
The optional settings
argument allows the caller to define additional
transcoding settings like Crop
, Position
or PsiControl
as defined by
the SDK.
<name="getJobStatus">Get Job Status action
Definition:
(
job: object,
) => object
Usage:
const job = await awsMediaConvertConnector.createJob(...);
const status = await awsMediaConvertConnector.getJobStatus(job);
Get the status of a transcoding job, as defined by the AWS SDK.
<name="getJobStatusById">Get Job Status By Id action
Definition:
(
id: string,
) => object
Usage:
const job = await awsMediaConvertConnector.createJob(...);
const status = await awsMediaConvertConnector.getJobStatusById(job.Id);
Get the status of a transcoding job by the job Id, as defined by the AWS SDK.
<name="listJobs">List Jobs action
Definition:
() => object[]
Usage:
const jobs = await awsMediaConvertConnector.listJobs();
for (job of jobs) {
console.log(job);
}
Get information on past and active transcoding jobs as defined here.
<name="listJobsById">List Jobs By Id action
Definition:
() => object
Usage:
const jobs = await awsMediaConvertConnector.listJobsById();
for (id in jobs) {
console.log(jobs[id]);
}
Get information on past and active transcoding jobs as defined here, indexed by job Id.
SDK Details
SDK action
Definition:
(
options ?: object,
) => object
Usage:
const mc = await awsMediaConvertConnector.sdk()
Get the underlying SDK object. You can specify additional options to override or add to the required fields in the connector's configuration.