Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用VideoPlayer播放360度立体视频_C#_Video_Unity3d_Virtual Reality_Video Player - Fatal编程技术网

C# 使用VideoPlayer播放360度立体视频

C# 使用VideoPlayer播放360度立体视频,c#,video,unity3d,virtual-reality,video-player,C#,Video,Unity3d,Virtual Reality,Video Player,我想在Android上的Unity虚拟现实中播放立体360度视频。到目前为止,我一直在做一些研究,我有两个左右眼摄像头,每个摄像头周围都有一个球体。我还需要一个自定义着色器使图像在球体内部渲染。通过将y平铺设置为0.5,在一个球体上显示图像的上半部分,在另一个球体上显示图像的下半部分,y平铺为0.5,y偏移为0.5有了它,我可以显示一个已经正确的3D 360度图像。整个想法来自于 现在对于视频,我需要控制视频速度,所以我需要新Unity 5.6 beta版的视频播放器。目前为止,我的设置要求视频

我想在Android上的Unity虚拟现实中播放立体360度视频。到目前为止,我一直在做一些研究,我有两个左右眼摄像头,每个摄像头周围都有一个球体。我还需要一个自定义着色器使图像在球体内部渲染。通过将y平铺设置为0.5,在一个球体上显示图像的上半部分,在另一个球体上显示图像的下半部分,y平铺为0.5,y偏移为0.5有了它,我可以显示一个已经正确的3D 360度图像。整个想法来自于

现在对于视频,我需要控制视频速度,所以我需要新Unity 5.6 beta版的视频播放器。目前为止,我的设置要求视频播放器在两个球体上播放视频,其中一个球体播放上部(一只眼睛),另一个视频播放下部(另一只眼睛)

这是我的问题:我不知道如何让视频播放器在两种不同的材质上播放相同的视频(因为它们具有不同的平铺值)。有办法吗

我得到了一个提示,我可以使用相同的材质,通过UV实现平铺效果,但我不知道这是如何工作的,我甚至没有视频播放器在两个对象上播放视频,在两个对象上使用相同的材质。我有一张截图。右边的球体只有材质videoMaterial。没有瓷砖,因为我必须通过紫外线

走哪条路,怎么做?我来对了吗

我来对了吗

几乎可以,但您当前使用的是
渲染器
材质
,而不是
渲染器
材质

走哪条路,怎么做

您需要为此使用
RenderTexture
。基本上,将视频渲染到
RenderTexture
,然后将该纹理指定给两个球体的材质

1。创建一个
渲染环境
,并将其分配给
视频播放器

2。为球体创建两种材质

3。将
VideoPlayer.renderMode
设置为
VideoRenderMode.RenderTexture

4。将两个球体的纹理设置为
RenderTexture

5。准备并播放视频

下面的代码正是这样做的。它应该是现成的。您需要做的唯一一件事是根据您的需要修改每种材质的平铺和偏移

您还应注释掉:

leftSphere = createSphere("LeftEye", new Vector3(-5f, 0f, 0f), new Vector3(4f, 4f, 4f));
rightSphere = createSphere("RightEye", new Vector3(5f, 0f, 0f), new Vector3(4f, 4f, 4f));
然后使用从任何3D应用程序导入的球体。这一行代码只是为了测试目的,使用Unity的球体播放视频不是一个好主意,因为球体没有足够的细节使视频平滑

using UnityEngine;
using UnityEngine.Video;

public class StereoscopicVideoPlayer : MonoBehaviour
{
    RenderTexture renderTexture;

    Material leftSphereMat;
    Material rightSphereMat;

    public GameObject leftSphere;
    public GameObject rightSphere;

    private VideoPlayer videoPlayer;

    //Audio
    private AudioSource audioSource;

