Set segment duration with media convert

837 views Asked by At

With AWS media convert everytime I convert an mp4 (6 second video) to a dash, the segment duration is about 30 seconds however I'd much appreciate if it were 1 second or less:

      <SegmentTemplate timescale="90000" duration="324000" startNumber="1"/>
      <Representation id="1" width="1280" height="720" bandwidth="72000000" codecs="avc1.4d4032">
        <SegmentTemplate media="5f8283b60a3ac3640191892_$Number%09d$.mp4" initialization="5f8283b60a3ac3640191892init.mp4" duration="324000" startNumber="1"/>
      </Representation>
      <Representation id="2" width="1920" height="1080" bandwidth="16200000" codecs="avc1.4d4029">
        <SegmentTemplate media="5f8283b60a3ac3640191891_$Number%09d$.mp4" initialization="5f8283b60a3ac3640191891init.mp4" duration="324000" startNumber="1"/>
      </Representation>
    </AdaptationSet>

I've tried messing with the job settings, but nothing I did seemed to work. Sometimes I got it down to 10 seconds, but that still isn't great, anyway here are the settings I used:

$jobSetting = [
      "OutputGroups"=> [
      [
        "CustomName"=> "nicenice",
        "Name"=> "DASH ISO",
        "Outputs"=> [
          [
            "ContainerSettings"=> [
              "Container"=> "MPD"
            ],
            "VideoDescription"=> [
              "Width"=> 1920,
              "ScalingBehavior"=> "DEFAULT",
              "Height"=> 1080,
              "TimecodeInsertion"=> "DISABLED",
              "AntiAlias"=> "ENABLED",
              "Sharpness"=> 50,
              "CodecSettings"=> [
                "Codec"=> "H_264",
                "H264Settings"=> [
                  "InterlaceMode"=> "PROGRESSIVE",
                  "NumberReferenceFrames"=> 3,
                  "Syntax"=> "DEFAULT",
                  "Softness"=> 0,
                  "GopClosedCadence"=> 1,
                  "GopSize"=> 60,
                  "Slices"=> 1,
                  "GopBReference"=> "DISABLED",
                  "SlowPal"=> "DISABLED",
                  "SpatialAdaptiveQuantization"=> "ENABLED",
                  "TemporalAdaptiveQuantization"=> "ENABLED",
                  "FlickerAdaptiveQuantization"=> "DISABLED",
                  "EntropyEncoding"=> "CABAC",
                  "Bitrate"=> 16200000,
                  "FramerateControl"=> "INITIALIZE_FROM_SOURCE",
                  "RateControlMode"=> "CBR",
                  "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",
                  "DynamicSubGop"=> "STATIC"
                ]
              ],
              "AfdSignaling"=> "NONE",
              "DropFrameTimecode"=> "ENABLED",
              "RespondToAfd"=> "NONE",
              "ColorMetadata"=> "INSERT"
            ],
            "NameModifier"=> "1"
          ],
          [
            "ContainerSettings"=> [
              "Container"=> "MPD"
            ],
            "VideoDescription"=> [
              "Width"=> 1280,
              "ScalingBehavior"=> "DEFAULT",
              "Height"=> 720,
              "TimecodeInsertion"=> "DISABLED",
              "AntiAlias"=> "ENABLED",
              "Sharpness"=> 50,
              "CodecSettings"=> [
                "Codec"=> "H_264",
                "H264Settings"=> [
                  "InterlaceMode"=> "PROGRESSIVE",
                  "NumberReferenceFrames"=> 3,
                  "Syntax"=> "DEFAULT",
                  "Softness"=> 0,
                  "GopClosedCadence"=> 1,
                  "GopSize"=> 60,
                  "Slices"=> 1,
                  "GopBReference"=> "DISABLED",
                  "SlowPal"=> "DISABLED",
                  "SpatialAdaptiveQuantization"=> "ENABLED",
                  "TemporalAdaptiveQuantization"=> "ENABLED",
                  "FlickerAdaptiveQuantization"=> "DISABLED",
                  "EntropyEncoding"=> "CABAC",
                  "Bitrate"=> 7200000,
                  "FramerateControl"=> "INITIALIZE_FROM_SOURCE",
                  "RateControlMode"=> "CBR",
                  "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",
                  "DynamicSubGop"=> "STATIC"
                ]
              ],
              "AfdSignaling"=> "NONE",
              "DropFrameTimecode"=> "ENABLED",
              "RespondToAfd"=> "NONE",
              "ColorMetadata"=> "INSERT"
            ],
            "NameModifier"=> "2"
          ],
          [
            "ContainerSettings"=> [
              "Container"=> "MPD"
            ],
            "AudioDescriptions"=> [
              [
                "AudioTypeControl"=> "FOLLOW_INPUT",
                "AudioSourceName"=> "Audio Selector 1",
                "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"
              ]
            ],
            "NameModifier"=> "3"
          ]
        ],
        "OutputGroupSettings"=> [
          "Type"=> "DASH_ISO_GROUP_SETTINGS",
          "DashIsoGroupSettings"=> [
            "SegmentLength"=> 1,
            "Destination"=> "s3://cactustestphp/videouploads/".$link . "/".$link,
            "FragmentLength"=> 2,
            "SegmentControl"=> "SEGMENTED_FILES",
            "MpdProfile"=> "MAIN_PROFILE",
            "HbbtvCompliance"=> "NONE"
          ]
        ]
      ]
    ],
    "AdAvailOffset"=> 0,
    "Inputs"=> [
      [
        "AudioSelectors"=> [
          "Audio Selector 1"=> [
            "Offset"=> 0,
            "DefaultSelection"=> "DEFAULT",
            "ProgramSelection"=> 1
          ]
        ],
        "VideoSelector"=> [
          "ColorSpace"=> "FOLLOW",
          "Rotate"=> "DEGREE_0",
          "AlphaBehavior"=> "DISCARD"
        ],
        "FilterEnable"=> "AUTO",
        "PsiControl"=> "USE_PSI",
        "FilterStrength"=> 0,
        "DeblockFilter"=> "DISABLED",
        "DenoiseFilter"=> "DISABLED",
        "InputScanType"=> "AUTO",
        "TimecodeSource"=> "ZEROBASED",
        "FileInput"=> "s3://cactustestphp/videouploads/test/". $fileid
      ]
      ]
    ];

