您可以同時將備用直播視像數據串流至直播視像廣播。如果您的主要串流影片出現故障,我們將自動切換至您的備用串流影片,以確保您的直播視像廣播不受干擾。您的直播將繼續使用備用串流影片,除非您手動切換回主要串流影片,或者您的主要串流影片已恢復正常而您的備用串流影片出現故障。
為了能在直播視像廣播時使用備用串流影片,您必須在建立直播的 LiveVideo 物件時啟用備用串流,或者在 LiveVideo 物件接收串流數據之前為其啟用此選項。
如要在建立直播的 LiveVideo 物件時啟用備用串流,請在您的查詢中包括 enable_backup_ingest=true
查詢字串參數。
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 的 /input_streams
邊緣傳送 POST
要求,以便在現有 LiveVideo 物件啟用備用串流,前提是此物件尚未接收任何直播視像串流數據。例如:
POST /{live-video-id}/input_streams &access_token={access-token}
此要求將傳回 LiveVideo 的 ID:
{ "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" }