สตรีมสำรอง

คุณสามารถสตรีมข้อมูลวิดีโอถ่ายทอดสดสำรองไปพร้อมกับการแพร่ภาพวิดีโอถ่ายทอดสดได้ หากสตรีมหลักของคุณขัดข้อง เราจะสลับไปยังสตรีมสำรองของคุณโดยอัตโนมัติเพื่อให้การแพร่ภาพวิดีโอถ่ายทอดสดของคุณดำเนินต่อไปอย่างราบรื่น การแพร่ภาพของคุณจะยังคงใช้สตรีมสำรองต่อไปจนกว่าคุณจะสลับกลับไปเป็นสตรีมหลักด้วยตัวเอง หรือเมื่อสตรีมหลักของคุณกลับมาทำงาน และสตรีมสำรองของคุณขัดข้อง

ในการใช้สตรีมสำรองกับการแพร่ภาพวิดีโอถ่ายทอดสด คุณจะต้องเปิดใช้งานการสตรีมสำรองเมื่อคุณสร้างอ็อบเจ็กต์ LiveVideo สำหรับการแพร่ภาพหรือเปิดใช้งานการสตรีมสำรองบนอ็อบเจ็กต์ LiveVideo ก่อนที่อ็อบเจ็กต์จะได้รับข้อมูลการสตรีม

เปิดใช้งานการสตรีมสำรองเมื่อสร้าง LiveVideo

ในการเปิดใช้งานการสตรีมสำรองเมื่อคุณสร้างอ็อบเจ็กต์ LiveVideo สำหรับการแพร่ภาพของคุณ ให้ใส่พารามิเตอร์สตริงการสืบค้น enable_backup_ingest=true ไว้ในการสืบค้นของคุณด้วย

ตัวอย่างเช่น ในการสร้าง LiveVideo โดยมีการเปิดใข้งานการสตรีมสำรองบนผู้ใช้:

POST /{user-id}/live_videos ?status=LIVE_NOW &enable_backup_ingest=true &access_token={access-token}

กระบวนการนี้จะส่งคืน URL สองรายการ โดยหนึ่งรายการสำหรับสตรีมหลัก และอีกหนึ่งรายการสำหรับสตรีมสำรอง (ลำดับรอง):

{ "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

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 ที่มีอยู่ได้ตราบใดที่อ็อบเจ็กต์ดังกล่าวยังไม่ได้รับข้อมูลการสตรีมวิดีโอถ่ายทอดสดใดๆ ด้วยการส่งคำขอ POST ไปยังจุดเชื่อมโยง /input_streams ของ LiveVideo ตัวอย่างเช่น:

POST /{live-video-id}/input_streams &access_token={access-token}

กระบวนการนี้จะส่งคืน ID ของ LiveVideo:

{ "id": "{live-video-id}" }

เมื่อเปิดใช้งานแล้ว คุณสามารถ [รับ URL การสตรีมหลักและสำรอง] จากอ็อบเจ็กต์ LiveVideo ได้

ตัวอย่างคำขอ cURL

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

curl -i -X POST \ "https://graph.facebook.com/10215840463339953 ?master_ingest_stream_id=1 &access_token=EAAI4b..."

รับ URL สตรีมหลักและสำรอง

คุณสามารถอ่านค่าในช่อง ingest_streams ของ LiveVideo ได้เพื่อรับ URL สตรีมหลักและสำรอง:

GET /{live-video-id} ?fields=ingest_streams &acess_token={access-token}

กระบวนการนี้จะส่งคืนสถานะของสตรีมนำเข้าและ URL ของสตรีมสำหรับสตรีมหลักและสำรอง (ถ้ามี) บน 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

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" }