Unity 6.3
0 онлайн 55 гостей 3 в системе
Вход

VideoClip.frameRate

Declaration

public double frameRate;

Описание

Частота кадров клипа в кадрах в секунду. (только для чтения).

Частота кадров — это количество кадров, которые отображаются в секунду видеоклипа. Это полезно, если вы хотите синхронизировать с другими эффектами в вашем проекте и контролировать производительность. Однако VideoPlayer.frameRate обычно дают более точный результат.

Дополнительные ресурсы: VideoPlayer.frameRate, VideoPlayer.frameCount.

// This script uses both the VideoPlayer and VideoClip components' frame count and frame rate
// to calculate the length of the video in seconds. Sometimes this can return different results, 
// but the VideoPlayer is more accurate, especially after a full playthrough.
// The script recalculates the counts on each loop. 

using UnityEngine; using UnityEngine.Video;

public class VideoClipLengthCalculator : MonoBehaviour { VideoPlayer videoPlayer;

void Start() { if (videoPlayer != null) { videoPlayer = GetComponent<VideoPlayer>(); videoPlayer.isLooping = true; VideoClip videoClip = videoPlayer.clip;

if (videoClip != null) { CalculateVideoLength(videoClip); videoPlayer.loopPointReached += OnLoop; videoPlayer.Play(); } else { Debug.LogWarning("VideoClip is not assigned."); } } else { Debug.LogWarning("VideoPlayer is not assigned."); } }

void CalculateVideoLength(VideoClip clip) { // Get frame count and frame rate from the VideoClip. ulong videoClipFrameCount = clip.frameCount; double videoClipFrameRate = clip.frameRate;

// Calculate the length in seconds (VideoClip) and output to console. double videoClipLengthInSeconds = videoClipFrameCount / videoClipFrameRate; Debug.Log($"Calculated VideoClip length: {videoClipLengthInSeconds} seconds.");

// Get frame count and frame rate from the VideoPlayer. ulong videoPlayerFrameCount = videoPlayer.frameCount; double videoPlayerFrameRate = videoPlayer.frameRate;

// Calculate the length in seconds (VideoPlayer) and output to console. double videoPlayerLengthInSeconds = videoPlayerFrameCount / videoPlayerFrameRate; Debug.Log($"Calculated VideoPlayer Length: {videoPlayerLengthInSeconds} seconds.");

}

void OnLoop(VideoPlayer vp) { // Recalculate the video length after loop happens. CalculateVideoLength(vp.clip); } }