實作即時 SSAI 的播放器增強功能

在本主題中,您將學習如何利用 Live SSAI 的播放程式增強功能來建立伺服器端廣告的即時串流,以改善使用者體驗。

簡介

Brightcove 的即時 SSAI 播放器增強功能可讓您透過廣告計數、廣告倒數計時器、點選廣告和隨附廣告來改善直播中的廣告突破。

您的廣告信息是使用廣告配置指定的,該配置可檢索VAST響應以標識要顯示的廣告。VAST文件還包含有關隨播廣告和信標網址的信息。

工作流程

要使用SSAI和播放器增強功能創建實時流,請按照以下步驟操作:

  1. 請您的客戶經理為您的帳戶啟用實時流,服務器端廣告插入(SSAI)和實時SSAI的播放器增強功能。
  2. 建立廣告組態
  3. 選用性:創建板岩資產以填充未使用的廣告時間
  4. 創建現場工作
  5. 創建播放令牌
  6. 配置播放器
  7. 開始流式傳輸
  8. 使用提示點觸發廣告(這可以在現場直播活動之前或之中進行)
  9. 清理

建立廣告組態

廣告配置定義了將服務器端廣告包含在實時流中所需的信息。這包括廣告提供商的網址,預期的廣告響應類型以及是否應發送信標。

若要建立新的廣告設定,請依照下列方式傳送POST要求:

方法 POST
URL https://api.bcovlive.io/v1/ssai/applications
標頭 X-API-KEY: your API KEY
內容類型:應用程序/JSON

設置帳戶後,將使用提供給您的API密鑰對所有請求進行身份驗證。密鑰在X-API-KEY標頭。

要求主體

有關請求正文字段的詳細信息,請參見實時API參考文件。

通過Live SSAI的播放器增強功能,突出顯示的字段可以在application_ad_configuration目的。

請求主體範例:

{
  "application_ad_configuration": {
	"ad_configuration_description": "your ad config description",
    "ad_configuration_expected_response_type": "Vast",
	"ad_configuration_headers_for_impressions": false,
	"ad_configuration_strategy": "SingleAdResponse",
	"ad_configuration_transforms": [],
	"ad_configuration_url_format": "your ad server",
    "ad_configuration_client_sdk_enabled": true,
    "client_options": {
      "show_ad_break_remaining_time": true / false,
      "show_ad_remaining_time": true / false,
      "show_number_of_remaining_ads": true / false,
      "client_only_tracking": true / false
    }
  },
  "application_description": "your application description"
}

以下是與使用 Live SSAI 增強播放器相關的廣告配置字段:

欄位 類型 必填 描述
ad_configuration_expected_response_type 字串 對於此功能,廣告配置的值必須為 Vast
ad_configuration_client_sdk_enabled 布林值 要啟用此功能,此字段的值必須為 true
client_options 物件 與 Player Enhancements 相關的字段對象
client_options.
show_ad_break_remaining_time
布林值 顯示廣告時間的剩餘時間
價值觀: true /false
client_options.
show_ad_remaining_time
布林值 顯示廣告的剩餘時間
價值觀: true /false
client_options.
show_number_of_remaining_ads
布林值 顯示廣告時段剩餘的廣告數量
價值觀: true /false
client_options.
client_only_tracking
布林值 禁用服務器端跟踪事件(印象/四分位數)
價值觀: true /false
默認: false


響應

範例回應:

{
  "application": {
    "application_description": "Test ad configuration",
    "application_ad_configuration": {
    "ad_configuration_description": "Ad config description",
    "ad_configuration_expected_response_type": "Vast",
    "ad_configuration_strategy": "SingleAdResponse",
    "ad_configuration_transforms": [],
    "ad_configuration_url_format": "https://solutions.brightcove.com/bcls/ads/simple-vast.xml",
    "ad_configuration_headers_for_impressions": false,
    "ad_configuration_client_sdk_enabled": true,
    "client_options": {
      "show_ad_break_remaining_time": true,
      "show_ad_remaining_time": true,
      "show_number_of_remaining_ads": true,
      "client_only_tracking": true
    }
    },
    "application_id": "1234567890abcdefghijkl",
    "application_type": "ads",
    "account_id": "001122334455aabbccddee"
  },
  "action": "inserted"
}

