c++ - 如何同时使用两个CameraCaptureUI(UWP/C++)

标签 c++ concurrency uwp video-capture uwp-xaml

我正在开发一个通用 Windows 平台应用程序 (UWP),我在其中使用 C++ 作为主要语言。我想同时从两个相机读取。一个摄像头属于 Kinect RGB 摄像头,另一个摄像头属于 Kinect 深度摄像头。到目前为止,我已经设法使用这段代码读取了一个:

void SDKTemplate::Scenario4_ReproVideo::Grabar_Click(Platform::Object^ 
sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
CameraCaptureUI^ dialog = ref new CameraCaptureUI();
dialog->VideoSettings->Format = CameraCaptureUIVideoFormat::Mp4;

Windows::Foundation::Collections::IPropertySet^ appSettings = ApplicationData::Current->LocalSettings->Values;

concurrency::task<StorageFile^>(dialog->CaptureFileAsync(CameraCaptureUIMode::Video)).then([this](StorageFile^ file) {
    if (file != nullptr) {

        concurrency::task<Streams::IRandomAccessStream^> (file->OpenAsync(FileAccessMode::Read)).then([this] (Streams::IRandomAccessStream^ stream){
            CapturedVideo->SetSource(stream, "video/mp4");
            logger->Text = "recording";
        });
        Windows::Foundation::Collections::IPropertySet^ appSettings = ApplicationData::Current->LocalSettings->Values;

        appSettings->Insert("CapturedVideo", PropertyValue::CreateString(file->Path));
    }
    else {
        logger->Text = "Something went wrong or was cancelled";
    }

});
}

通过这样做,我可以从其中一台摄像机可靠地进行录制。我的问题是我需要同时从两个摄像头进行录制,因为我需要深度和 RGB 来处理视频。

我是并发新手,有没有办法(越简单越好)同时实现两路录音?

最佳答案

在 UWP 应用中,我们可以使用 MediaCapture 捕获照片和视频提供从捕获设备捕获照片、音频和视频的功能的类。见题目Basic photo, video, and audio capture with MediaCapture .

我们可以初始化多个MediaCapture实例然后使用 MediaFrameReader 读取帧类(class)。看题目Discover and select camera capabilities with camera profilesProcess media frames with MediaFrameReader并查看官方样本 CameraFrames .

另外,UWP多机位采集也有类似的帖子,大家也可以引用一下:

Handle multiple camera capture UWP

关于c++ - 如何同时使用两个CameraCaptureUI(UWP/C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50739627/

相关文章:

uwp - 在 UWP 中鼠标悬停时如何更改按钮的背景?

C++ 外部类声明

c++ - 在 GCC 中,如何(暂时)抑制来自 "#pragma message"的消息

java - scheduleWithFixedDelay 抛出异常如何重启schedule?

multithreading - Clojure 多线程输出流

c# - 在 ScrollViewer (UWP) 中移动图像

c++ - 访问冲突 C++(删除 vector 中的项目)

C++如何使用坐标 vector 查找正方形或矩形的面积

c# - 当我们需要重入支持时,异步函数的互斥体替代方案

xaml - UWP ToggleSwitch 将内容放在左侧