    void Start()
    {
        //Create Render Texture
        renderTexture = createRenderTexture();

        //Create Left and Right Sphere Materials
        leftSphereMat = createMaterial();
        rightSphereMat = createMaterial();

        //Create the Left and Right Sphere Spheres
        leftSphere = createSphere("LeftEye", new Vector3(-5f, 0f, 0f), new Vector3(4f, 4f, 4f));
        rightSphere = createSphere("RightEye", new Vector3(5f, 0f, 0f), new Vector3(4f, 4f, 4f));

        //Assign material to the Spheres
        leftSphere.GetComponent<MeshRenderer>().material = leftSphereMat;
        rightSphere.GetComponent<MeshRenderer>().material = rightSphereMat;

        //Add VideoPlayer to the GameObject
        videoPlayer = gameObject.AddComponent<VideoPlayer>();

        //Add AudioSource
        audioSource = gameObject.AddComponent<AudioSource>();

        //Disable Play on Awake for both Video and Audio
        videoPlayer.playOnAwake = false;
        audioSource.playOnAwake = false;

        // We want to play from url
        videoPlayer.source = VideoSource.Url;
        videoPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";

        //Set Audio Output to AudioSource
        videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;

        //Assign the Audio from Video to AudioSource to be played
        videoPlayer.EnableAudioTrack(0, true);
        videoPlayer.SetTargetAudioSource(0, audioSource);

        //Set the mode of output to be RenderTexture
        videoPlayer.renderMode = VideoRenderMode.RenderTexture;

        //Set the RenderTexture to store the images to
        videoPlayer.targetTexture = renderTexture;

        //Set the Texture of both Spheres to the Texture from the RenderTexture
        assignTextureToSphere();

        //Prepare Video to prevent Buffering
        videoPlayer.Prepare();

        //Subscribe to prepareCompleted event
        videoPlayer.prepareCompleted += OnVideoPrepared;
    }


    RenderTexture createRenderTexture()
    {

        RenderTexture rd = new RenderTexture(1024, 1024, 16, RenderTextureFormat.ARGB32);
        rd.Create();
        return rd;
    }

    Material createMaterial()
    {
        return new Material(Shader.Find("Specular"));
    }

    void assignTextureToSphere()
    {
        //Set the Texture of both Spheres to the Texture from the RenderTexture
        leftSphereMat.mainTexture = renderTexture;
        rightSphereMat.mainTexture = renderTexture;
    }

    GameObject createSphere(string name, Vector3 spherePos, Vector3 sphereScale)
    {
        GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        sphere.transform.position = spherePos;
        sphere.transform.localScale = sphereScale;
        sphere.name = name;
        return sphere;
    }

    void OnVideoPrepared(VideoPlayer source)
    {
        Debug.Log("Done Preparing Video");

        //Play Video
        videoPlayer.Play();

        //Play Sound
        audioSource.Play();

        //Change Play Speed
        if (videoPlayer.canSetPlaybackSpeed)
        {
            videoPlayer.playbackSpeed = 1f;
        }
    }
}
使用UnityEngine;
使用UnityEngine.Video;
公共级立体视频播放器:单行为
{
渲染器渲染器渲染器;
材料左球体;
材料右旋球体;
公共游戏对象左球体;
公共游戏对象rightSphere;
私人视频播放器;
//音频
私人音频源音频源;
void Start()
{
//创建渲染纹理
renderTexture=createRenderTexture();
//创建左侧和右侧球体材质
leftSphereMat=createMaterial();
rightSphereMat=createMaterial();
//创建左侧和右侧球体
leftSphere=createSphere(“左眼”,新矢量3(-5f,0f,0f),新矢量3(4f,4f,4f));
rightSphere=createSphere(“右眼”、新矢量3(5f、0f、0f)、新矢量3(4f、4f、4f));
//将材质指定给球体
leftSphere.GetComponent().material=leftSphereMat;
rightSphere.GetComponent().material=rightSphereMat;
//将VideoPlayer添加到游戏对象
videoPlayer=gameObject.AddComponent();
//添加音频源

audioSource=gameObject.AddComponent介绍如何使用特殊着色器进行此操作,但这对我和其他一些人不起作用。我建议您使用上述方法,直到将VR支持添加到
VideoPlayer
API。

“我有两个左右眼摄像头,每个摄像头周围都有一个球体。”这是为VR设计的吗?啊,是的,我应该在某个地方提到它。我到目前为止只提到了立体声。然后标记VR。看起来你想要用C#语言的解决方案。为什么不标记它呢?标记也很重要。只是为你做了。谢谢你添加了VR标记。我不需要用C#语言的解决方案。如果有人说我需要用另一种语言做,我会这么做:)Boo have been在Unity中停产,但我会尽我最大的努力提供解决方案。这是一种很棒的语言。
VideoPlayer
仍然是新的,处于测试阶段,在一些Android设备上仍然不起作用。Unity意识到这一点,他们正在开发它。慢慢来。