从URL VideoClip访问视频维度? (关闭)

时间:2018-01-12 18:33:57

标签: c# unity3d video

我正在尝试使用Unity VideoPlayer从URL加载和播放视频,并使用此陡峭的内容works

现在我遇到了一些麻烦,因为我无法通过我的代码访问剪辑属性,事实上当我使用URL加载VideoClip时,VideoPlayer中的剪辑属性始终返回null。

我想要这个属性,因为我对视频剪辑的宽度和高度感兴趣所以我可以根据我的画布或面板调整它们的大小,它可能会因视频宽高比而有所不同。

因为我每次要求宽度和高度时都使用RenderToTexture来显示视频,所以它返回RTT的{w,h}而不是视频的{w,h}。

有没有办法解决这个问题?

提前致谢。

我正在使用Unity 2017.3.0f3

public string VideoPath = string.Empty;
public VideoPlayer player;

public delegate IEnumerator OnVideoReady();
public static event OnVideoReady VideoReady;

IEnumerator Start()
{
    player = GetComponent<VideoPlayer>();

    player.playOnAwake = false;
    player.enabled = false;

    yield return null;

    // ABSOLUTE PATH TO THE VIDEO FILE
    var path = UnifiedIO.SystemIO.Internal.Path.GetFullPath(VideoPath);

    if(Debug.isDebugBuild)
    {
        Debug.Log("*** Path to 360 file : " + path);
    }
    // PREPARE ALL THE MEDIA DATA
    player.source = VideoSource.Url;
    player.url = path;
    player.playOnAwake = true;
    player.enabled = true;
    player.Prepare();

    yield return new WaitUntil(()=> player.isPrepared); 
    player.Play();


    if(Debug.isDebugBuild)
    {
        Debug.LogFormat("*** Video Player information; aspect ratio {0}; frame {1}; frame count {2}, frame rate {3}," +
                        "playback speed {4}, source {5}, url {6}",
                        player.aspectRatio,
                        player.frame, 
                        player.frameCount,
                        player.frameRate, 
                        player.playbackSpeed, 
                        player.source,
                        player.url);


        Debug.LogFormat("*** Clip information; frame rate {0}, Width {1}, height {2}, lenght {3}, name {4}, " +
                        "original path {5}, pixel aspect ratio denominator {6}, pixel aspect ratio numerator {7}",
                        player.clip.frameRate,
                        player.clip.width,
                        player.clip.height,
                        player.clip.length,
                        player.clip.name,
                        player.clip.originalPath,
                        player.clip.pixelAspectRatioDenominator,
                        player.clip.pixelAspectRatioNumerator);
    }

    if (VideoReady != null)
        StartCoroutine(VideoReady());

    yield return new WaitForEndOfFrame();

    if(FindObjectOfType<PanelFadeAnimation>())
        FindObjectOfType<PanelFadeAnimation>().EnlightenScene();
}

0 个答案:

没有答案