Json:

{
  "Queue": "!!",
  "UserMetadata": {
    "Customer": "Amazon"
  },
  "Role": "!!",
  "Settings": {
    "OutputGroups": [
      {
        "CustomName": "nicenice",
        "Name": "DASH ISO",
        "Outputs": [
          {
            "ContainerSettings": {
              "Container": "MPD"
            },
            "VideoDescription": {
              "Width": 3840,
              "ScalingBehavior": "DEFAULT",
              "Height": 2160,
              "TimecodeInsertion": "DISABLED",
              "AntiAlias": "ENABLED",
              "Sharpness": 50,
              "CodecSettings": {
                "Codec": "H_264",
                "H264Settings": {
                  "InterlaceMode": "PROGRESSIVE",
                  "NumberReferenceFrames": 3,
                  "Syntax": "DEFAULT",
                  "Softness": 0,
                  "FramerateDenominator": 1,
                  "GopClosedCadence": 1,
                  "GopSize": 30,
                  "Slices": 1,
                  "GopBReference": "DISABLED",
                  "SlowPal": "DISABLED",
                  "SpatialAdaptiveQuantization": "ENABLED",
                  "TemporalAdaptiveQuantization": "ENABLED",
                  "FlickerAdaptiveQuantization": "DISABLED",
                  "EntropyEncoding": "CABAC",
                  "Bitrate": 66200000,
                  "FramerateControl": "SPECIFIED",
                  "RateControlMode": "CBR",
                  "CodecProfile": "MAIN",
                  "Telecine": "NONE",
                  "FramerateNumerator": 30,
                  "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",
                  "DynamicSubGop": "STATIC"
                }
              },
              "AfdSignaling": "NONE",
              "DropFrameTimecode": "ENABLED",
              "RespondToAfd": "NONE",
              "ColorMetadata": "INSERT"
            },
            "NameModifier": "1"
          },
          {
            "ContainerSettings": {
              "Container": "MPD"
            },
            "VideoDescription": {
              "Width": 1920,
              "ScalingBehavior": "DEFAULT",
              "Height": 1080,
              "TimecodeInsertion": "DISABLED",
              "AntiAlias": "ENABLED",
              "Sharpness": 50,
              "CodecSettings": {
                "Codec": "H_264",
                "H264Settings": {
                  "InterlaceMode": "PROGRESSIVE",
                  "NumberReferenceFrames": 3,
                  "Syntax": "DEFAULT",
                  "Softness": 0,
                  "FramerateDenominator": 1,
                  "GopClosedCadence": 1,
                  "GopSize": 30,
                  "Slices": 1,
                  "GopBReference": "DISABLED",
                  "SlowPal": "DISABLED",
                  "SpatialAdaptiveQuantization": "ENABLED",
                  "TemporalAdaptiveQuantization": "ENABLED",
                  "FlickerAdaptiveQuantization": "DISABLED",
                  "EntropyEncoding": "CABAC",
                  "Bitrate": 16200000,
                  "FramerateControl": "SPECIFIED",
                  "RateControlMode": "CBR",
                  "CodecProfile": "MAIN",
                  "Telecine": "NONE",
                  "FramerateNumerator": 30,
                  "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",
                  "DynamicSubGop": "STATIC"
                }
              },
              "AfdSignaling": "NONE",
              "DropFrameTimecode": "ENABLED",
              "RespondToAfd": "NONE",
              "ColorMetadata": "INSERT"
            },
            "NameModifier": "2"
          },
          {
            "ContainerSettings": {
              "Container": "MPD"
            },
            "VideoDescription": {
              "Width": 1280,
              "ScalingBehavior": "DEFAULT",
              "Height": 720,
              "TimecodeInsertion": "DISABLED",
              "AntiAlias": "ENABLED",
              "Sharpness": 50,
              "CodecSettings": {
                "Codec": "H_264",
                "H264Settings": {
                  "InterlaceMode": "PROGRESSIVE",
                  "NumberReferenceFrames": 3,
                  "Syntax": "DEFAULT",
                  "Softness": 0,
                  "FramerateDenominator": 1,
                  "GopClosedCadence": 1,
                  "GopSize": 30,
                  "Slices": 1,
                  "GopBReference": "DISABLED",
                  "SlowPal": "DISABLED",
                  "SpatialAdaptiveQuantization": "ENABLED",
                  "TemporalAdaptiveQuantization": "ENABLED",
                  "FlickerAdaptiveQuantization": "DISABLED",
                  "EntropyEncoding": "CABAC",
                  "Bitrate": 5200000,
                  "FramerateControl": "SPECIFIED",
                  "RateControlMode": "CBR",
                  "CodecProfile": "MAIN",
                  "Telecine": "NONE",
                  "FramerateNumerator": 30,
                  "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",
                  "DynamicSubGop": "STATIC"
                }
              },
              "AfdSignaling": "NONE",
              "DropFrameTimecode": "ENABLED",
              "RespondToAfd": "NONE",
              "ColorMetadata": "INSERT"
            },
            "NameModifier": "3"
          },
          {
            "ContainerSettings": {
              "Container": "MPD"
            },
            "VideoDescription": {
              "Width": 640,
              "ScalingBehavior": "DEFAULT",
              "Height": 360,
              "TimecodeInsertion": "DISABLED",
              "AntiAlias": "ENABLED",
              "Sharpness": 50,
              "CodecSettings": {
                "Codec": "H_264",
                "H264Settings": {
                  "InterlaceMode": "PROGRESSIVE",
                  "NumberReferenceFrames": 3,
                  "Syntax": "DEFAULT",
                  "Softness": 0,
                  "FramerateDenominator": 1,
                  "GopClosedCadence": 1,
                  "GopSize": 30,
                  "Slices": 1,
                  "GopBReference": "DISABLED",
                  "SlowPal": "DISABLED",
                  "SpatialAdaptiveQuantization": "ENABLED",
                  "TemporalAdaptiveQuantization": "ENABLED",
                  "FlickerAdaptiveQuantization": "DISABLED",
                  "EntropyEncoding": "CABAC",
                  "Bitrate": 1200000,
                  "FramerateControl": "SPECIFIED",
                  "RateControlMode": "CBR",
                  "CodecProfile": "MAIN",
                  "Telecine": "NONE",
                  "FramerateNumerator": 30,
                  "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",
                  "DynamicSubGop": "STATIC"
                }
              },
              "AfdSignaling": "NONE",
              "DropFrameTimecode": "ENABLED",
              "RespondToAfd": "NONE",
              "ColorMetadata": "INSERT"
            },
            "NameModifier": "4"
          },
          {
            "ContainerSettings": {
              "Container": "MPD"
            },
            "VideoDescription": {
              "Width": 256,
              "ScalingBehavior": "DEFAULT",
              "Height": 144,
              "TimecodeInsertion": "DISABLED",
              "AntiAlias": "ENABLED",
              "Sharpness": 50,
              "CodecSettings": {
                "Codec": "H_264",
                "H264Settings": {
                  "InterlaceMode": "PROGRESSIVE",
                  "NumberReferenceFrames": 3,
                  "Syntax": "DEFAULT",
                  "Softness": 0,
                  "FramerateDenominator": 1,
                  "GopClosedCadence": 1,
                  "GopSize": 30,
                  "Slices": 1,
                  "GopBReference": "DISABLED",
                  "SlowPal": "DISABLED",
                  "SpatialAdaptiveQuantization": "ENABLED",
                  "TemporalAdaptiveQuantization": "ENABLED",
                  "FlickerAdaptiveQuantization": "DISABLED",
                  "EntropyEncoding": "CABAC",
                  "Bitrate": 200000,
                  "FramerateControl": "SPECIFIED",
                  "RateControlMode": "CBR",
                  "CodecProfile": "MAIN",
                  "Telecine": "NONE",
                  "FramerateNumerator": 30,
                  "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",
                  "DynamicSubGop": "STATIC"
                }
              },
              "AfdSignaling": "NONE",
              "DropFrameTimecode": "ENABLED",
              "RespondToAfd": "NONE",
              "ColorMetadata": "INSERT"
            },
            "NameModifier": "5"
          },
          {
            "ContainerSettings": {
              "Container": "MPD"
            },
            "AudioDescriptions": [
              {
                "AudioTypeControl": "FOLLOW_INPUT",
                "AudioSourceName": "Audio Selector 1",
                "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"
              }
            ],
            "NameModifier": "6"
          }
        ],
        "OutputGroupSettings": {
          "Type": "DASH_ISO_GROUP_SETTINGS",
          "DashIsoGroupSettings": {
            "SegmentLength": 1,
            "Destination": "!!/videouploads/5fa1ababa7cea975176544/5fa1ababa7cea975176544",
            "FragmentLength": 1,
            "SegmentControl": "SEGMENTED_FILES",
            "MpdProfile": "MAIN_PROFILE",
            "HbbtvCompliance": "NONE"
          }
        }
      }
    ],
    "AdAvailOffset": 0,
    "Inputs": [
      {
        "AudioSelectors": {
          "Audio Selector 1": {
            "Offset": 0,
            "DefaultSelection": "DEFAULT",
            "ProgramSelection": 1
          }
        },
        "VideoSelector": {
          "ColorSpace": "FOLLOW",
          "Rotate": "DEGREE_0",
          "AlphaBehavior": "DISCARD"
        },
        "FilterEnable": "AUTO",
        "PsiControl": "USE_PSI",
        "FilterStrength": 0,
        "DeblockFilter": "DISABLED",
        "DenoiseFilter": "DISABLED",
        "TimecodeSource": "ZEROBASED",
        "FileInput": "!!/videouploads/test/5fa1ababa7cea975176544.mp4"
      }
    ]
  },
  "AccelerationSettings": {
    "Mode": "DISABLED"
  },
  "StatusUpdateInterval": "SECONDS_60",
  "Priority": 0
}

