ZD 录屏 SDK 高级示例 – Visual C++ 进阶 Visual C++ 示例代码片段展示如何同时录制多个摄像头和主屏幕 // 将布局上下文切换到主屏幕块并存储前一个块索引 int oldBlock = ScnLib_SetLayoutContext(0); // 设置主屏幕输出单独的视频(可选) ScnLib_SetVideoPathW(L"C:\\Recordings\\Main Screen.mp4"); // 获取主屏幕视频分辨率 int videoWidth = 0, videoHeight = 0; ScnLib_GetVideoResolution(&videoWidth, &videoHeight); // 我们将把 3 个垂直堆叠的摄像头视图与主屏幕的右侧靠齐,每个视图都是视频高度的 1/3 videoHeight /= 3; // 我们偏好长宽比为 4:3 的摄像头视图 videoWidth = videoHeight * 4 / 3; // 将布局上下文切换到摄像头视图块 #1 ScnLib_SetLayoutContext(1); // 设置摄像头 #1 视图输出单独的视频(可选) ScnLib_SetVideoPathW(L"C:\\Recordings\\Webcam #1.mp4"); // 假定有不少于 3 个摄像头设备连接到了电脑,为摄像头 #1 视图选择第一个摄像头设备 ScnLib_SelectWebcamDevice(0); // 将摄像头 #1 视图与右上角对齐,向右偏移其宽度,使其显示在主屏幕侧边 ScnLib_SetWebcamPosition(SCNLIB_POSITION_TOP_RIGHT, -videoWidth, 0); ScnLib_SetWebcamViewSize(videoWidth, videoHeight); // 将布局上下文切换到摄像头视图块 #2 ScnLib_SetLayoutContext(2); // 设置摄像头 #2 视图输出单独的视频(可选) ScnLib_SetVideoPathW(L"C:\\Recordings\\Webcam #2.mp4"); // 假定有不少于 3 个摄像头设备连接到了电脑,为摄像头 #2 视图选择第二个摄像头设备 ScnLib_SelectWebcamDevice(1); // 将摄像头 #2 视图与右侧对齐,同时向右偏移其宽度,使其显示在主屏幕侧边 ScnLib_SetWebcamPosition(SCNLIB_POSITION_RIGHT, -videoWidth, 0); ScnLib_SetWebcamViewSize(videoWidth, videoHeight); // 将布局上下文切换到摄像头视图块#3 ScnLib_SetLayoutContext(3); // 设置摄像头 #3 视图输出单独的视频(可选) ScnLib_SetVideoPathW(L"C:\\Recordings\\Webcam #3.mp4"); // 假定有不少于 3 个摄像头设备连接到了电脑,为摄像头 #3 视图选择第三个摄像头设备 ScnLib_SelectWebcamDevice(2); // 将摄像头 #3 视图与右下角对齐,向右偏移其宽度,使其显示在主屏幕侧边 ScnLib_SetWebcamPosition(SCNLIB_POSITION_BOTTOM_RIGHT, -videoWidth, 0); ScnLib_SetWebcamViewSize(videoWidth, videoHeight); // 将布局上下文切换到合成屏幕 ScnLib_SetLayoutContext(-1); // 设置合成屏幕输出单独的视频 ScnLib_SetVideoPathW(L"C:\\Recordings\\Composition Screen.mp4"); // 恢复到之前的布局上下文 ScnLib_SetLayoutContext(oldBlock); // 现在开始录制会话 ScnLib_StartRecording(); 引用的API接口: ScnLib_SetLayoutContext() ScnLib_SetVideoPathA/W() ScnLib_SetVideoResolution() ScnLib_GetVideoResolution() ScnLib_SelectWebcamDevice() ScnLib_SetWebcamPosition() ScnLib_SetWebcamViewSize() ScnLib_StartRecording() 立即获取 SDK SDK APIs