การบันทึกและเล่น API ช่วยให้คุณสามารถบันทึกวิดีโอและข้อมูล AR เพียงครั้งเดียวภายในสภาพแวดล้อมที่กำหนด และใช้เนื้อหานั้นแทนที่เซสชันกล้องแบบสด
ข้อกำหนดเบื้องต้น
ตรวจสอบว่าคุณเข้าใจแนวคิด AR พื้นฐาน และวิธีกำหนดค่าเซสชัน ARCore ก่อนดำเนินการต่อ
ความเข้ากันได้กับ ARCore API อื่นๆ
ARCore API อาจให้ผลการค้นหาระหว่างการเล่นต่างจากที่สังเกตการณ์ระหว่างการบันทึกเนื่องจากวิธีการประมวลผลข้อมูลเซสชัน และอาจให้ผลลัพธ์ที่แตกต่างกันในระหว่างเซสชันการเล่นครั้งต่อๆ ไป ตัวอย่างเช่น จำนวนสิ่งที่ติดตามได้ที่ตรวจพบ เวลาที่แม่นยำในการตรวจจับ และท่าทางในช่วงเวลาต่างๆ อาจแตกต่างกันระหว่างการเล่น
ความเข้ากันได้กับ Cloud Anchor
คุณสามารถโฮสต์และแก้ไข Cloud Anchor ขณะบันทึกหรือเล่นเซสชันได้
กำลังบันทึก
เริ่ม หยุด และตรวจสอบสถานะของการบันทึกเซสชัน ARCore
บันทึกเซสชัน ARCore
หากต้องการบันทึกเซสชัน ARCore ให้กําหนดค่าเซสชันและระบุ URI ของ MP4 สําหรับการบันทึก โทรหา ArSession_startRecording()
ก่อนการโทรถึง ArSession_resume()
ครั้งแรก การบันทึกจะเริ่มต้นโดยอัตโนมัติเมื่อเซสชันกลับมาทำงานอีกครั้ง หากต้องการหยุดบันทึกโดยอัตโนมัติเมื่อเซสชันหยุดชั่วคราว โปรดโทรหา ArRecordingConfig_setAutoStopOnPause()
หากต้องการบันทึกเซสชันบางส่วน ให้โทรหา ArSession_startRecording()
ขณะที่เซสชันดำเนินอยู่
ArRecordingConfig* recording_config = nullptr; ArRecordingConfig_create(ar_session, &recording_config); ArRecordingConfig_setMp4DatasetUri(ar_session, recording_config, mp4_dataset_uri); ArRecordingConfig_setAutoStopOnPause(ar_session, recording_config, true); CHECK(ArSession_startRecording(ar_session, recording_config)); // … // Resume ARCore session to start recording. CHECK(ArSession_resume(ar_session)); // … // Recording ends. CHECK(ArSession_pause(ar_session));
หยุดบันทึก
หากต้องการหยุดบันทึกโดยไม่หยุดเซสชัน AR ที่ทำงานอยู่ในปัจจุบันชั่วคราว ให้โทรหา ArSession_stopRecording()
และ ArRecordingConfig_destroy()
ArStatus status = ArSession_stopRecording(ar_session); ArRecordingConfig_destroy(recording_config);
ตรวจสอบสถานะการบันทึก
ArSession_getRecordingStatus()
สามารถใช้เพื่อระบุ ArRecordingStatus
ปัจจุบันได้ทุกเมื่อ
ArRecordingStatus recording_status; // Can be called at any time. ArSession_getRecordingStatus(ar_session, &recording_status); if (recording_status == AR_RECORDING_NONE) { // The dataset recorder is not recording. } else if (recording_status == AR_RECORDING_OK) { // The dataset recorder is recording normally. } else if (recording_status == AR_RECORDING_IO_ERROR) { // The dataset recorder encountered an error while recording. }
การเล่น
เล่นเซสชัน AR ที่บันทึกไว้ก่อนหน้านี้ เซสชันจะเล่นแบบเรียลไทม์และจะไม่สามารถปรับการเล่นหรือความเร็วของเซสชันได้
เล่นเซสชันที่บันทึกไว้ก่อนหน้านี้
หากต้องการเล่นเซสชันที่บันทึกไว้ก่อนหน้านี้ โปรดโทรหา ArSession_setPlaybackDatasetUri()
ก่อนการโทรถึง ArSession_resume()
ครั้งแรก
เมื่อเริ่มเล่นเนื่องจากการเรียก ArSession_resume()
ครั้งแรก การหยุดเซสชันชั่วคราวด้วยการเรียกใช้ ArSession_pause()
จะระงับการประมวลผลเฟรมรูปภาพทั้งหมดของกล้องและข้อมูลเซ็นเซอร์อื่นๆ ที่บันทึกไว้ในชุดข้อมูล ระบบจะไม่ประมวลผลเฟรมรูปภาพและเฟรมเซ็นเซอร์ของกล้องซ้ำ เมื่อเซสชันกลับมาทำงานอีกครั้งโดยการเรียกใช้ ArSession_resume()
โดยทั่วไปการติดตาม AR สําหรับเซสชันจะเกิดปัญหาเนื่องจากช่องว่างในข้อมูลที่ประมวลผล
// Specify previously recorded MP4 file. CHECK(ArSession_setPlaybackDatasetUri(ar_session, mp4_dataset_uri)); // … // Playback starts from the beginning of the dataset. CHECK(ArSession_resume(ar_session)); // … // Pause AR session, but allow playback to silently continue. CHECK(ArSession_pause(ar_session)); // … // Resume AR session. Playback continues with gap to paused session. CHECK(ArSession_resume(ar_session));
เริ่มเล่นใหม่ตั้งแต่ต้น
หากต้องการรีสตาร์ทการเล่นจากจุดเริ่มต้นของชุดข้อมูล ให้หยุดเซสชันชั่วคราวแล้วเรียกใช้ ArSession_setPlaybackDatasetUri()
โดยระบุการบันทึก MP4 เดียวกันก่อนเล่นเซสชันต่อ
CHECK(ArSession_pause(ar_session)); // Pause and specify the *same* dataset: CHECK(ArSession_setPlaybackDatasetUri(ar_session, mp4_dataset_uri)); // Playback starts from the *beginning* of the dataset. CHECK(ArSession_resume(ar_session));
เล่นเซสชันอื่น
หากต้องการเล่นชุดข้อมูลอื่น ให้หยุดเซสชันชั่วคราวและระบุชุดข้อมูลใหม่ก่อนกลับมาใช้งานเซสชันอีกครั้ง
CHECK(ArSession_pause(ar_session)); // Pause and specify a *different* dataset: CHECK(ArSession_setPlaybackDatasetUri(ar_session, other_mp4_dataset_uri)); // Playback starts from the *beginning* of the new dataset. CHECK(ArSession_resume(ar_session));
ตรวจสอบสถานะการเล่น
ใช้ ArSession_getPlaybackStatus()
ได้ทุกเมื่อเพื่อระบุ ArPlaybackStatus
ปัจจุบัน
ArPlaybackStatus playback_status; // Can be called at any time. ArSession_getPlaybackStatus(ar_session, &playback_status); if (playback_status == AR_PLAYBACK_NONE) { // The session is not playing back an MP4 dataset file. } else if (playback_status == AR_PLAYBACK_OK) { // Playback is in process without issues. } else if (playback_status == AR_PLAYBACK_IO_ERROR) { // Playback has stopped due to an error. } else if (playback_status == AR_PLAYBACK_FINISHED) { // Playback has finished successfully. }
สิ่งที่จะเกิดขึ้นหลังจากนี้
- ดูวิธีเพิ่มข้อมูลที่กำหนดเองในเซสชันที่บันทึกไว้