{OCI Media Services} Getting Started with Media Services



https://docs.oracle.com/en-us/iaas/Content/media-services/get-started.htm

https://qiita.com/nakasato310/items/bdf430947f516c48276a


OCI CLI バージョン: 3.44.0

 

-- 1. コンパートメント作成

oci iam compartment create \
--compartment-id ocid1.tenancy.oc1..111111111111111111111111111111111111111111111111111111111111 \
--description cmp02 \
--name cmp02


oci iam compartment list \
--query 'data[?"name"==`'cmp02'`].id | [0]' \
--raw-output

 

-- 2. バケット作成 2個

 

oci os bucket list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 

 

oci os bucket create \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--name bucket01 \
--auto-tiering Disabled \
--object-events-enabled false \
--public-access-type NoPublicAccess \
--storage-tier Standard \
--versioning Disabled

oci os bucket create \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--name bucket02 \
--auto-tiering Disabled \
--object-events-enabled false \
--public-access-type NoPublicAccess \
--storage-tier Standard \
--versioning Disabled


-- 3. 動画ファイル登録


oci os object list \
--bucket-name bucket01

 

oci os object put \
--bucket-name bucket01 \
--file mov_hts-samp003.mp4


-- 4. ポリシー設定

oci iam policy list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 


oci iam policy create \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--description polyc01 \
--name polyc01 \
--statements '[
"Allow service mediaservices to read object-family in compartment cmp02",
"Allow service mediaservices to read media-family in compartment cmp02",
]'

 

 

-- 5. メディアワークフロー作成

oci media-services media-workflow list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--all

 

 

 

oci media-services media-workflow create --generate-full-command-json-input

cat <<-'EOF' > mf01.json

{
    "compartment-id": "ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111",
    "display-name": "mf01",
    "parameters": {
      "input": {
        "bucketName": "bucket01",
        "namespaceName": "111111111111"
      },
      "output": {
        "assetCompartmentId": "ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111",
        "basePrefix": "${/output/objectNamePath}",
        "bucketName": "bucket02",
        "namespaceName": "111111111111",
        "objectName": "output/",
        "objectNameFilename": "",
        "objectNamePath": "output/"
      },
      "taskOutput": {
        "thumbnail": "Thumbnail/ /",
        "transcode": "Transcode/"
      }
    },
    "tasks": [
      {
        "key": "getFiles",
        "parameters": {
          "taskParameters": [
            {
              "bucketName": "${/input/bucketName}",
              "namespaceName": "${/input/namespaceName}",
              "objectName": "${/input/objectName}",
              "target": "${/input/objectName}"
            }
          ]
        },
        "prerequisites": ,
        "type": "getFiles",
        "version": 1
      },
      {
        "key": "transcode",
        "parameters": {
          "standardTranscode": {
            "audioCodec": "aac",
            "input": "${/getFiles/taskParameters/0/target}",
            "ladder": [
              {
                "size": {
                  "height": 1080,
                  "resizeMethod": "scale"
                }
              },
              {
                "size": {
                  "height": 720,
                  "resizeMethod": "scale"
                }
              },
              {
                "size": {
                  "height": 480,
                  "resizeMethod": "scale"
                }
              },
              {
                "size": {
                  "height": 360,
                  "resizeMethod": "scale"
                }
              }
            ],
            "outputPrefix": "${/output/objectNameFilename}standardTranscode",
            "packaging": {
              "packageType": "hls",
              "segmentLength": 6
            },
            "videoCodec": "h264"
          },
          "transcodeType": "standardTranscode"
        },
        "prerequisites": [
          "getFiles"
        ],
        "type": "transcode",
        "version": 1
      },
      {
        "key": "thumbnail",
        "parameters": {
          "thumbnails": {
            "frameSelectors": [
              {
                "format": "jpg",
                "namePrefix": "thumbnail",
                "sizes": [
                  {
                    "width": 390
                  },
                  {
                    "width": 196
                  }
                ]
              }
            ],
            "input": "${/getFiles/taskParameters/0/target}"
          }
        },
        "prerequisites": [
          "transcode"
        ],
        "type": "thumbnail",
        "version": 1
      },
      {
        "key": "putFiles",
        "parameters": {
          "taskParameters": [
            {
              "assetCompartmentId": "${/output/assetCompartmentId}",
              "bucketName": "${/output/bucketName}",
              "namespaceName": "${/output/namespaceName}",
              "objectName": "${/output/basePrefix}${/taskOutput/thumbnail}${/output/objectNameFilename}",
              "registerMetadata": true,
              "source": "*.${/thumbnail/thumbnails/frameSelectors/0/format}"
            },
            {
              "assetCompartmentId": "${/output/assetCompartmentId}",
              "bucketName": "${/output/bucketName}",
              "namespaceName": "${/output/namespaceName}",
              "objectName": "${/output/basePrefix}${/taskOutput/transcode}",
              "registerMetadata": true,
              "source": "*.m3u8"
            },
            {
              "assetCompartmentId": "${/output/assetCompartmentId}",
              "bucketName": "${/output/bucketName}",
              "namespaceName": "${/output/namespaceName}",
              "objectName": "${/output/basePrefix}${/taskOutput/transcode}",
              "registerMetadata": true,
              "source": "*.fmp4"
            }
          ]
        },
        "prerequisites": [
          "thumbnail"
        ],
        "type": "putFiles",
        "version": 1
      }
    ]
}

EOF

cat mf01.json