So, in other words, what would I have to change to make my segment duration set to 1 second or less?

1

There are 1 answers

2
Matthew Bournival On

Thank you for providing the job's JSON settings for further review. Looking at the OutputGroupSettings I can see that you are specifying a SegmentLength value of 1 second so the resulting fragmented MP4 files should be about 1 second in length give or take a few frames.

How are you confirming that the resulting fMP4 files are 30 and 10 seconds respectively? The most accurate way of determining this information is to combine a variant's init MP4 with one of the fragments into a separate file and observe it using a media inspector like Mediainfo or ffprobe. I used your job settings on an MP4 file I had available to me and confirmed that the resulting MP4 segments produces are 1 second in length:

Concatenate a segment with its init file for the full MP4 asset

$ cat 5fa1ababa7cea9751765441init.mp4 >> 5fa1ababa7cea9751765441_concat.mp4 && cat 5fa1ababa7cea9751765441_000000001.mp4 >> 5fa1ababa7cea9751765441_concat.mp4

Probe the newly concatenated file to review the details

$ ffprobe -hide_banner -i 5fa1ababa7cea9751765441_concat.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '5fa1ababa7cea9751765441_concat.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1dash
    creation_time   : 2020-11-20T20:30:59.000000Z
  Duration: 00:00:01.03, start: 0.066667, bitrate: 7658 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], 7648 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2020-11-20T20:30:59.000000Z
      handler_name    : ETI ISO Video Media Handler
      encoder         : Elemental H.264

I'm curious how you are confirming the resulting duration of each fMP4 asset and if you can try the above steps as well if you have not already done so.