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

网站备案依据长沙市最新疫情

网站备案依据,长沙市最新疫情,做网站英文编辑有前途,汽车充电桩网站建设中企动力技术支持Unity3D使用场景 Unity3D是非常流行的游戏开发引擎,可以创建各种类型的3D和2D游戏或其他互动应用程序。常见使用场景如下: 游戏开发:Unity3D是一个广泛用于游戏开发的环境,适用于创建各种类型的游戏,包括动作游戏、角…

Unity3D使用场景

Unity3D是非常流行的游戏开发引擎,可以创建各种类型的3D和2D游戏或其他互动应用程序。常见使用场景如下:

  1. 游戏开发:Unity3D是一个广泛用于游戏开发的环境,适用于创建各种类型的游戏,包括动作游戏、角色扮演游戏、策略游戏、冒险游戏等。
  2. 虚拟现实:Unity3D也常用于虚拟现实(VR)开发,它提供了对VR设备的支持,如Oculus Rift和HTC Vive。
  3. 交互式演示:Unity3D可以用于创建各种类型的交互式演示,如产品原型、建筑和设计模拟器、教育应用程序等。
  4. 实时渲染:Unity3D的实时渲染功能可以用于创建电影级的特效和动画,以及用于视觉预览和产品渲染。
  5. 跨平台开发:Unity3D支持多个平台,包括PC、Mac、Linux、Android、iOS、Windows等,这使得开发者可以更容易地将他们的应用程序和游戏移植到不同的平台。

无论你是在哪个领域使用Unity3D,都需要了解其基本的工具和功能,包括场景编辑器、游戏对象、组件、脚本等。同时,还需要掌握一些基本的编程语言,如C#,以编写游戏逻辑和控制流程。

如何获取Camera场景数据

Unity3D获取摄像机数据通常用RenderTexture和RenderTexture.GetPixel方法来获取数据,把捕获屏幕的图像,存储在一个Texture2D实例中,用这个实例获取RGB数据。需要注意的是,需要为输出纹理创建一个新的纹理对象,否则可能会在屏幕上看到一片空白。示例代码如下:

using UnityEngine;  public class GetCameraData : MonoBehaviour  
{  public Texture2D outputTexture; // 输出纹理,用于存储RGB数据  public RenderTexture renderTexture; // RenderTexture实例,用于捕获屏幕图像  void Start()  {  // 创建一个RenderTexture实例  renderTexture = new RenderTexture(Screen.width, Screen.height, 24);  // 获取当前摄像机  Camera camera = GetComponent<Camera>();  // 将当前摄像机的屏幕输出设置为刚刚创建的RenderTexture实例  camera.targetTexture = renderTexture;  // 创建一个空的Texture2D实例,用于存储从RenderTexture读取的RGB数据  outputTexture = new Texture2D(Screen.width, Screen.height);  }  void Update()  {  // 从RenderTexture中读取RGB数据,并存储到outputTexture中  RenderTexture.active = renderTexture;  outputTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);  outputTexture.Apply();  }  
}

如何实现RTMP推送服务

本文以大牛直播SDK开发的Unity3D下Android平台的RTMP推送camera场景的demo为例,结合Unity和原生模块交互,大概介绍下核心实现逻辑。

开始推送RTMP服务:

    public bool StartRtmpPusher(){if (is_pushing_rtmp_){Debug.Log("已推送..");   return false;}if(!is_rtsp_publisher_running_){InitAndSetConfig();}if (pusher_handle_ == 0) {Debug.LogError("StartRtmpPusher, publisherHandle is null..");return false;}NT_PB_U3D_SetPushUrl(pusher_handle_, rtmp_push_url_);int is_suc = NT_PB_U3D_StartPublisher(pusher_handle_);if (is_suc  == DANIULIVE_RETURN_OK){Debug.Log("StartPublisher success..");          is_pushing_rtmp_ = true;}else{Debug.LogError("StartPublisher failed..");return false;}return true;}

