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

VideoClip.frameCount

Declaration

public ulong frameCount;

Описание

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

Полезно знать длину видео в кадрах, чтобы обеспечить, что любые эффекты, которые вы играете на видео воспроизведения в пределах временных рамок видео. VideoClip извлекает количество кадров из метаданных файла.

Примечание: длину VideoClip возвращает может быть неточно, как внешний кодер может быть неточным. Используйте VideoPlayer.frameCount, чтобы получить более точное значение. Однако, VideoPlayer.frameCount становится более точным после одного проигрывания, так что не будет полностью точным, пока клип не закончится один раз.

Дополнительные ресурсы: 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); } }