Record video with synchronized associated metadata with UWP/c++

128 Views Asked by At

I want to record a video with C++ & UWP API. I use the MediaCapture object to do so.

m_mediaCapture = Platform::Agile<MediaCapture>(ref new MediaCapture());

I managed to record a video with 'StartRecordToStorageFileAsync' function.

m_mediaCapture->StartRecordToStorageFileAsync(...)

In addition to this, I wish to record metadata associated with each frame (such as timestamp, camera parameters, image indexes ...). I managed to access these properties through the object 'MediaFrameReader'. I bind a function 'onFrameArrived' to 'FrameArrived' event.

m_mediaCapture->CreateFrameReaderAsync(...).then([=](MediaFrameReader^ reader)
{
   ...
   m_mediaFrameReader->FrameArrived +=
                                ref new TypedEventHandler<MediaFrameReader^, MediaFrameArrivedEventArgs^>(
                                    std::bind(&VideoRecordController::onFrameArrived, this, _1, _2));
}

where I can access the required metadata.

void VideoRecordController::onFrameArrived(MediaFrameReader^ sender, MediaFrameArrivedEventArgs^ args)
{
    if (MediaFrameReference^ frame = sender->TryAcquireLatestFrame())
    {
        // Access to MediaFrameReference metadata, e.g. :
        auto timestamp = frame->SystemRelativeTime->Value.Duration;
        auto cameraParameters = frame->VideoMediaFrame->CameraIntrinsics;
    }
    // Or misc. data
    static int frameIndex = 0;
    frameIndex++;
    // ... Save metadata
}

However, the metadata are not synchronized with the saved video (different output frequencies). The video is recorded with ~30 FPS, whereas metadata are recorded at ~20 DataPerSecond. It looks like the 'FrameArrived' event is not called at every frame. My question is then : How to record a video with synchronized associated frame metadata ?

Thanks!

0

There are 0 best solutions below