我有一个Keyframe
列表,它们只是TimeSpans和
具有自己的timeSpan刻度的字段(类型为long),称为tempTicks
。
完整列表来自关键帧1-7000。
而且几乎每个关键帧都具有比以前更大的时间戳。
我想从300-800抓取那些关键帧,我想给他们
从0个滴答声开始的新TimeSpan。
List<Keyframe> region = new List<Keyframe>();
long highestTicks = 0;
long durationTicks = 0; //Stores the whole duration of this new region
//beginFrame and endFrame are 300 and 800
for (int i = beginFrame; i < endFrame; i += 1)
{
//Clip is the full list of keyframes
Keyframe k = clip.Keyframes[i];
if (region.Count < 1)
{
k.Time = TimeSpan.FromTicks(0);
}
else
{
//This is the trouble-part
if (k.Time.Ticks > highestTicks)
{
highestTicks = k.Time.Ticks;
k.Time =
TimeSpan.FromTicks(highestTicks - region[region.Count -1].tempTicks);
}
}
durationTicks += k.Time.Ticks;
region.Add(k);
}
我不能以这种方式正确地获得所有这些信息。
你明白为什么吗?
示例:拍摄电影的最爱场景。您想要以场景从媒体播放器中的0:00开始而不是从原始位置的87:00开始导出的方式。
最佳答案
尝试以下方法:
var tickOffset = clip.Keyframes[beginFrame].Time.Ticks;
// this is your 'region' variable
var adjustedFrames = clip.Keyframes
.Skip(beginFrame)
.Take(endFrame - beginFrame)
.Select(kf => new Keyframe {
Time = TimeSpan.FromTicks(kf.Time.Ticks - tickOffset),
OtherProperty = kf.OtherProperty
})
.ToList();
var durationTicks = adjustedFrames.Max(k => k.Time.Ticks);