成功創建廣告配置後,請複制application_id(廣告配置ID)已生成。稍後將需要使用它來找到SSAI播放URL。

要列出,更新和刪除廣告配置,請參見管理廣告配置文件

建立即時工作

要創建現場工作,請發送POST要求如下:

方法 POST
URL https://api.bcovlive.io/v1/jobs
標頭 X-API-KEY: your API KEY
內容類型:應用程序/JSON

要求主體

有關請求正文字段的詳細信息,請參見實時API參考文件。

對於啟用了SSAI的現場作業,請設置ad_insertion: true在您的HTTP請求正文中。

樣品請求(視頻雲視頻)

要創建視頻雲視頻以用於直播,並從直播中創建 VOD 剪輯,請包括 videocloud 請求正文中的對象。有關詳細信息,請參見實時API:創建VOD剪輯文件。

服務器端廣告插入 (SSAI) 需要下面突出顯示的字段。

{
  "live_stream": true,
  "ad_insertion": true,
  "region": "us-west-2",
  "reconnect_time": 1800,
  "outputs": [{
      "label": "hls720p",
      "live_stream": true,
      "width": 1280,
      "height": 720,
      "video_codec": "h264",
      "h264_profile": "high",
      "video_bitrate": 2100,
      "segment_seconds": 4,
      "keyframe_interval": 60
    },
    {
      "label": "hls540p",
      "live_stream": true,
      "width": 960,
      "height": 540,
      "video_codec": "h264",
      "h264_profile": "main",
      "video_bitrate": 1500,
      "segment_seconds": 4,
      "keyframe_interval": 60
    },
    {
      "label": "hls360p",
      "live_stream": true,
      "width": 640,
      "height": 360,
      "video_codec": "h264",
      "h264_profile": "main",
      "video_bitrate": 800,
      "segment_seconds": 4,
      "keyframe_interval": 60
    }
  ],
  "videocloud": {
    "video": {
      "name": "Live SSAI VideoCloud Asset",
      "description": "",
      "long_description": "",
      "tags": [],
      "reference_id": "live_ssai_vc_asset",
      "link": {
      "url": "",
      "text": ""
    },
    "schedule": {
      "starts_at": null,
      "ends_at": null
    },
    "custom_fields": {}
    }
  }
}

樣品申請(遠程視頻)

要為您的直播使用遠程視頻,您的請求正文應類似於此。

服務器端廣告插入 (SSAI) 需要下面突出顯示的字段。

{
  "live_stream":true,
  "ad_insertion":true,
  "region":"us-west-2",
  "reconnect_time":1800,
  "outputs":[
    {
      "label": "hls720p",
      "live_stream": true,
      "width": 1280,
      "height": 720,
      "video_codec": "h264",
      "h264_profile": "high",
      "video_bitrate": 2100,
      "segment_seconds": 4,
      "keyframe_interval": 60
    },
    {
      "label": "hls540p",
      "live_stream": true,
      "width": 960,
      "height": 540,
      "video_codec": "h264",
      "h264_profile": "main",
      "video_bitrate": 1500,
      "segment_seconds": 4,
      "keyframe_interval": 60
    },
    {
      "label": "hls360p",
      "live_stream": true,
      "width": 640,
      "height": 360,
      "video_codec": "h264",
      "h264_profile": "main",
      "video_bitrate": 800,
      "segment_seconds": 4,
      "keyframe_interval": 60
    }
  ]
}

其他有用的資源:

響應

示例響應(視頻雲視頻)
{
 "id": "227356abcdefghijklmno12345",
 "outputs": [
  {
   "id": "0-2273561a201ec18",
   "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_0/chunklist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_0/chunklist_dvr.m3u8",
   "playback_url_vod": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_0/chunklist_vod.m3u8",
   "playback_added_cdns": [],
   "label": "hls720p"
  },
  {
   "id": "1-2273561a201e8c18",
   "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_1/chunklist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_1/chunklist_dvr.m3u8",
   "playback_url_vod": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_1/chunklist_vod.m3u8",
   "playback_added_cdns": [],
   "label": "hls540p"
  },
  {
   "id": "2-2273561a201ec18",
   "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_2/chunklist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_2/chunklist_dvr.m3u8",
   "playback_url_vod": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/profile_2/chunklist_vod.m3u8",
   "playback_added_cdns": [],
   "label": "hls360p"
  },
  {
   "id": "3-2273561a201ec18",
   "playlist_type": "defaultS3",
   "type": "playlist",
   "filename": "playlist.m3u8",
   "dvr_filename": "playlist_dvr.m3u8",
   "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/playlist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/playlist_dvr.m3u8",
   "ssai_playback_urls": {
    "b907ac7935e2": {
     "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/b907ac7935e2/playlist_ssaiM.m3u8",
     "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/b907ac7935e2/playlist_dvr_ssaiM.m3u8",
     "playback_added_cdns": [],
     "description": "Test ad configuration for SLS",
     "type": "ads"
    },
    "dc9aa8ee3520f2": {
     "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/dc9aa8ee3520f2/playlist_ssaiM.m3u8",
     "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/dc9aa8ee3520f2/playlist_dvr_ssaiM.m3u8",
     "playback_added_cdns": [],
     "description": "Test live ad config for SLS",
     "type": "ads"
    }
   },
   "playback_added_cdns": []
  }
 ],
 "stream_url": "rtmp://ec2-54-184-149-60.us-west-2.compute.amazonaws.com:1935/2273561a201ec18",
 "stream_name": "alive",
 "static": false,
 "job_videocloud_asset_id": "6227380655001",
 "encryption": {},
 "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/playlist.m3u8",
 "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/playlist_dvr.m3u8",
 "ssai_playback_urls": {
  "b907ac7935e2": {
   "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/b907ac7935e2/playlist_ssaiM.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/b907ac7935e2/playlist_dvr_ssaiM.m3u8",
   "playback_added_cdns": [],
   "description": "Test ad configuration for SLS",
   "type": "ads"
  },
  "dc9aa8ee3520f2": {
   "playback_url": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/dc9aa8ee3520f2/playlist_ssaiM.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/2273561a201ec18/us-west-2/NA/dc9aa8ee3520f2/playlist_dvr_ssaiM.m3u8",
   "playback_added_cdns": [],
   "description": "Test live ad config for SLS",
   "type": "ads"
  }
 },
 "playback_added_cdns": []
}

示例響應(遠程視頻)
{
 "id": "bbccddeeffgghhiijjkk0011223344",
 "outputs": [
  {
   "id": "0-bbccddeeffgghhiijjkk0011223344",
   "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_0/chunklist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_0/chunklist_dvr.m3u8",
   "playback_url_vod": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_0/chunklist_vod.m3u8",
   "playback_added_cdns": [],
   "label": "hls720p"
  },
  {
   "id": "1-bbccddeeffgghhiijjkk0011223344",
   "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_1/chunklist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_1/chunklist_dvr.m3u8",
   "playback_url_vod": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_1/chunklist_vod.m3u8",
   "playback_added_cdns": [],
   "label": "hls540p"
  },
  {
   "id": "2-bbccddeeffgghhiijjkk0011223344",
   "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_2/chunklist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_2/chunklist_dvr.m3u8",
   "playback_url_vod": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/profile_2/chunklist_vod.m3u8",
   "playback_added_cdns": [],
   "label": "hls360p"
  },
  {
   "id": "3-bbccddeeffgghhiijjkk0011223344",
   "playlist_type": "defaultS3",
   "type": "playlist",
   "filename": "playlist.m3u8",
   "dvr_filename": "playlist_dvr.m3u8",
   "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/playlist.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/playlist_dvr.m3u8",
   "ssai_playback_urls": {
    "91bc2d5ff4a4441db34c2457c751c3ca": {
     "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/91bc2d5ff4a4441db34c2457c751c3ca/playlist_ssaiM.m3u8",
     "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/91bc2d5ff4a4441db34c2457c751c3ca/playlist_dvr_ssaiM.m3u8",
     "playback_added_cdns": [],
     "description": "Test ad configuration",
     "type": "ads"
    },
    "e7f6e9a3022a45e1b0b322ba57399150": {
     "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/e7f6e9a3022a45e1b0b322ba57399150/playlist_ssaiM.m3u8",
     "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/e7f6e9a3022a45e1b0b322ba57399150/playlist_dvr_ssaiM.m3u8",
     "playback_added_cdns": [],
     "description": "House Ads - 0077db20eb444b5daa7487438c90a271",
     "type": "ads"
    }
   }
  }
 ],
 "stream_url": "rtmp://ep4-usw2.bcovlive.io:1935/bbccddeeffgghhiijjkk0011223344",
 "stream_name": "alive",
 "static": false,
 "encryption": {},
 "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/playlist.m3u8",
 "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/playlist_dvr.m3u8",
 "ssai_playback_urls": {
  "91bc2d5ff4a4441db34c2457c751c3ca": {
   "playback_url": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/91bc2d5ff4a4441db34c2457c751c3ca/playlist_ssaiM.m3u8",
   "playback_url_dvr": "https://bcovlive-a.akamaihd.net/bbccddeeffgghhiijjkk0011223344/us-west-2/NA/91bc2d5ff4a4441db34c2457c751c3ca/playlist_dvr_ssaiM.m3u8",
   "playback_added_cdns": [],
   "description": "Test ad configuration",
   "type": "ads"
  }
 }
}

從 API 響應中,記下下一步的以下字段值:

  • id - 您的實時工作編號
  • stream_url, stream_name - 直播編碼器的輸入
  • job_videocloud_asset_id - 視頻雲視頻ID

創建播放令牌

您將需要播放器的播放令牌。

要創建播放令牌,請發送POST要求如下:

方法 POST
URL https://api.bcovlive.io/v1/jobs/your live job id/playback-token
標頭 X-API-KEY: your API KEY
內容類型:應用程序/JSON

要求主體

請求主體範例:

{
   "dvr":true / false,
   "application_id":"your ad config id"
}

響應

範例回應:

{
 "playback_token": "live.JhQabcdefghijkl000000000abcdefghi"
}

響應主體將包含生成的播放令牌。在與您的播放器進行播放 API 調用時使用它。

設定播放程式

從Playback API播放實時流的過程與播放普通Video Cloud視頻的方式略有不同。除了提供視頻ID(參考ID)之外,您還需要添加一個播放令牌,以標識您要使用的廣告配置。您還需要指定是否要播放DVR。

網路播放器

有關配置Brightcove Player的詳細信息,請參見在Brightcove Player中將Player增強功能用於Live SSAI文件。

原生安卓播放器

有關為Android配置本機播放器的詳細信息,請參見將播放器增強功能與本機SDK一起用於Live SSAI文件。

原生 iOS 播放器

有關為iOS配置Native Player的詳細信息,請參閱將播放器增強功能與本機SDK一起用於Live SSAI文件。

開始流式傳輸

有許多工具可以創建直播事件。以下是一些編碼器,可用於生成CDN交付的實時流:

清理

實時流完成後,可以按以下步驟清理流的工件:

  1. 停止流式編碼器
  2. 取消現場作業。

    要取消現場工作,請發送PUT要求如下:

    方法 PUT
    URL https://api.bcovlive.io/v1/jobs/your live job id/cancel
    標頭 X-API-KEY: your API KEY
    內容類型:應用程序/JSON

    有關詳細信息,請參見實時API參考文件。

  3. 刪除廣告配置

    若要刪除廣告設定,請依照下列方式傳送DELETE請求:

    方法 PUT
    URL https://api.bcovlive.io/v1/ssai/applications/application/your ad config id
    標頭 X-API-KEY: your API KEY
    內容類型:應用程序/JSON

    有關詳細信息,請參見實時API參考文件。