如何在UWP C+中从流记录中提取帧+;项目

如何在UWP C+中从流记录中提取帧+;项目,uwp,video-capture,c++-cx,Uwp,Video Capture,C++ Cx,在一个UWP C++/CX项目中,我试图从MediaCapture相机流的每一帧中截取屏幕快照,并在最后将该流保存为视频。我的做法: /// <summary> /// Records an MP4 video to a StorageFile and adds rotation metadata to it /// </summary> /// <returns></returns> task<void> CameraControl:

在一个UWP C++/CX项目中,我试图从MediaCapture相机流的每一帧中截取屏幕快照,并在最后将该流保存为视频。我的做法:

/// <summary>
/// Records an MP4 video to a StorageFile and adds rotation metadata to it
/// </summary>
/// <returns></returns>
task<void> CameraControl::StartRecordingAsyncStream()
{
//InMemoryRandomAccessStream^ video_stream;
// Calculate rotation angle, taking mirroring into account if necessary
auto rotationAngle = CameraRotationHelper::ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper->GetCameraCaptureOrientation());
auto encodingProfile = MediaProperties::MediaEncodingProfile::CreateMp4(MediaProperties::VideoEncodingQuality::Auto);

encodingProfile->Video->Properties->Insert(RotationKey, rotationAngle);


return create_task(_mediaCapture->StartRecordToStreamAsync(encodingProfile, this->video_stream))
    .then([this]()
{
    _isRecording = true;
    WriteLine("Started recording");


}).then([this](task<void> previousTask)
{
    try
    {
        previousTask.get();
    }
    catch (Exception^ ex)
    {
        // File I/O errors are reported as exceptions
        WriteLine(ex->Message);
    }
});
}

/// <summary>
/// Stops recording a video
/// </summary>
/// <returns></returns>
task<void> CameraControl::StopRecordingAsyncStream()
{
_isRecording = false;

WriteLine("Stopping recording...");
return create_task(_mediaCapture->StopRecordAsync())
    .then([this]()
{
    WriteLine("Stopped recording!");

    });
}


//Loads all frames as images from the stream
void CameraControl::LoadVideoStream(void) {

//TODO: Read all Frames as Thumbnails from "this->video_stream" and store them as Bitmaps, for example in a vector

}

/// <summary>
/// Stores the recorded stream as a MP4 video
/// </summary>
/// <returns></returns>
task<void> CameraControl::StoreRecordingAsync()
{

// Create storage file for the capture
return create_task(_captureFolder->CreateFileAsync("SimpleVideo.mp4", CreationCollisionOption::GenerateUniqueName))
    .then([this](StorageFile^ file)
{

//TODO: Write the "this->video_stream" as a MP4 video to the file

});
}
//
///将MP4视频录制到StorageFile并向其中添加旋转元数据
/// 
/// 
任务CameraControl::StartRecordingAsyncStream()
{
//内存随机存取流^视频流;
//计算旋转角度,必要时考虑镜像
auto rotationAngle=CameraRotationHelper::ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper->GetCameraCaptureOrientation());
自动编码配置文件=MediaProperties::MediaEncodingProfile::CreateMp4(MediaProperties::VideoEncodingQuality::auto);
编码配置文件->视频->属性->插入(旋转键、旋转角);
返回创建任务(\u mediaCapture->StartRecordToStreamAsync(编码配置文件,此->视频流))
.然后([这个]()
{
_isRecording=true;
WriteLine(“开始录制”);
}).然后([此](任务上一个任务)
{
尝试
{
previousTask.get();
}
捕获(异常^ex)
{
//文件I/O错误报告为异常
写线(ex->Message);
}
});
}
/// 
///停止录制视频
/// 
/// 
任务CameraControl::StopRecordingAsyncStream()
{
_isRecording=false;
WriteLine(“停止录制…”);
返回创建任务(\u mediaCapture->StopRecordAsync())
.然后([这个]()
{
WriteLine(“停止录制!”);
});
}
//将所有帧作为图像从流中加载
void CameraControl::LoadVideoStream(void){
//TODO:从“this->video\u stream”中将所有帧作为缩略图读取,并将其存储为位图,例如在向量中
}
/// 
///将录制的流存储为MP4视频
/// 
/// 
任务CameraControl::StoreRecordingAsync()
{
//为捕获创建存储文件
返回create_任务(_captureFolder->CreateFileAsync(“SimpleVideo.mp4”,CreationCollisionOption::GenerateUniqueName))
。然后([this](存储文件^file)
{
//TODO:将“this->video\u stream”作为MP4视频写入文件
});
}
对于第一个问题,我需要一个类似MP4Decoder的东西来转换流(类似于CapturePhotoToStreamAsync的位图解码器)

关于第二个问题:我知道有一个函数“StartRecordToStorageFileAsync”。但这不是一个解决方案,因为保存视频在最后是可选的。我不想保存所有视频

谢谢

科罗诺

编辑:

我尝试实现一个具有FrameArrized事件的媒体帧读取器

public : IAsyncOperation<MediaFrameReader> CreateFrameReaderAsync(MediaFrameSource inputSource)
public:IAsyncOperation CreateFrameReaderAsync(MediaFrameSource输入源)

在PC上运行良好,但在Win10移动设备上找不到MediaFrameSource。不知道为什么。

使用
MediaFrameReader
可以从
MediaCapture
作为
软件位图
访问单个帧。我已经做了这个处理C帧中的单独帧,但是它同样应该在C++中工作。我的代码基于以下示例:

为什么要从MediaCapture摄像头流的每一帧截图?看起来我们可以直接保存视频。因为我不想要视频,我需要一个图像流来一步一步地分析运动。在分析之后,存储视频应该是一个选项。