我正在尝试在 C++/CX UWP 项目中以定义的时间间隔从现有视频中截取屏幕截图。我的想法是使用MediaComposition 库中的函数“GetThumbnailsAsync” :
create_task(MediaClip::CreateFromFileAsync(this->last_video)).then([this](MediaClip^ clip )
{
// Create a MediaComposition containing the clip and set it on the MediaElement.
MediaComposition^ composition = ref new MediaComposition();
composition->Clips->Append(clip);
TimeSpan ts;
ts.Duration = 1000;
IVector<TimeSpan>^ i_ts_vector;
//TODO
create_task(composition->GetThumbnailsAsync(is_ts_vector, 0, 0, VideoFramePrecision::NearestFrame)).then([this, clip, composition](IVectorView<ImageStream^>^ imageStream)
{
//TODO
});
});
last_video 是带有视频路径的 StorageFile。
这不起作用,因为 i_ts_vector 未初始化且仍为 NULL。我已经尝试过这样的事情:
IVector<TimeSpan>^ i_ts_vector = ref new Vector<TimeSpan>();
这适用于 int 向量,但不适用于 TimeSpan 向量。它给出了一个编译器错误:
错误 C2678 二进制“==”:未找到采用“const Windows::Foundation::TimeSpan”类型的左侧操作数的运算符(或没有可接受的转换)
如何使用 TimeSpan-Elements 初始化和填充 IVector?或者有更好的截屏方式吗?
科罗诺
这里的问题是(引用Vector 中的值类型)
要存储在Platform::Collections::Vector中的任何元素都必须支持相等比较,无论是隐式还是使用您提供的自定义std::equal_to比较器。所有引用类型和所有标量类型都隐式支持相等比较。对于Windows::Foundation::DateTime等非标量值类型,或自定义比较——例如,
objA->UniqueID == objB->UniqueID—you
必须提供自定义函数对象。
TimeSpan Struct也是没有相等运算 ( operator==
)的非标量值类型之一。所以你得到了Error C2678
。为了解决这个问题,你可以提供一个像下面这样的自定义函子:
struct MyEqual : public std::binary_function<const TimeSpan, const TimeSpan, bool>
{
bool operator()(const TimeSpan& _Left, const TimeSpan& _Right) const
{
return _Left.Duration == _Right.Duration;
}
};
然后在Platform::Collections::Vector 中使用它,例如:
IVector<TimeSpan>^ i_ts_vector = ref new Platform::Collections::Vector<TimeSpan, MyEqual>();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句