德州市网站建设内江网站建设新闻

当前位置: 首页 > news >正文

德州市网站建设,内江网站建设新闻,墙纸 html 网站模板,网络直播公司营销方案技术背景 Unity3D可以用于创建各种类型的的应用程序#xff0c;包括虚拟现实、培训模拟器等。以下是一些可以使用Unity3D全景播放的场景#xff1a; 虚拟现实体验#xff1a;全景视频可以用来创建逼真的虚拟环境#xff0c;使用户能够感受到身临其境的感觉#xff1b;培…技术背景 Unity3D可以用于创建各种类型的的应用程序包括虚拟现实、培训模拟器等。以下是一些可以使用Unity3D全景播放的场景 虚拟现实体验全景视频可以用来创建逼真的虚拟环境使用户能够感受到身临其境的感觉培训模拟器全景视频可以用来创建真实的训练环境例如飞行模拟器、驾驶模拟器等以提供更加真实的训练体验建筑设计全景视频可以用来展示建筑设计的或室内装潢使客户能够感受到真实的的效果文旅导览全景视频可以用来展示旅游景点或城市使游客能够感受到身临其境的感觉。 在Unity3D平台上实现全景实时RTMP或RTSP流渲染可以通过以下方式 获取全景视频数据源首先需要拉取RTMP或RTSP流数据解码后把RGB或YUV数据回调到unity从而获取到全景视频流数据Unity创建个Sphere创建个材质球(Material)并把材质球挂在到Sphere实现实时渲染使用Unity3D的渲染管道您可以将纹理映射到球体或立方体的表面上并使用着色器来处理纹理的坐标以实现全景视频的实时渲染。 技术实现 本文以大牛直播SDK的RTMP推送端作为数据采集获取全景窗体数据后编码打包推送到RTMP服务或启动个轻量级RTSP服务对外提供个RTSP的拉流URL。 然后播放端拉取RTSP或RTMP的URL把YUV或RGB数据回调上来然后再在Unity窗体绘制出来。 获取数据源 public void Play(int sel){if (videoctrl[sel].is_running){Debug.Log(已经在播放..);return;}lock (videoctrl[sel].framelock){videoctrl[sel].cur_videoframe null;}OpenPlayer(sel);if (videoctrl[sel].playerhandle IntPtr.Zero)return;//设置播放URLNTSmartPlayerSDK.NT_SP_SetURL(videoctrl[sel].playerhandle, videoctrl[sel].videoUrl);/* 播放前参数配置可加在此处 /int play_buffertime 0;NTSmartPlayerSDK.NT_SP_SetBuffer(videoctrl[sel].playerhandle, play_buffertime); //设置buffer timeint is_using_tcp 0; //TCP模式NTSmartPlayerSDK.NT_SP_SetRTSPTcpMode(videoctrl[sel].playerhandle, is_using_tcp);int timeout 10;NTSmartPlayerSDK.NT_SP_SetRtspTimeout(videoctrl[sel].playerhandle, timeout);int is_auto_switch_tcp_udp 1;NTSmartPlayerSDK.NT_SP_SetRtspAutoSwitchTcpUdp(videoctrl[sel].playerhandle, is_auto_switch_tcp_udp);Boolean ismute false;NTSmartPlayerSDK.NT_SP_SetMute(videoctrl[sel].playerhandle, ismute ? 1 : 0); //是否启动播放的时候静音int is_fast_startup 1;NTSmartPlayerSDK.NT_SP_SetFastStartup(videoctrl[sel].playerhandle, is_fast_startup); //设置快速启动模式Boolean is_lowlatency false;NTSmartPlayerSDK.NT_SP_SetLowLatencyMode(videoctrl[sel].playerhandle, is_lowlatency ? 1 : 0); //设置是否启用低延迟模式//设置旋转角度(设置0 90 180 270度有效其他值无效)int rotate_degrees 0;NTSmartPlayerSDK.NT_SP_SetRotation(videoctrl[sel].playerhandle, rotate_degrees);int volume 100;NTSmartPlayerSDK.NT_SP_SetAudioVolume(videoctrl[sel].playerhandle, volume); //设置播放音量, 范围是[0, 100], 0是静音100是最大音量, 默认是100// 设置上传下载报速度int is_report 0;int report_interval 2;NTSmartPlayerSDK.NT_SP_SetReportDownloadSpeed(videoctrl[sel].playerhandle, is_report, report_interval);/ – 播放前参数配置可加在此处 – *///video frame callback (YUV/RGB)videoctrl[sel].video_frame_callback new SP_SDKVideoFrameCallBack(NT_SP_SetVideoFrameCallBack);NTSmartPlayerSDK.NT_SP_SetVideoFrameCallBack(videoctrl[sel].playerhandle, (Int32)NT.NTSmartPlayerDefine.NT_SP_E_VIDEO_FRAME_FORMAT.NT_SP_E_VIDEO_FRAME_FROMAT_I420, windowhandle, videoctrl[sel].video_frame_callback);UInt32 flag NTSmartPlayerSDK.NT_SP_StartPlay(videoctrl[sel].playerhandle);if (flag DANIULIVE_RETURN_OK){videoctrl[sel].is_need_getframe true;Debug.Log(播放成功);}else{videoctrl[sel].is_need_getframe false;Debug.LogError(播放失败);}videoctrl[sel].is_running true;} 针对数据处理 private void SDKVideoFrameCallBack(UInt32 status, IntPtr frame, int sel){//这里拿到回调frame进行相关操作NT_SP_VideoFrame video_frame (NT_SP_VideoFrame)Marshal.PtrToStructure(frame, typeof(NT_SP_VideoFrame));VideoFrame u3d_frame new VideoFrame();u3dframe.width videoframe.width;u3dframe.height videoframe.height;u3dframe.timestamp (UInt64)videoframe.timestamp;int d_y_stride videoframe.width;int d_u_stride (videoframe.width 1) / 2;int d_v_stride d_u_stride;int d_y_size d_y_stride * videoframe.height;int d_u_size d_u_stride * ((videoframe.height 1) / 2);int d_v_size d_u_size;int u_v_height ((u3dframe.height 1) / 2);u3d_frame.ystride d_y_stride;u3d_frame.ustride d_u_stride;u3d_frame.vstride d_v_stride;u3d_frame.ydata new byte[d_y_size];u3d_frame.udata new byte[d_u_size];u3d_frame.vdata new byte[d_v_size];CopyFramePlane(u3d_frame.ydata, d_y_stride,videoframe.plane0, videoframe.stride0, u3dframe.height);CopyFramePlane(u3d_frame.udata, d_u_stride,videoframe.plane1, videoframe.stride1, u_v_height);CopyFramePlane(u3d_frame.vdata, d_v_stride,videoframe.plane2, videoframe.stride2, u_v_height);lock (videoctrl[sel].framelock ){videoctrl[sel].cur_videoframe u3d_frame;}} 刷新Texture private void UpdateYUVTexture(VideoFrame video_frame, int sel) {if (video_frame.ydata null || video_frame.udata null || video_frame.vdata null){Debug.Log(video frame with null..);return;}if (videoctrl[sel].yTexture_ ! null){videoctrl[sel].yTexture_.LoadRawTextureData(video_frame.ydata);videoctrl[sel].yTexture.Apply();}if (videoctrl[sel].uTexture ! null){videoctrl[sel].uTexture_.LoadRawTextureData(video_frame.udata);videoctrl[sel].uTexture.Apply();}if (videoctrl[sel].vTexture ! null){videoctrl[sel].vTexture_.LoadRawTextureData(video_frame.vdata);videoctrl[sel].vTexture_.Apply();} } 全景播放的时候如果需要移动显示区域可以用以下代码 public class MouseMove : MonoBehaviour {Vector2 p1, p2;private Vector3 PreMouseMPos;private Vector3 PreMouseLPos;public float minimumY -60F;public float maximumY 60F;float rotationY 0F;private float wheelSpeed 5.0f;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {if (Input.GetMouseButton(0)){if (PreMouseLPos.x 0){PreMouseLPos new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f);}else{Vector3 CurMouseLPos new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f);Vector3 offset CurMouseLPos - PreMouseLPos;Quaternion tt Quaternion.Euler(offset);float rotationX transform.localEulerAngles.y - tt.x * 20;rotationY tt.y * 20;rotationY Mathf.Clamp(rotationY, minimumY, maximumY);transform.localEulerAngles new Vector3(rotationY, rotationX, 0);PreMouseLPos CurMouseLPos;}}else{PreMouseLPos new Vector3(0.0f, 0.0f, 0.0f);}} }总结 Unity全景播放RTMP或RTSP实时流可以广泛用于各种需要提供真实场景或沉浸式体验的场景为用户带来更加逼真的体验。与此同时Unity全景实时播放需要有非常高的延迟要求和性能要求特别是全景数据源分辨率和码率都非常高对解码效率和解码后的数据拷贝投递提了更高的要求。