oci media-services media-workflow create \
--from-json file://mf01.json 

 


oci media-services media-workflow get \
--media-workflow-id ocid1.mediaworkflow.oc1.iad.111111111111111111111111111111111111111111111111111111111111

 

oci media-services media-workflow delete \
--media-workflow-id ocid1.mediaworkflow.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--force 

 

-- 6. メディアワークフロージョブ実行

oci media-services media-workflow-job list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--all


oci media-services media-workflow-job create-media-workflow-job-by-id --generate-full-command-json-input

cat <<-'EOF' > mfj01.json

{
    "compartment-id": "ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111",
    "display-name": "mfj01",
    "media-workflow-id": "ocid1.mediaworkflow.oc1.iad.111111111111111111111111111111111111111111111111111111111111",
    "parameters": {
      "input": {
        "bucketName": "bucket01",
        "namespaceName": "111111111111",
        "objectName": "mov_hts-samp003.mp4",
        "objectNameFilename": "mov_hts-samp003"
      },
      "output": {
        "assetCompartmentId": "ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111",
        "basePrefix": "${/output/objectNamePath}",
        "bucketName": "bucket02",
        "namespaceName": "111111111111",
        "objectName": "output_1/ ",
        "objectNameFilename": " ",
        "objectNamePath": "output_1/"
      },
      "taskOutput": {
        "thumbnail": "Thumbnail/ /",
        "transcode": "Transcode/"
      }
    }
}


EOF

cat mfj01.json


oci media-services media-workflow-job create-media-workflow-job-by-id \
--from-json file://mfj01.json 

 


oci media-services media-workflow-job get \
--media-workflow-job-id ocid1.mediaworkflowjob.oc1.iad.111111111111111111111111111111111111111111111111111111111111


ジョブが正常終了するまで待つ

 

 

-- 7. Distribution Channel作成

oci media-services stream-distribution-channel list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--all 

 


oci media-services stream-distribution-channel create --generate-full-command-json-input

oci media-services stream-distribution-channel create \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--display-name sd01

 

oci media-services stream-distribution-channel get \
--stream-distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111


oci media-services stream-distribution-channel delete \
--stream-distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--force 

 

-- 8. Stream Cdn Config作成


oci media-services stream-cdn-config list \
--distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--all 


oci media-services stream-cdn-config create-edge-stream-cdn-config \
--display-name cdn01 \
--distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111 

 

oci media-services stream-cdn-config delete \
--stream-cdn-config-id ocid1.streamcdnconfig.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--force 

 


-- 9. Packaging Configuration作成

oci media-services stream-packaging-config list \
--distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--all 

 


oci media-services stream-packaging-config create-stream-packaging-config-encryption-none --generate-full-command-json-input


oci media-services stream-packaging-config create-stream-packaging-config-encryption-none \
--display-name sp01 \
--distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--segment-time-in-seconds 20 \
--stream-packaging-format HLS 

 

oci media-services stream-packaging-config get \
--stream-packaging-config-id ocid1.streampackagingconfig.oc1.iad.111111111111111111111111111111111111111111111111111111111111


oci media-services stream-packaging-config delete \
--stream-packaging-config-id ocid1.streampackagingconfig.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--force 

 

 

-- 10. Distribution ChannelにPlaylist Assetを取り込む

oci media-services media-asset list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--all


oci media-services media-asset create --generate-full-command-json-input


cat <<-'EOF' > ma01.json

{
    "bucket-name": "bucket02",
    "compartment-id": "ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111",
    "display-name": "ma01",
    "media-asset-tags": ,
    "metadata": [],
    "namespace-name": "111111111111",
    "object-name": "output_1/Transcode/master.m3u8",
    "type": "PLAYLIST"
}

EOF

 

cat ma01.json


oci media-services media-asset create \
--from-json file://ma01.json 

 

oci media-services media-asset get  \
--media-asset-id ocid1.mediaasset.oc1.iad.111111111111111111111111111111111111111111111111111111111111


--★ After the media asset ID is created, you can ingest the asset.


oci media-services stream-distribution-channel ingest \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--media-asset-id ocid1.mediaasset.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--stream-distribution-channel-id ocid1.streamdistributionchannel.oc1.iad.111111111111111111111111111111111111111111111111111111111111

 

画面反映まで時間が少しかかる

 

oci media-services media-asset delete \
--media-asset-id ocid1.mediaasset.oc1.iad.111111111111111111111111111111111111111111111111111111111111 \
--force 

 


-- 11. 動確


https://hlsjs.video-dev.org/demo/


Playlist AssetsからURL取得

 


-- 12. クリーンアップ

Playlist Assets削除
Packaging Configuration削除
Stream Cdn Config削除
Distribution Channel削除
メディアワークフロー削除

 

ポリシー削除

oci iam policy list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--query 'data[?"description"==`'polyc01'`].id | [0]' \
--raw-output


oci iam policy delete \
--policy-id ocid1.policy.oc1..111111111111111111111111111111111111111111111111111111111111 \
--force


バケット削除

oci os bucket list \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 

 


oci os bucket delete \
--name bucket01 \
--empty \
--force

oci os bucket delete \
--name bucket02 \
--empty \
--force

 

コンパートメント削除

oci iam compartment list \
--query 'data[?"name"==`'cmp02'`].id | [0]' \
--raw-output


oci iam compartment delete \
--compartment-id ocid1.compartment.oc1..111111111111111111111111111111111111111111111111111111111111 \
--force