I am converting mp4 videos in s3 into resized version and uploading to s3 using aws elemental mediaconvert. Is there a setting in the elemental media convert job which I can use to set the CacheControl max-age header so that it gets applied to the resized version of the video?
One of the job setting that I use is shared below
{
ContainerSettings: {
Container: "MP4",
Mp4Settings: {
CslgAtom: "INCLUDE",
FreeSpaceBox: "EXCLUDE",
MoovPlacement: "PROGRESSIVE_DOWNLOAD",
},
},
VideoDescription: {
Width: 720,
ScalingBehavior: "DEFAULT",
Height: 1280,
TimecodeInsertion: "DISABLED",
AntiAlias: "ENABLED",
Sharpness: 50,
CodecSettings: {
Codec: "H_264",
H264Settings: {
InterlaceMode: "PROGRESSIVE",
NumberReferenceFrames: 3,
Syntax: "DEFAULT",
Softness: 0,
GopClosedCadence: 1,
GopSize: 90,
Slices: 1,
GopBReference: "DISABLED",
MaxBitrate: 3000000,
SlowPal: "DISABLED",
SpatialAdaptiveQuantization: "ENABLED",
TemporalAdaptiveQuantization: "ENABLED",
FlickerAdaptiveQuantization: "DISABLED",
EntropyEncoding: "CABAC",
FramerateControl: "INITIALIZE_FROM_SOURCE",
RateControlMode: "QVBR",
QvbrSettings: {
QvbrQualityLevel: 7,
},
CodecProfile: "MAIN",
Telecine: "NONE",
MinIInterval: 0,
AdaptiveQuantization: "HIGH",
CodecLevel: "AUTO",
FieldEncoding: "PAFF",
SceneChangeDetect: "ENABLED",
QualityTuningLevel: "SINGLE_PASS",
FramerateConversionAlgorithm: "DUPLICATE_DROP",
UnregisteredSeiTimecode: "DISABLED",
GopSizeUnits: "FRAMES",
ParControl: "INITIALIZE_FROM_SOURCE",
NumberBFramesBetweenReferenceFrames: 2,
RepeatPps: "DISABLED",
},
},
AfdSignaling: "NONE",
DropFrameTimecode: "ENABLED",
RespondToAfd: "NONE",
ColorMetadata: "INSERT",
},
AudioDescriptions: [
{
AudioTypeControl: "FOLLOW_INPUT",
CodecSettings: {
Codec: "AAC",
AacSettings: {
AudioDescriptionBroadcasterMix: "NORMAL",
Bitrate: 96000,
RateControlMode: "CBR",
CodecProfile: "LC",
CodingMode: "CODING_MODE_2_0",
RawFormat: "NONE",
SampleRate: 48000,
Specification: "MPEG4",
},
},
LanguageCodeControl: "FOLLOW_INPUT",
},
],
Extension: ".mp4",
},
],
OutputGroupSettings: {
Type: "FILE_GROUP_SETTINGS",
FileGroupSettings: {
Destination: "",
DestinationSettings: {
S3Settings: {
AccessControl: {
CannedAcl: "PUBLIC_READ",
},
},
},
},
},
}
MediaConvert does not presently have a setting that allows adding user metadata (e.g. HTTP headers) to its outputs.
This needs to be implemented as a 'post processing' step to your workflow.
Since MediaConvert uses Amazon S3 as its output destination, you would typically set object metadata (i.e. Cache-Control headers) in Amazon S3 at the time you upload the object. Once the object is uploaded, you cannot modify object metadata. The only way to modify object metadata is to make a copy of the object and set the metadata.
There are a few approaches to do this:
A. You can add cache-control headers to your objects using the Amazon S3 console. The console handles the copying of the object with the new metadata behind the scenes.
Adding headers to your objects using the Amazon S3 console : https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationAddingHeadersInS3 Editing object metadata in the Amazon S3 console : https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-object-metadata.html
B. You can automate adding metadata by: Configuring an S3 Event notification on your destination S3 bucket, that monitors for 'New object created events' and subsequently triggers Lambda function. The Lambda function code then makes a copy of the recently created object (mp4 file) and sets the metadata.
Amazon S3 Event Notifications : https://docs.aws.amazon.com/AmazonS3/latest/userguide/NotificationHowTo.html
Tutorial: Using an Amazon S3 trigger to invoke a Lambda function : https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html
C. Since you are looking to set Cache-Control headers on your objects, I assume that also intend to make your transcoded videos available via a browser or shared cache (e.g. CDN). Should you be using a CDN like CloudFront, you can opt to configure CloudFront to add one or more HTTP headers to the responses that it sends to viewers. Making these changes doesn't require writing code or changing the origin. The HTTP headers that you can add include the Cache-Control header.
Adding HTTP headers to CloudFront responses : https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-response-headers.html
To do so: