您可以同時將備份直播視訊資料串流為直播視訊播放。如果您的主要串流失效,我們將自動切換到您的備份串流,讓您的直播視訊播放可以繼續不中斷。除非您手動切換回主要串流,或主要串流已恢復且備份串流失效,否則您的播放將繼續使用備份串流。
為了讓備份串流搭配直播視訊播放使用,您必須在建立播放的 LiveVideo 物件時啟用備份串流,或在備份串流接收串流資料之前,在 LiveVideo 物件上將其啟用。
若要在建立播放的 LiveVideo 物件時啟用備份串流,請在查詢中加入 enable_backup_ingest=true
查詢字串參數。
例如,若要在使用者上建立啟用備份串流的 LiveVideo:
POST /{user-id}/live_videos ?status=LIVE_NOW &enable_backup_ingest=true &access_token={access-token}
這將傳回兩個網址,一個用於主要串流,另一個用於備份(次要):
{ "id": "{live-video-id}", "stream_url": "{stream-url}", "secure_stream_url": "{secure-stream-url}", "stream_secondary_urls": [ "{stream-secondary-urls}" ], "secure_stream_secondary_urls": [ "{secure-stream-secondary-urls}" ] }
將 secure_stream_url
用於主要內嵌串流,將 secure_stream_secondary_urls
用於備份內嵌串流。在播放期間,您可以隨時將備份資料串流到 LiveVideo 物件。
curl -i -X POST \ "https://graph.facebook.com/362629830945302/live_videos ?enable_backup_ingest=true &access_token=EAAI4b..."
{ "id": "10215840463339953", "stream_url": "rtmps://rtmp.facebook.com/rtmp/10215840463339953?s_bl=1&s_l=1&s_sml=3&s_sw=0&s_vt=api&a=AbxMhT-cq73GTdpuPLo", "secure_stream_url": "rtmps://rtmp.facebook.com/rtmp/10215840463339953?s_bl=1&s_l=1&s_sml=3&s_sw=0&s_vt=api&a=AbxMhT-cq73GTdpuPLo", "stream_secondary_urls": [ "rtmp://rtmps.facebook.com/rtmp/10215840463339953?s_bl=1&s_l=1&s_sml=3&s_sw=1&s_vt=api&a=AbzhD2fKJw1Uw7JQjFc" ], "secure_stream_secondary_urls": [ "rtmps://rtmps.facebook.com/rtmp/10215840463339953?s_bl=1&s_l=1&s_sml=3&s_sw=1&s_vt=api&a=AbzhD2fKJw1Uw7JQF80" ] }
只要現有 LiveVideo 物件尚未收到任何直播視訊串流資料,您就可以透過向 LiveVideo 的 /input_streams
關係連線傳送 POST
要求,在現有 LiveVideo 物件上啟用備份串流。例如:
POST /{live-video-id}/input_streams &access_token={access-token}
如此將傳回 LiveVideo 的編號:
{ "id": "{live-video-id}" }
啟用之後,您就可以從 LiveVideo 物件 [取得主要串流和備份串流網址]。
curl -i -X POST \ "https://graph.facebook.com/10215840463339953/input_streams &access_token=EAAI4b..."
{ "id": "10215840463339953" }
您可以透過傳送要求到以下內容,在 LiveVideo 的主要和備份串流之間進行手動切換:
POST /{live-video-id} ?master_ingest_stream_id={master-ingest-stream-id} &access_token={access-token}
{master-ingest-stream-id}
值為布林值,0
代表主要內嵌串流,1
代表備份內嵌串流。
curl -i -X POST \ "https://graph.facebook.com/10215840463339953 ?master_ingest_stream_id=1 &access_token=EAAI4b..."
您可以讀取 LiveVideo 的ingest_streams
欄位,取得主要和備份串流網址:
GET /{live-video-id} ?fields=ingest_streams &acess_token={access-token}
這將傳回 LiveVideo 上主要和備份串流(如果有的話)的內嵌串流健康狀態和串流網址:
{ "ingest_streams": [ { "stream_id": "{stream-id}", "stream_url": "{stream-url}", "secure_stream_url": "{secure-stream-url}", "is_master": {is-master}, "stream_health": {stream-health}, "id": "{id}" }, { "stream_id": "{stream-id}", "stream_url": "{stream-url}", "secure_stream_url": "{secure-stream-url}", "is_master": {is-master}, "stream_health": {stream-health}, "id": "{id}" } ], "id":"10215840874550233" }
curl -i -X GET \ "https://graph.facebook.com/10215840463339953 ?fields=ingest_streams &access_token=EAAI4b..."
{ "ingest_streams": [ { "stream_id": "0", "stream_url": "rtmps://live-api.facebook.com/rtmp/10215840874550233?s_bl=1&s_l=1&s_sml=3&s_sw=0&s_vt=api&a=AbyvsHKGRrur_sZOeuo", "secure_stream_url": "rtmps://live-api.facebook.com/rtmp/10215840874550233?s_bl=1&s_l=1&s_sml=3&s_sw=0&s_vt=api&a=AbyvsHKGRrur_sZOF08", "is_master": true, "stream_health": { "video_bitrate": 2304481.75, "video_framerate": 27.586206436157, "video_gop_size": 2000, "video_height": 700, "video_width": 1120, "audio_bitrate": 118149.8828125 }, "id":"10215840874630235" }, { "stream_id": "1", "stream_url": "rtmps://live-api.facebook.com/rtmp/10215840874550233?s_bl=1&s_l=1&s_sml=3&s_sw=1&s_vt=api_dev&a=AbySai39Wr08FKpUYw0", "secure_stream_url": "rtmps://live-api.facebook.com/rtmp/10215840874550233?s_bl=1&s_l=1&s_sml=3&s_sw=1&s_vt=api_dev&a=AbySai39Wr08FKpUv3M", "is_master": false, "stream_health": { "video_bitrate": 1866942.625, "video_framerate": 22.338048934937, "video_gop_size": 2000, "video_height": 700, "video_width": 1120, "audio_bitrate": 95675.3515625 }, "id":"10215840874670236" } ], "id":"10215840874550233" }