LoginSignup
2
0

More than 3 years have passed since last update.

AWS Elemental MediaLiveをAWS CLIでサクッと作成

Last updated at Posted at 2021-01-08

新年明けましておめでとうございます:cow::bamboo:
streampack risakoです。
年末年始はゆっくり過ごせましたか?私はあまり出かけずに寝正月を満喫しました笑
2021年もいろんなことを吸収してQiitaに残せるように頑張っていきます!

今回はAWS Elemental Medialive(以下MediaLive) inputとChannelをAWS CLI(以下、CLI)でサクッと作成する方法をご紹介します:point_up:
AWSマネジメントコンソールから作成するより、慣れてしまえばCLIのほうが時間短縮になるので複数作成する場合などは重宝します。
よくMediaLive inputやchannelを作成するという方はぜひ参考にして頂けたら幸いです:blush:

はじめに

  • MediaLiveをCLIで作成する場合、JSON形式で記述した設ファイルを用意する必要があります。 あらかじめ作成しておきましょう。
  • また、今回はAWS Elemental MediaStoreを使用します。 こちらも先に作成しておく必要があります。

JSONファイルの参考例をご紹介します。
注意:
JSONファイルは、必ず最初の文字を大文字にする必要があります。
小文字で作成してしまうとエラーが表示され、作成できません。

input作成

{
    "Name": "test-input",
    "Type": "RTMP_PUSH",
    "InputSecurityGroups": [
        "000000"
    ],
    "Destinations": [
        {
        "StreamName": "hoge/stream"
      }
    ]
}

変更が必要な箇所

項目 説明 備考
Name 任意のinput名を入力
Type 入力タイプを入力 JSONでのType記載方法はこちら
InputSecurityGroups 入力セキュリティグループID 既存のセキュリティグループがある場合は、そのIDを記載
StreamName 任意のStreamNameを入力 今回はSINGLE_INPUTで作成するため1つですが、STANDARD_INPUTの場合は2つ記載します。注:Typeによって設定内容が変わる

inputをCLIで作成する

$aws medialive --profile <名前付きプロファイル名> create-input --region <作成するリージョン> --cli-input-json file://<JSONファイル名>

【例】
$aws medialive --profile xxxx create-input --region ap-northeast-1 --cli-input-json file://test-input.json

Channel作成

ABRが1つのシンプルなチャンネル設定の例です。

