Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

amazon web services - Have an AWS MediaConvert job template output to the same directory

I'm trying to set up a job in Amazon's MediaConvert service which will take any video I upload to an S3 bucket and convert it to a streaming-friendly format. For the most part, this seems to be working - my app calls the API to run the job each time I upload a video.

However, for convenience (to make it easier to find the outputs for a specific file), I would like to put the output files into the same directory that the input file was found in.

Is there a way to set a job template's output to a path relative to the input? Alternatively, is it possible to override the output directory without having to define the entire job from scratch in the Java code?

This is how I'm setting the input directory in the Java API:

CreateJobRequest request = CreateJobRequest.builder()
    .role(roleName)
    .jobTemplate("Process uploaded videos") // Matches a custom template I made in AWS
    .settings(JobSettings.builder()
        .inputs(Input.builder()
            .fileInput("s3://" + mConfig.bucket + "/" + mFolder + filename)
            .build())
        .build())
    .build();

Updated version with output path specified:

CreateJobRequest request = CreateJobRequest.builder()
    .role(MEDIACONVERT_ROLE)
    .jobTemplate("Process uploaded videos") // Matches a custom template I made in AWS
    .settings(JobSettings.builder()
        .inputs(Input.builder()
            .fileInput("s3://" + mConfig.bucket + "/" + mFolder + filename)
            .build())
        .outputGroups(OutputGroup.builder()
            .name("Streaming video") // Matches the name of the output group in the template
            .outputGroupSettings(OutputGroupSettings.builder()
                .type(OutputGroupType.FILE_GROUP_SETTINGS)
                .fileGroupSettings(FileGroupSettings.builder()
                    .destination("s3://" + mConfig.bucket + "/" + mFolder) // Put output in the same folder as the input
                    .build())
                .build())
            .build())
        .build())
    .build();
question from:https://stackoverflow.com/questions/65834880/have-an-aws-mediaconvert-job-template-output-to-the-same-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no native method in AWS Elemental MediaConvert for setting a relative path for the output based on the location of the input, however you are right in that you can override parameters from a template without needing to define the entire job from scratch.

For instance, here's an AWS CLI (boto3) JSON example of submitting job using a template that does not reference presets.

Notes: This template contains an input array object (notice there is not a FileURI parameter, you will add this on job create)

{
  "Queue": "arn:aws:mediaconvert:us-west-2:111122223333:queues/Default",
  "Name": "Test_MP4", 
  "Description":"Test MP4"
  "Settings": {
    "OutputGroups": [
      {
        "Name": "File Group",
        "Outputs": [
          {
            "ContainerSettings": {
              "Container": "MP4",
              "Mp4Settings": {
                "CslgAtom": "EXCLUDE",
                "FreeSpaceBox": "EXCLUDE",
                "MoovPlacement": "NORMAL"
              }
            },
            "VideoDescription": {
              "Width": 3840,
              "ScalingBehavior": "DEFAULT",
              "Height": 2160,
              "VideoPreprocessors": {
                "Deinterlacer": {
                  "Algorithm": "INTERPOLATE",
                  "Mode": "DEINTERLACE",
                  "Control": "NORMAL"
                }
              },
              "TimecodeInsertion": "DISABLED",
              "AntiAlias": "ENABLED",
              "Sharpness": 50,
              "CodecSettings": {
                "Codec": "H_265",
                "H265Settings": {
                  "InterlaceMode": "PROGRESSIVE",
                  "ParNumerator": 1,
                  "NumberReferenceFrames": 3,
                  "FramerateDenominator": 1001,
                  "GopClosedCadence": 1,
                  "AlternateTransferFunctionSei": "DISABLED",
                  "HrdBufferInitialFillPercentage": 90,
                  "GopSize": 48,
                  "Slices": 4,
                  "GopBReference": "ENABLED",
                  "HrdBufferSize": 20000000,
                  "SlowPal": "DISABLED",
                  "ParDenominator": 1,
                  "SpatialAdaptiveQuantization": "ENABLED",
                  "TemporalAdaptiveQuantization": "ENABLED",
                  "FlickerAdaptiveQuantization": "DISABLED",
                  "Bitrate": 10000000,
                  "FramerateControl": "SPECIFIED",
                  "RateControlMode": "CBR",
                  "CodecProfile": "MAIN_MAIN",
                  "Tiles": "ENABLED",
                  "Telecine": "NONE",
                  "FramerateNumerator": 24000,
                  "MinIInterval": 0,
                  "AdaptiveQuantization": "HIGH",
                  "CodecLevel": "LEVEL_5",
                  "SceneChangeDetect": "ENABLED",
                  "QualityTuningLevel": "MULTI_PASS_HQ",
                  "FramerateConversionAlgorithm": "DUPLICATE_DROP",
                  "UnregisteredSeiTimecode": "DISABLED",
                  "GopSizeUnits": "FRAMES",
                  "ParControl": "SPECIFIED",
                  "NumberBFramesBetweenReferenceFrames": 3,
                  "TemporalIds": "DISABLED",
                  "SampleAdaptiveOffsetFilterMode": "ADAPTIVE"
                }
              },
              "AfdSignaling": "NONE",
              "DropFrameTimecode": "ENABLED",
              "RespondToAfd": "NONE",
              "ColorMetadata": "INSERT"
            },
            "AudioDescriptions": [
              {
                "AudioTypeControl": "FOLLOW_INPUT",
                "CodecSettings": {
                  "Codec": "AAC",
                  "AacSettings": {
                    "AudioDescriptionBroadcasterMix": "NORMAL",
                    "Bitrate": 160000,
                    "RateControlMode": "CBR",
                    "CodecProfile": "LC",
                    "CodingMode": "CODING_MODE_2_0",
                    "RawFormat": "NONE",
                    "SampleRate": 48000,
                    "Specification": "MPEG4"
                  }
                },
                "LanguageCodeControl": "FOLLOW_INPUT",
                "AudioType": 0
              }
            ],
            "NameModifier": "_1"
          }
        ],
        "OutputGroupSettings": {
          "Type": "FILE_GROUP_SETTINGS",
          "FileGroupSettings": {
            "Destination": "s3://myawsbucket/out/"
          }
        }
      }
    ],
    "AdAvailOffset": 0,
    "Inputs": [
      {
        "AudioSelectors": {
          "Audio Selector 1": {
            "Offset": 0,
            "DefaultSelection": "DEFAULT",
            "ProgramSelection": 1
          }
        },
        "VideoSelector": {
          "ColorSpace": "FOLLOW"
        },
        "FilterEnable": "AUTO",
        "PsiControl": "USE_PSI",
        "FilterStrength": 0,
        "DeblockFilter": "DISABLED",
        "DenoiseFilter": "DISABLED",
        "TimecodeSource": "EMBEDDED"
      }
    ]
  }
}

