Search code examples
javascriptfileaws-media-convert

AWS Elemental MediaConvert Video File trimming start and end duration


Just wanted to know How I handle a video trimming from AWS Elemental MediaConvert when the user upload's a video file through JavaScript


Solution

  • MediaConvert requires you to set the SDK to use a specific API input [1,2]

    The JavaScript SDK docs [3] call out how to define and create a job in MeidaConvert using the JS SDK. In order to accomplish input clipping you would need to add the InputClippings option to your Input JSON block. An example is below:

    "Inputs": [
          {
            "AudioSelectors": {
              "Audio Selector 1": {
                "Offset": 0,
                "DefaultSelection": "NOT_DEFAULT",
                "ProgramSelection": 1,
                "SelectorType": "TRACK",
                "Tracks": [
                  1
                ]
              }
            },
            "VideoSelector": {
              "ColorSpace": "FOLLOW"
            },
            "FilterEnable": "AUTO",
            "PsiControl": "USE_PSI",
            "FilterStrength": 0,
            "DeblockFilter": "DISABLED",
            "DenoiseFilter": "DISABLED",
            "TimecodeSource": "ZEROBASED",
            "FileInput": "s3://INPUT_BUCKET_AND_FILE_NAME",
            "InputClippings": [
              {
                "StartTimecode": "00:00:00:00",
                "EndTimecode": "00:05:00:00"
              }
            ]
          }
        ]
    

    Keep in mind that TimecodeSource will affect clipping regions. If you know the source file your user is uploading contains embedded timecode, you can change this to EMBEDDED, for more information see the documentation [4]

    == Resources ==
    [1] https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/emc-examples-jobs.html#emc-examples-jobs-configure-sdk
    [2] https://docs.aws.amazon.com/mediaconvert/latest/apireference/custom-endpoints.html
    [3]https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/emc-examples-jobs.html#emc-examples-jobs-spec
    [4] https://docs.aws.amazon.com/mediaconvert/latest/ug/setting-up-an-assembly-workflow-job.html