1

我有一个Keyframes 列表,它们只是具有 TimeSpan 的对象和一个具有自己的 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 开始,即您最初拍摄它的地方。

4

3 回答 3

4

尝试以下方式:

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);
于 2013-04-22T23:00:14.623 回答
1

就地修改这些帧的时间有点奇怪。人们会期望您将它们提取到一个新列表中,而不是修改原始值。尽管如此,这样做的方法是使用第一个字段作为“基础”,然后从所有其他字段中减去该值。因此,如果您的时间是[..., 27, 28, 32, 33, 35, 37, 39, ...]并且您想将值从 27 更改为 39,它们将变为[0, 1, 5, 6, 8, 10, 12]

List<Keyframe> region = new List<Keyframe>();

long highestTicks = 0;
long durationTicks = 0; //Stores the whole duration of this new region

long baseTicks = clip.Keyframes[beginFrame].Time.Ticks;

//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];
    k.Time = TimeSpan.FromTicks(k.Time.Ticks - baseTicks);
    highestTicks = Math.Max(highestTicks, k.Time.Ticks);

     region.Add(k);
}

durationTicks = highestTicks;

虽然我真的不明白你为什么担心蜱虫。您可以TimeSpan直接对值进行数学计算。

于 2013-04-22T23:15:15.260 回答
0

看起来“i”值从 300 运行到 799。您需要 <= 运算符吗?

于 2013-04-22T22:34:56.507 回答