LoginSignup
0
0

More than 1 year has passed since last update.

MediaLiveのInputSwitch【備忘録】

Last updated at Posted at 2021-06-13

MediaLiveのチャンネルのSchedule actionsAction type: Input Switchとして作成するとInputの切り替えができます。
"Schedule"とはいいつつ、Start typeimmediateにすることでactionは作成直後に実行されます。
これによって放送中の映像を任意のタイミングで切り替えることが可能になります。
今回はRTPM(Live配信)とMP4(S3に格納済み)で入力を切り替えてみます。

Input, Channelの作成

MediaStoreとか視聴用のHTMLは前もって作成しておきます。

  • Live配信用のInput
    Input type: RTMP(push)にします

  • MP4用のInput
    Input typeMP4に、Input sourceはコンテンツを格納したS3のURLを設定します。
    Screenshot_2021-06-13 MediaLive_1.png

  • Channnel
    上記のInput2つをアタッチします。
    MP4のコンテンツは繰り返し出力したいので、General input settings > Source End BehaviorLOOPを選択しておきます。
    Screenshot_2021-06-13 MediaLive.png

Lambda

チャンネルを切り替えるためのAPIをAPIGateway + Lambdaで作成します。
Pythonで実装します。

def lambda_handler(event, context):
    client = boto3.client('medialive')
    input = json.loads(event['body'])['Input']
    actionName = json.loads(event['body'])['ActionName']

    response = client.batch_update_schedule(
        ChannelId='<作成したChannelのID>',
        Creates={
            'ScheduleActions': [
                {
                    'ActionName': actionName,
                    'ScheduleActionSettings': {
                        'InputSwitchSettings': {
                            'InputAttachmentNameReference': input,
                            'UrlPath': []
                        }
                    },
                    'ScheduleActionStartSettings': {
                        'ImmediateModeScheduleActionStartSettings': {}
                    }
                }
            ]
        }
    )

Live配信中にコンソールで下記コマンドを打つとMP4の映像に切り替わります。
私の環境ではAPIを叩いてから切り替えに15secくらいかかりました。

curl -X POST https://{API Gatewayのドメイン}/{ステージ}/{リソース} -d '{"Input":"<MP4用のInput名>", "ActionName": "ChannelSwitch"}'

参考

参考にさせていただきました。

[アップデート] AWS Elemental MediaLiveでInputのスイッチングが可能になりました #reinvent #mediaservices | DevelopersIO
AWS Elemental MediaLiveで番組編成っぽいことをしてみた | DevelopersIO
AWS Elemental MediaLiveのスケジュール機能を使ってみた(コンソール版) - Qiita

0
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
0
0