The following JSON payload adds an input and a caption selector on input as well as a caption track to the output, and it changes the destination location for the output file.

Note: You will need to make sure to include you job template name as well as the role you want the service to assume (i.e. what you set up in Setting up using IAM)

{
  "Settings": {
    "OutputGroups": [
      {
        "Name": "File Group",
        "Outputs": [
          {
          "CaptionDescriptions": [
              {
                "DestinationSettings": {
                  "DestinationType": "EMBEDDED"
                },
                "CaptionSelectorName": "Captions Selector 1",
                "LanguageCode": "ENG"
              }
            ]
          }
        ],
        "OutputGroupSettings": {
          "Type": "FILE_GROUP_SETTINGS",
          "FileGroupSettings": {
            "Destination": "s3://myawsbucket/newfolder/out/"
          }
        }
      }
    ],
    "AdAvailOffset": 0,
    "Inputs": [
      {
        "AudioSelectors": {
          "Audio Selector 1": {
            "Offset": 0,
            "DefaultSelection": "DEFAULT",
            "ProgramSelection": 1
          }
        },
        "VideoSelector": {
          "ColorSpace": "FOLLOW"
        },
        "FilterEnable": "AUTO",
        "PsiControl": "USE_PSI",
        "FilterStrength": 0,
        "DeblockFilter": "DISABLED",
        "DenoiseFilter": "DISABLED",
        "TimecodeSource": "EMBEDDED",
        "FileInput": "s3://myawsbucket/input/test.mp4",
        "CaptionSelectors": {
          "Captions Selector 1": {
            "SourceSettings": {
              "SourceType": "SCC",
              "FileSourceSettings": {
                "SourceFile": "s3://myawsbucket/input/Captions/SCC/test.scc"
              }
            }
          }
        }
      }
    ]
  },
  "JobTemplate": "Test_MP4",
  "Role": "arn:aws:iam::111122223333:role/MediaConvertRole"
}

To only change the destination, you would use this JSON:

{
  "Settings": {
    "OutputGroups": [
      {
        "OutputGroupSettings": {
          "Type": "FILE_GROUP_SETTINGS",
          "FileGroupSettings": {
            "Destination": "s3://myawsbucket/newfolder/out/"
          }
        }
      }
    ],
    "Inputs": [
      {
        "FileInput": "s3://myawsbucket/input/test.mp4"
      }
    ]
  },
  "JobTemplate": "Test_MP4",
  "Role": "arn:aws:iam::111122223333:role/MediaConvertRole"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...