InitAndSetConfig()完成常规参数设置,比如软硬编码、帧率、码率等参数设置,如果需要采集audio,还可以把麦克风采集到的audio和audioclip获取到的audio数据mix后输出:

    private void InitAndSetConfig(){if ( java_obj_cur_activity_ == null ){Debug.LogError("getApplicationContext is null");return;}int audio_opt = 1;int video_opt = 3;video_width_ = camera_.pixelWidth;video_height_ = camera_.pixelHeight;pusher_handle_ = NT_PB_U3D_Open(audio_opt, video_opt, video_width_, video_height_);if (pusher_handle_ != 0){Debug.Log("NT_PB_U3D_Open success");NT_PB_U3D_Set_Game_Object(pusher_handle_, game_object_);}else{Debug.LogError("NT_PB_U3D_Open failed!");return;}int fps = 30;int gop = fps * 2;if(video_encoder_type_ == (int)PB_VIDEO_ENCODER_TYPE.VIDEO_ENCODER_HARDWARE_AVC){int h264HWKbps = setHardwareEncoderKbps(true, video_width_, video_height_);h264HWKbps = h264HWKbps * fps / 25;Debug.Log("h264HWKbps: " + h264HWKbps);int isSupportH264HWEncoder = NT_PB_U3D_SetVideoHWEncoder(pusher_handle_, h264HWKbps);if (isSupportH264HWEncoder == 0) {NT_PB_U3D_SetNativeMediaNDK(pusher_handle_, 0);NT_PB_U3D_SetVideoHWEncoderBitrateMode(pusher_handle_, 1); // 0:CQ, 1:VBR, 2:CBRNT_PB_U3D_SetVideoHWEncoderQuality(pusher_handle_, 39);NT_PB_U3D_SetAVCHWEncoderProfile(pusher_handle_, 0x08); // 0x01: Baseline, 0x02: Main, 0x08: High// NT_PB_U3D_SetAVCHWEncoderLevel(pusher_handle_, 0x200); // Level 3.1// NT_PB_U3D_SetAVCHWEncoderLevel(pusher_handle_, 0x400); // Level 3.2// NT_PB_U3D_SetAVCHWEncoderLevel(pusher_handle_, 0x800); // Level 4NT_PB_U3D_SetAVCHWEncoderLevel(pusher_handle_, 0x1000); // Level 4.1 多数情况下,这个够用了//NT_PB_U3D_SetAVCHWEncoderLevel(pusher_handle_, 0x2000); // Level 4.2// NT_PB_U3D_SetVideoHWEncoderMaxBitrate(pusher_handle_, ((long)h264HWKbps)*1300);Debug.Log("Great, it supports h.264 hardware encoder!");}}else if(video_encoder_type_ == (int)PB_VIDEO_ENCODER_TYPE.VIDEO_ENCODER_HARDWARE_HEVC){int hevcHWKbps = setHardwareEncoderKbps(false, video_width_, video_height_);hevcHWKbps = hevcHWKbps*fps/25;Debug.Log("hevcHWKbps: " + hevcHWKbps);int isSupportHevcHWEncoder = NT_PB_U3D_SetVideoHevcHWEncoder(pusher_handle_, hevcHWKbps);if (isSupportHevcHWEncoder == 0) {NT_PB_U3D_SetNativeMediaNDK(pusher_handle_, 0);NT_PB_U3D_SetVideoHWEncoderBitrateMode(pusher_handle_, 0); // 0:CQ, 1:VBR, 2:CBRNT_PB_U3D_SetVideoHWEncoderQuality(pusher_handle_, 39);// NT_PB_U3D_SetVideoHWEncoderMaxBitrate(pusher_handle_, ((long)hevcHWKbps)*1200);Debug.Log("Great, it supports hevc hardware encoder!");}}else {if (is_sw_vbr_mode_) //H.264 software encoder{int is_enable_vbr = 1;int video_quality = CalVideoQuality(video_width_, video_height_, true);int vbr_max_bitrate = CalVbrMaxKBitRate(video_width_, video_height_);vbr_max_bitrate = vbr_max_bitrate * fps / 25;NT_PB_U3D_SetSwVBRMode(pusher_handle_, is_enable_vbr, video_quality, vbr_max_bitrate);//NT_PB_U3D_SetSWVideoEncoderSpeed(pusher_handle_, 2);}}NT_PB_U3D_SetAudioCodecType(pusher_handle_, 1);NT_PB_U3D_SetFPS(pusher_handle_, fps);NT_PB_U3D_SetGopInterval(pusher_handle_, gop);if (audio_push_type_ == (int)PB_AUDIO_OPTION.AUDIO_OPTION_MIC_EXTERNAL_PCM_MIXER|| audio_push_type_ == (int)PB_AUDIO_OPTION.AUDIO_OPTION_TWO_EXTERNAL_PCM_MIXER){NT_PB_U3D_SetAudioMix(pusher_handle_, 1);}else{NT_PB_U3D_SetAudioMix(pusher_handle_, 0);}}

投递video数据的逻辑实现如下:

    void PostVideoData() {if(pusher_handle_ == 0)return;if(!is_pushing_rtmp_ && !is_rtsp_publisher_running_)return;if (textures_poll_ == null)return;int w = camera_.pixelWidth;int h = camera_.pixelHeight;if (w != video_width_ || h != video_height_) {Debug.Log("PostVideoData resolution changed++ width: " + w + " height: " + h);if(render_texture_ != null) {render_texture_.Release();render_texture_ = null;}video_width_  = w;video_height_ = h;}if (null == render_texture_ ) {render_texture_ = new RenderTexture(video_width_, video_height_, 16);render_texture_.Create();}Texture2D image_texture = textures_poll_.get(video_width_, video_height_);if (null == image_texture)return;...image_texture.ReadPixels(new Rect(0, 0, video_width_, video_height_), 0, 0, false);...post_image_worker_.post(image_texture, is_vertical_flip_, is_horizontal_flip_, scale_width_, scale_height_);}

如果需要停止RTMP推送:

    private void StopRtmpPusher(){if(!is_pushing_rtmp_)return;NT_PB_U3D_StopPublisher(pusher_handle_);if(!is_rtsp_publisher_running_){NT_PB_U3D_Close(pusher_handle_);pusher_handle_ = 0;NT_PB_U3D_UnInit();}is_pushing_rtmp_ = false;}

技术总结

Unity3D下采集camera场景并推送RTMP具有重要的意义,可以为实时监控、在线直播、视频教程制作、增强现实和虚拟现实应用以及数据记录和分析等领域提供有力的支持。比如,采集camera场景可以用于增强现实和虚拟现实应用。在AR中,可以通过采集实际场景的画面,将虚拟元素与现实场景进行融合,增强沉浸感和互动性。

http://www.yidumall.com/news/92468.html

相关文章:

  • 企业网站建设的调研朋友圈推广文案
  • 以下属于网站的管理 更新 维护优化大师手机版
  • 用jsp做的购物网站seo优化网站教程百度
  • 网站建设贰金手指下拉it教育培训机构排名
  • 中国专业做鞋子的网站企业网站优化哪家好
  • 合肥专业做网站的网站发帖推广平台
  • 一个网站是怎么建立的长沙网站优化推广
  • 用什么做公司宣传网站轻松seo优化排名
  • 个人养老金制度来了百度关键词优化送网站
  • 一站式网站建设比较好网络营销的基本功能
  • 长治网站建设培训文件电商运营平台
  • 金融企业网站建设郑州做网站的大公司
  • android编程开发淘宝seo软件
  • 2023年5月新冠症状seo页面代码优化
  • 网站seo优化包括哪些方面清远新闻最新
  • 主要给人家做网站的公司网站出售
  • 网站策划书哪个容易做央视新闻最新消息今天
  • 施工程找工程做哪个网站好惠州百度seo找谁
  • 官方网站做兼职seo技术助理
  • 微信公众平台网站建设新闻报道网页设计软件
  • 南通网站建设方案服务seo交互论坛
  • wordpress防止ddos插件百度seo教程
  • 永久免费建个人主页简述什么是seo及seo的作用
  • 做彩票网站电话多少成全在线观看免费高清动漫
  • 手把手教建设网站媒体广告投放平台
  • steam网站代做百度免费咨询
  • 深圳建网站多少钱公司官网优化方案
  • 建筑网站排行网络营销品牌案例
  • 澄海玩具网站建设公司如何让百度收录
  • mac电脑安装wordpress北京seo关键词