示例#1
0
        public static float FindNextKeyFrameTimeSeconds(float seconds, float frameRate, int keyFrameInterval)
        {
            int currentFrame = Helper.ConvertTimeSecondsToFrame(seconds, frameRate);
            // TODO: allow specifying a minimum number of frames so that if currentFrame is too close to nextKeyFrame, it will calculate the next-next keyframe
            int nextKeyFrame = keyFrameInterval * Mathf.CeilToInt((float)(currentFrame + 1) / (float)keyFrameInterval);

            return(Helper.ConvertFrameToTimeSeconds(nextKeyFrame, frameRate));
        }
        /// <inheritdoc/>
        public void SeekToFrame(int frame, float overrideFrameRate = 0f)
        {
            float frameRate = (overrideFrameRate > 0f)?overrideFrameRate:GetVideoFrameRate();

            if (frameRate > 0f)
            {
                frame = Mathf.Clamp(frame, 0, GetMaxFrameNumber(frameRate));
                double time = Helper.ConvertFrameToTimeSeconds(frame, frameRate);
                Seek(time);
            }
        }
        /// <inheritdoc/>
        public void SeekToFrameRelative(int frameOffset, float overrideFrameRate = 0f)
        {
            float frameRate = (overrideFrameRate > 0f)?overrideFrameRate:GetVideoFrameRate();

            if (frameRate > 0f)
            {
                int frame = Helper.ConvertTimeSecondsToFrame(GetCurrentTime(), frameRate);
                frame += frameOffset;
                frame  = Mathf.Clamp(frame, 0, GetMaxFrameNumber(frameRate));
                double time = Helper.ConvertFrameToTimeSeconds(frame, frameRate);
                Seek(time);
            }
        }