90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/service/mediaconvert"
|
|
"github.com/aws/aws-sdk-go-v2/service/mediaconvert/types"
|
|
)
|
|
|
|
var MediaConvertClient MediaConvert
|
|
|
|
type MediaConvert interface {
|
|
QueueEncodingJob(ctx context.Context, key string) (string, error)
|
|
}
|
|
|
|
type MediaConvertConcrete struct {
|
|
MediaConvertClient *mediaconvert.Client
|
|
Role string
|
|
InputBucket string
|
|
OutputBucket string
|
|
}
|
|
|
|
func (svc MediaConvertConcrete) QueueEncodingJob(ctx context.Context, key string) (string, error) {
|
|
input := fmt.Sprintf("s3://%s/%s", svc.InputBucket, key)
|
|
destination := fmt.Sprintf("s3://%s/%s", svc.OutputBucket, key)
|
|
|
|
job, err := svc.MediaConvertClient.CreateJob(ctx, &mediaconvert.CreateJobInput{
|
|
Role: &svc.Role,
|
|
Settings: &types.JobSettings{
|
|
Inputs: []types.Input{
|
|
{
|
|
FileInput: &input,
|
|
AudioSelectors: map[string]types.AudioSelector{
|
|
"Audio Selector 1": {
|
|
DefaultSelection: types.AudioDefaultSelectionDefault,
|
|
},
|
|
},
|
|
VideoSelector: &types.VideoSelector{},
|
|
},
|
|
},
|
|
OutputGroups: []types.OutputGroup{
|
|
{
|
|
Name: aws.String("File Group"),
|
|
OutputGroupSettings: &types.OutputGroupSettings{
|
|
Type: types.OutputGroupTypeFileGroupSettings,
|
|
FileGroupSettings: &types.FileGroupSettings{
|
|
Destination: &destination,
|
|
},
|
|
},
|
|
Outputs: []types.Output{
|
|
{
|
|
ContainerSettings: &types.ContainerSettings{
|
|
Container: types.ContainerTypeMp4,
|
|
},
|
|
VideoDescription: &types.VideoDescription{
|
|
CodecSettings: &types.VideoCodecSettings{
|
|
Codec: types.VideoCodecH264,
|
|
H264Settings: &types.H264Settings{
|
|
RateControlMode: types.H264RateControlModeQvbr,
|
|
MaxBitrate: aws.Int32(5000000),
|
|
},
|
|
},
|
|
},
|
|
AudioDescriptions: []types.AudioDescription{
|
|
{
|
|
CodecSettings: &types.AudioCodecSettings{
|
|
Codec: types.AudioCodecAac,
|
|
AacSettings: &types.AacSettings{
|
|
Bitrate: aws.Int32(96000),
|
|
CodingMode: types.AacCodingModeCodingMode20,
|
|
SampleRate: aws.Int32(48000),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return aws.ToString(job.Job.Id), nil
|
|
}
|