{
  "Name": "test-channel",
  "InputAttachments": [
    {
      "InputId": "xxxxx",
      "InputAttachmentName": "test-input",
      "InputSettings": {
        "SourceEndBehavior": "CONTINUE",
        "InputFilter": "AUTO",
        "FilterStrength": 1,
        "DeblockFilter": "DISABLED",
        "DenoiseFilter": "DISABLED",
        "AudioSelectors": [
          {
          "Name": "Audio1"
          }
      ],
        "CaptionSelectors": []
      }
    }
  ],
  "Destinations": [
    {
      "Id": "hlsdestin",
      "Settings": [
        {
          "Url": "mediastoressl://xxxx.data.mediastore.ap-northeast-1.amazonaws.com/demo/liveA"
        },
      ],
      "MediaPackageSettings": []
    }
  ],
  "EncoderSettings": {
    "AudioDescriptions": [
      {
        "AudioSelectorName": "Audio1",
        "CodecSettings": {
          "AacSettings": {
            "InputType": "NORMAL",
            "Bitrate": 128000,
            "CodingMode": "CODING_MODE_2_0",
            "RawFormat": "NONE",
            "Spec": "MPEG4",
            "Profile": "LC",
            "RateControlMode": "CBR",
            "SampleRate": 48000
          }
        },
        "AudioTypeControl": "FOLLOW_INPUT",
        "LanguageCodeControl": "FOLLOW_INPUT",
        "Name": "audio_mid"
      }
    ],
    "CaptionDescriptions": [],
    "OutputGroups": [
      {
        "OutputGroupSettings": {
          "HlsGroupSettings": {
            "AdMarkers": [],
            "CaptionLanguageSetting": "OMIT",
            "CaptionLanguageMappings": [],
            "HlsCdnSettings": {
              "HlsMediaStoreSettings": {
                "NumRetries": 10,
                "ConnectionRetryInterval": 1,
                "RestartDelay": 15,
                "FilecacheDuration": 300,
                "MediaStoreStorageClass": "TEMPORAL"
              }
            },
            "InputLossAction": "EMIT_OUTPUT",
            "ManifestCompression": "NONE",
            "Destination": {
              "DestinationRefId": "hlsdestin"
            },
            "IvInManifest": "INCLUDE",
            "IvSource": "FOLLOWS_SEGMENT_NUMBER",
            "ClientCache": "ENABLED",
            "TsFileMode": "SEGMENTED_FILES",
            "ManifestDurationFormat": "FLOATING_POINT",
            "SegmentationMode": "USE_SEGMENT_DURATION",
            "RedundantManifest": "DISABLED",
            "OutputSelection": "MANIFESTS_AND_SEGMENTS",
            "StreamInfResolution": "INCLUDE",
            "IFrameOnlyPlaylists": "DISABLED",
            "IndexNSegments": 15,
            "ProgramDateTime": "EXCLUDE",
            "ProgramDateTimePeriod": 600,
            "KeepSegments": 30,
            "SegmentLength": 2,
            "TimedMetadataId3Frame": "PRIV",
            "TimedMetadataId3Period": 10,
            "HlsId3SegmentTagging": "DISABLED",
            "CodecSpecification": "RFC_4281",
            "DirectoryStructure": "SINGLE_DIRECTORY",
            "SegmentsPerSubdirectory": 10000,
            "Mode": "LIVE"
          }
        },
        "Name": "HLS Group",
        "Outputs": [
          {
            "OutputSettings": {
              "HlsOutputSettings": {
                "NameModifier": "_mid",
                "HlsSettings": {
                  "StandardHlsSettings": {
                    "M3u8Settings": {
                      "AudioFramesPerPes": 4,
                      "AudioPids": "492-498",
                      "NielsenId3Behavior": "NO_PASSTHROUGH",
                      "PcrControl": "PCR_EVERY_PES_PACKET",
                      "PmtPid": "480",
                      "ProgramNum": 1,
                      "Scte35Pid": "500",
                      "Scte35Behavior": "NO_PASSTHROUGH",
                      "TimedMetadataPid": "502",
                      "TimedMetadataBehavior": "NO_PASSTHROUGH",
                      "VideoPid": "481"
                    },
                    "AudioRenditionSets": "program_audio"
                  }
                },
                "H265PackagingType": "HVC1"
              }
            },
            "OutputName": "mid",
            "VideoDescriptionName": "video_mid",
            "AudioDescriptionNames": [
              "audio_mid"
            ],
            "CaptionDescriptionNames": []
          }
        ]
      }
    ],
    "TimecodeConfig": {
      "Source": "EMBEDDED"
    },
    "VideoDescriptions": [
      {
        "CodecSettings": {
          "H264Settings": {
              "AfdSignaling": "NONE",
              "ColorMetadata": "INSERT",
              "AdaptiveQuantization": "MEDIUM",
              "Bitrate": 2000000,
              "EntropyEncoding": "CABAC",
              "FlickerAq": "ENABLED",
              "FramerateControl": "SPECIFIED",
              "FramerateNumerator": 30,
              "FramerateDenominator": 1,
              "GopBReference": "DISABLED",
              "GopClosedCadence": 1,
              "GopNumBFrames": 1,
              "GopSize": 2,
              "GopSizeUnits": "SECONDS",
              "SubgopLength": "FIXED",
              "ScanType": "PROGRESSIVE",
              "Level": "H264_LEVEL_AUTO",
              "LookAheadRateControl": "MEDIUM",
              "NumRefFrames": 1,
              "ParControl": "INITIALIZE_FROM_SOURCE",
              "Profile": "MAIN",
              "RateControlMode": "CBR",
              "Syntax": "DEFAULT",
              "SceneChangeDetect": "ENABLED",
              "SpatialAq": "ENABLED",
              "TemporalAq": "ENABLED",
              "TimecodeInsertion": "DISABLED"
            }
      },
        "Height": 720,
        "Name": "video_mid",
        "RespondToAfd": "NONE",
        "Sharpness": 50,
        "ScalingBehavior": "DEFAULT",
        "Width": 1280
      }
    ]
  },
  "RoleArn": "arn:aws:iam::xxxxx:role/MediaLiveAccessRole",
  "InputSpecification": {
    "Codec": "AVC",
    "Resolution": "HD",
    "MaximumBitrate": "MAX_20_MBPS"
  },
  "LogLevel": "ERROR",
  "Tags": {},
  "ChannelClass": "SINGLE_PIPELINE"
}

変更が必要な箇所

項目 説明 備考
Name Channel名
InputId 先ほど作成したInputID
Url mediastoreのData endpoint https://ではなく、mediastoressl:// に変更が必要です。
AudioDescriptions 音声Bitrateなど、音声に関する設定を入力
VideoDescriptions 映像BitrateやFrame Rate、解像度など、映像に関する設定を入力
RoleArn MediaLiveのアクセス権をもつIAMRole 未作成の場合は、先に作成する必要があります。
ChannelClass 入力本数 SINGLE_PIPELINEeまたはSTANDARD

ChannelをCLIで作成!

$ aws medialive --profile <名前付きプロファイル名>  create-channel --region <作成するリージョン> --cli-input-json file://<JSONファイル名>

【例】
$ aws medialive --profile xxxx create-channel --region ap-northeast-1 --cli-input-json file://test-channel.json

以上で、作成は終了です!
コンソール画面に作成されたinputやChannelがあれば正常に作成できています!
同じ設定のChannelを複数作成する時など、一つテンプレートを用意しておくととても便利ですね:point_up:

今回もお読みいただきありがとうございました:smiley:

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0