Carlos Hernandez Perez
Carlos Hernandez Perez

Reputation: 331

How to use two CameraCaptureUI at the same time (UWP / C++)

I am working on a Universal Windows Platform Application (UWP) in which I am using C++ as the main language. I want to read from two cameras at the same time. One camera belongs to the Kinect RGB camera and the other to the Kinect Depth camera. So far I've managed to read from just one using this piece of code:

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

});
}

By doing this I can reliably record from one of the cameras. My problem is that I need to record from both cameras at the same time as I need the Depth and RGB to process the video.

I am new to concurrency, is there a way (the simpler the better) to achieve two recordings simultaneously?

Upvotes: 0

Views: 411

Answers (1)

Breeze Liu - MSFT
Breeze Liu - MSFT

Reputation: 3808

In UWP app, we can capture photos and video using the MediaCapture class which provides functionality for capturing photos, audio, and videos from a capture device. See the topic Basic photo, video, and audio capture with MediaCapture.

We can initialize multiple MediaCapture instances then read frame by using MediaFrameReader Class. see the topic Discover and select camera capabilities with camera profiles and Process media frames with MediaFrameReader and also look into the official sample CameraFrames.

Besides, there is a similar thread about UWP multiple camera capture, you can also refer it:

Handle multiple camera capture UWP

Upvotes: 1

Related Questions