是个小菜鸡 2021-10-08 15:29 采纳率: 20%
浏览 187
已结题

WebRTC RenderStreaming 进行直播,videoPlayer 渲染视频流 ,如何渲染

WebRTC RenderStreaming 进行直播,videoPlayer 渲染视频流 ,不知道如何渲染,我使用raw image 可以播放但是rawimage 不能像videoplayer一样放在 sphere上面 ,就实现不了vr播放器的感觉,还有就是获取得到的数据是texture 类型 ,videoplayer并不支持,想知道如何渲染

我能用rawimage 来播放视频流,我可以用videoplayer 实现vr视频播放器 , 我怎么结合一下,合起来才是我想实现的功能

Unity版本
2021.1.22
平台
vive VR眼镜


   // 思路来源 https://blog.csdn.net/Wenliuyong/article/details/119870304

    // 使用raw image 播放
    public SingleConnection singleConnection;
    public ReceiveVideoViewer videoViewer;
    public RawImage videoView;

    void Start()
    {
         var connectId = "111111";
        singleConnection.CreateConnection(connectId);
        videoViewer.OnUpdateReceiveTexture += (tex) => {
            videoView.texture = tex;
        };
    }

        // 参数 <texture> tex 
        // 使用videoplayer 播放,这个播放不了, 不是很懂

        var videoPlayer = camera.AddComponent<UnityEngine.Video.VideoPlayer>();
        videoPlayer.playOnAwake = true;
        videoPlayer.isLooping = true;
        //videoPlayer.source = UnityEngine.Video.VideoSource.Url;
        videoPlayer.source = UnityEngine.Video.VideoSource.VideoClip;
        // videoPlayer.clip = Application.dataPath + "/Scenes/123.mp4";
        videoPlayer.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;
        videoPlayer.audioOutputMode = UnityEngine.Video.VideoAudioOutputMode.None;
        videoPlayer.SetDirectAudioMute(0, true);
        videoViewer.OnUpdateReceiveTexture += (tex) => {
            // TextureToTexture2D  函数来源网络,具体逻辑不明白
            var r2d = TextureToTexture2D(tex);
           RenderTexture rt = new RenderTexture(tex.width / 2, tex.height / 2, 0);
           RenderTexture.active = rt;
           Graphics.Blit(tex, rt);
           videoPlayer.targetTexture = rt;
        };
  • 写回答

2条回答 默认 最新

  • Cool38142587 2021-10-08 21:31
    关注

    https://zhuanlan.zhihu.com/p/412870658
    不知道对你有没有帮助

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月9日
  • 赞助了问题酬金 10月8日
  • 赞助了问题酬金 10月8日
  • 修改了问题 10月8日
  • 展开全部

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