您可以同时将备用直播视频数据投射到一个视频直播中。如果您的主要投射视频出现故障,我们将自动切换至您的备用投射视频,以便您的直播视频可以不间断地继续播放。除非您手动切换回主要投射视频,或者您的主要投射视频已恢复而您的备用投射视频出现故障,否则我们将继续为您的直播使用备用投射视频。
为了能在视频直播时使用备用投射视频,您必须在创建直播的 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 的 /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" }