做網(wǎng)站做推廣有效果嗎做廣告推廣哪個(gè)平臺(tái)好
技術(shù)背景
VR(虛擬現(xiàn)實(shí)技術(shù))給我們帶來(lái)身臨其境的視覺體驗(yàn),廣泛的應(yīng)用于城市規(guī)劃、教育培訓(xùn)、工業(yè)仿真、房地產(chǎn)、水利電力、室內(nèi)設(shè)計(jì)、文旅、軍事等眾多領(lǐng)域,常用的行業(yè)比如:
- 教育行業(yè):VR頭顯可以用于教育培訓(xùn),提供沉浸式的教學(xué)體驗(yàn),例如虛擬實(shí)驗(yàn)室、虛擬課堂等,幫助學(xué)生更好地理解和掌握知識(shí)。
- 醫(yī)療行業(yè):VR頭顯可以用于醫(yī)療訓(xùn)練和治療,例如手術(shù)模擬、康復(fù)訓(xùn)練等,提高醫(yī)療效果和質(zhì)量。
- 文旅行業(yè):VR頭顯可以用于旅游娛樂,提供沉浸式的旅游體驗(yàn),例如虛擬旅游、文化遺產(chǎn)展示等。
- 房地產(chǎn)行業(yè):VR頭顯可以用于房地產(chǎn)展示,提供更加真實(shí)、直觀的房屋展示和體驗(yàn),幫助客戶更好地了解和選擇房屋。
- 展覽展示行業(yè):VR頭顯可以用于展覽展示,提供沉浸式的展覽體驗(yàn),例如虛擬展廳、虛擬展品等,吸引觀眾的注意和參與。
- 軍事行業(yè):VR頭顯可以用于軍事訓(xùn)練和作戰(zhàn)指揮,提供更加真實(shí)、逼真的軍事訓(xùn)練環(huán)境。
技術(shù)實(shí)現(xiàn)
如何在VR頭顯實(shí)現(xiàn)RTMP或RTSP播放?
VR頭顯播放RTMP或RTSP流數(shù)據(jù),簡(jiǎn)單來(lái)說(shuō),通過(guò)jni層打通RTMP或RTSP流傳輸,解包并解碼回調(diào)給Unity YUV或RGB數(shù)據(jù),Unity場(chǎng)景下,繪制即可,本文以大牛直播SDK的Unity平臺(tái)RTMP、RTSP播放為例,介紹下具體技術(shù)實(shí)現(xiàn):
開始播放:
public void Play(){if (is_running){Debug.Log("已經(jīng)在播放。。"); return;}//獲取輸入框的urlstring url = input_url_.text.Trim();OpenPlayer();if ( player_handle_ == 0 )return;NT_U3D_Set_Game_Object(player_handle_, game_object_);/* ++ 播放前參數(shù)配置可加在此處 ++ */int is_using_tcp = 0; //TCP/UDP模式設(shè)置NT_U3D_SetRTSPTcpMode(player_handle_, is_using_tcp);int is_report = 0;int report_interval = 1;NT_U3D_SetReportDownloadSpeed(player_handle_, is_report, report_interval); //下載速度回調(diào)NT_U3D_SetBuffer(player_handle_, play_buffer_time_); //設(shè)置buffer timeNT_U3D_SetPlayerLowLatencyMode(player_handle_, is_low_latency_ ? 1 : 0); //設(shè)置是否啟用低延遲模式NT_U3D_SetMute(player_handle_, is_mute_ ? 1 : 0); //是否啟動(dòng)播放的時(shí)候靜音NT_U3D_SetAudioVolume(player_handle_, cur_audio_volume_); //設(shè)置播放音量NT_U3D_SetVideoDecoderMode(player_handle_, is_hw_decode_ ? 1 : 0); //設(shè)置H.264軟硬解模式NT_U3D_SetVideoHevcDecoderMode(player_handle_, is_hw_decode_ ? 1 : 0); //設(shè)置H.265軟硬解模式int is_fast_startup = 1;NT_U3D_SetFastStartup(player_handle_, is_fast_startup); //設(shè)置快速啟動(dòng)模式int rtsp_timeout = 10;NT_U3D_SetRTSPTimeout(player_handle_, rtsp_timeout); //設(shè)置RTSP超時(shí)時(shí)間int is_auto_switch_tcp_udp = 1;NT_U3D_SetRTSPAutoSwitchTcpUdp(player_handle_, is_auto_switch_tcp_udp); //設(shè)置TCP/UDP模式自動(dòng)切換int is_audiotrack = 1;NT_U3D_SetAudioOutputType(player_handle_, is_audiotrack); //設(shè)置音頻輸出模式: if 0: 自動(dòng)選擇; if with 1: audiotrack模式NT_U3D_SetUrl(player_handle_, videoUrl);/* -- 播放前參數(shù)配置可加在此處 -- */int flag = NT_U3D_StartPlay(player_handle_);if (flag == DANIULIVE_RETURN_OK){is_need_get_frame_ = true;Debug.Log("播放成功");}else{is_need_get_frame_ = false;Debug.LogError("播放失敗");}is_running = true; }
Close Player:
private void ClosePlayer(){is_need_get_frame_ = false;is_need_init_texture_ = false;int flag = NT_U3D_StopPlay(player_handle_);if (flag == DANIULIVE_RETURN_OK){Debug.Log("停止成功");}else{Debug.LogError("停止失敗");}flag = NT_U3D_Close(player_handle_);if (flag == DANIULIVE_RETURN_OK){Debug.Log("關(guān)閉成功");}else{Debug.LogError("關(guān)閉失敗");}player_handle_ = 0;NT_U3D_UnInit();is_running = false;video_width_ = 0;video_height_ = 0;}
Event事件回調(diào)處理:
/// <summary>/// android 傳遞過(guò)來(lái) code/// </summary>/// <param name="event_message"></param>public void onNTSmartEvent(string event_message){if (null == event_message || event_message.Length < 1)return;string[] strs = event_message.Split(',');if (null == strs || strs.Length < 6)return;string player_handle =strs[0];string code = strs[1];string param1 = strs[2];string param2 = strs[3];string param3 = strs[4];string param4 = strs[5];Debug.Log("[daiusdk] code: 0x" + Convert.ToString(Convert.ToInt32(code), 16));String player_event = "";switch (Convert.ToInt32(code)){case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:player_event = "開始..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:player_event = "連接中..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:player_event = "連接失敗..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:player_event = "連接成功..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:player_event = "連接斷開..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:player_event = "停止播放..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:player_event = "分辨率信息: width: " + Convert.ToInt32(param1) + ", height: " + Convert.ToInt32(param2);break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:player_event = "收不到媒體數(shù)據(jù),可能是url錯(cuò)誤..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_SWITCH_URL:player_event = "切換播放URL..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CAPTURE_IMAGE:player_event = "快照: " + param1 + " 路徑:" + param3;if (Convert.ToInt32(param1) == 0){player_event = "截取快照成功..";}else{player_event = "截取快照失敗..";}break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RECORDER_START_NEW_FILE:player_event = "[record]開始一個(gè)新的錄像文件 : " + param3;break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_ONE_RECORDER_FILE_FINISHED:player_event = "[record]已生成一個(gè)錄像文件 : " + param3;break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_START_BUFFERING:player_event = "Start_Buffering..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_BUFFERING:player_event = "Buffering: " + Convert.ToInt32(param1);break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP_BUFFERING:player_event = "Stop_Buffering..";break;case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DOWNLOAD_SPEED:player_event = "download_speed:" + param1 + "Byte/s" + ", "+ (Convert.ToInt32(param1) * 8 / 1000) + "kbps" + ", " + (Convert.ToInt32(param1) / 1024)+ "KB/s";break;}Debug.Log(player_event);player_event = null;strs = null;}
如何封裝實(shí)現(xiàn)原生jni層交互:
/// SmartPlayerAndroidMono.cs/// Author: daniusdk.com///Created on 2018/05/10/// <summary>/// Init/// </summary>public int NT_U3D_Init(){return player_obj_.Call<int>("Init", java_obj_cur_activity_);}/// <summary>/// 開始/// 返回播放句柄/// </summary>public long NT_U3D_Open(){return player_obj_.Call<long>("Open");}/// <summary>/// Register Game Object,用于消息傳遞/// </summary>public int NT_U3D_Set_Game_Object(long handle, string gameObjectName){return player_obj_.Call<int>("SetGameObject", handle, gameObjectName);}/// <summary>/// 設(shè)置H.264解碼方式 false 軟件解碼 true 硬件解碼 默認(rèn)為false/// </summary>/// <param name="isHwDecoder"></param>public int NT_U3D_SetVideoDecoderMode(long handle, int isHwDecoder){return player_obj_.Call<int>("SetPlayerVideoHWDecoder", handle, isHwDecoder);}/// <summary>/// 設(shè)置H.265 解碼方式 false 軟件解碼 true 硬件解碼 默認(rèn)為false/// </summary>/// <param name="isHevcHwDecoder"></param>public int NT_U3D_SetVideoHevcDecoderMode(long handle, int isHevcHwDecoder){return player_obj_.Call<int>("SetPlayerVideoHevcHWDecoder", handle, isHevcHwDecoder);}/// <summary>/// 設(shè)置音頻輸出模式: if 0: 自動(dòng)選擇; if with 1: audiotrack模式/// </summary>/// <param name="use_audiotrack"></param>public int NT_U3D_SetAudioOutputType(long handle, int use_audiotrack){return player_obj_.Call<int>("SetAudioOutputType", handle, use_audiotrack);}/// <summary>/// 設(shè)置播放端緩存大小, 默認(rèn)200毫秒/// </summary>/// <param name="buffer"></param>public int NT_U3D_SetBuffer(long handle, int buffer){return player_obj_.Call<int>("SetBuffer", handle, buffer);}/// <summary>/// 接口可實(shí)時(shí)調(diào)用:設(shè)置是否實(shí)時(shí)靜音,1:靜音; 0: 取消靜音/// </summary>/// <param name="is_mute"></param>public int NT_U3D_SetMute(long handle, int is_mute){return player_obj_.Call<int>("SetMute", handle, is_mute);}/// <summary>/// 接口可實(shí)時(shí)調(diào)用:設(shè)置播放音量,范圍是[0, 100], 0是靜音,100是最大音量, 默認(rèn)是100/// </summary>/// <param name="audio_volume"></param>public int NT_U3D_SetAudioVolume(long handle, int audio_volume){return player_obj_.Call<int>("SetAudioVolume", handle, audio_volume);}/// <summary>/// 設(shè)置RTSP TCP模式, 1: TCP; 0: UDP/// </summary>/// <param name="is_using_tcp"></param>public int NT_U3D_SetRTSPTcpMode(long handle, int is_using_tcp){return player_obj_.Call<int>("SetRTSPTcpMode", handle, is_using_tcp);}/// <summary>/// 設(shè)置RTSP超時(shí)時(shí)間, timeout單位為秒,必須大于0/// </summary>/// <param name="timeout"></param>public int NT_U3D_SetRTSPTimeout(long handle, int timeout){return player_obj_.Call<int>("SetRTSPTimeout", handle, timeout);}/// <summary>/// 設(shè)置RTSP TCP/UDP自動(dòng)切換/// NOTE: 對(duì)于RTSP來(lái)說(shuō),有些可能支持rtp over udp方式,有些可能支持使用rtp over tcp方式./// 為了方便使用,有些場(chǎng)景下可以開啟自動(dòng)嘗試切換開關(guān), 打開后如果udp無(wú)法播放,sdk會(huì)自動(dòng)嘗試tcp, 如果tcp方式播放不了,sdk會(huì)自動(dòng)嘗試udp./// </summary>/// <param name="timeout"></param>/// timeout:如果設(shè)置1的話, sdk將在tcp和udp之間嘗試切換播放,如果設(shè)置為0,則不嘗試切換.public int NT_U3D_SetRTSPAutoSwitchTcpUdp(long handle, int is_auto_switch_tcp_udp){return player_obj_.Call<int>("SetRTSPAutoSwitchTcpUdp", handle, is_auto_switch_tcp_udp);}/// <summary>/// 設(shè)置快速啟動(dòng)該模式,/// </summary>/// <param name="is_fast_startup"></param>public int NT_U3D_SetFastStartup(long handle, int is_fast_startup){return player_obj_.Call<int>("SetFastStartup", handle, is_fast_startup);}/// <summary>/// 設(shè)置超低延遲模式 false不開啟 true開啟 默認(rèn)false/// </summary>/// <param name="mode"></param>public int NT_U3D_SetPlayerLowLatencyMode(long handle, int mode){return player_obj_.Call<int>("SetPlayerLowLatencyMode", handle, mode);}/// <summary>/// 設(shè)置視頻垂直反轉(zhuǎn)/// is_flip: 0: 不反轉(zhuǎn), 1: 反轉(zhuǎn)/// </summary>/// <param name="is_flip"></param>public int NT_U3D_SetFlipVertical(long handle, int is_flip){return player_obj_.Call<int>("SetFlipVertical", handle, is_flip);}/// <summary>/// 設(shè)置視頻水平反轉(zhuǎn)/// is_flip: 0: 不反轉(zhuǎn), 1: 反轉(zhuǎn)/// </summary>/// <param name="is_flip"></param>public int NT_U3D_SetFlipHorizontal(long handle, int is_flip){return player_obj_.Call<int>("SetFlipHorizontal", handle, is_flip);}/// <summary>/// 設(shè)置順時(shí)針旋轉(zhuǎn), 注意除了0度之外, 其他角度都會(huì)額外消耗性能/// degress: 當(dāng)前支持 0度,90度, 180度, 270度 旋轉(zhuǎn)/// </summary>/// <param name="degress"></param>public int NT_U3D_SetRotation(long handle, int degress){return player_obj_.Call<int>("SetRotation", handle, degress);}/// <summary>/// 設(shè)置是否回調(diào)下載速度/// is_report: if 1: 上報(bào)下載速度, 0: 不上報(bào)./// report_interval: 上報(bào)間隔,以秒為單位,>0./// </summary>/// <param name="is_report"></param>/// <param name="report_interval"></param>public int NT_U3D_SetReportDownloadSpeed(long handle, int is_report, int report_interval){return player_obj_.Call<int>("SetReportDownloadSpeed", handle, is_report, report_interval);}/// <summary>/// 設(shè)置是否需要在播放或錄像過(guò)程中快照/// </summary>/// <param name="is_save_image"></param>public int NT_U3D_SetSaveImageFlag(long handle, int is_save_image){return player_obj_.Call<int>("SetSaveImageFlag", handle, is_save_image);}/// <summary>/// 播放或錄像過(guò)程中快照/// </summary>/// <param name="imageName"></param>public int NT_U3D_SaveCurImage(long handle, string imageName){return player_obj_.Call<int>("SaveCurImage", handle, imageName);}/// <summary>/// 播放或錄像過(guò)程中,快速切換url/// </summary>/// <param name="uri"></param>public int NT_U3D_SwitchPlaybackUrl(long handle, string uri){return player_obj_.Call<int>("SwitchPlaybackUrl", handle, uri);}/// <summary>/// 創(chuàng)建錄像存儲(chǔ)路徑/// </summary>/// <param name="path"></param>public int NT_U3D_CreateFileDirectory(string path){return player_obj_.Call<int>("CreateFileDirectory", path);}/// <summary>/// 設(shè)置錄像存儲(chǔ)路徑/// </summary>/// <param name="path"></param>public int NT_U3D_SetRecorderDirectory(long handle, string path){return player_obj_.Call<int>("SetRecorderDirectory", handle, path);}/// <summary>/// 設(shè)置單個(gè)錄像文件大小/// </summary>/// <param name="size"></param>public int NT_U3D_SetRecorderFileMaxSize(long handle, int size){return player_obj_.Call<int>("SetRecorderFileMaxSize", handle, size);}/// <summary>/// 設(shè)置錄像時(shí)音頻轉(zhuǎn)AAC編碼的開關(guān)/// aac比較通用,sdk增加其他音頻編碼(比如speex, pcmu, pcma等)轉(zhuǎn)aac的功能./// 注意: 轉(zhuǎn)碼會(huì)增加性能消耗/// </summary>/// <param name="is_transcode"></param>/// is_transcode:設(shè)置為1的話,如果音頻編碼不是aac,則轉(zhuǎn)成aac,如果是aac,則不做轉(zhuǎn)換. 設(shè)置為0的話,則不做任何轉(zhuǎn)換. 默認(rèn)是0.public int NT_U3D_SetRecorderAudioTranscodeAAC(long handle, int is_transcode){return player_obj_.Call<int>("SetRecorderAudioTranscodeAAC", handle, is_transcode);}/// <summary>/// 設(shè)置播放路徑/// </summary>public int NT_U3D_SetUrl(long handle, string url){return player_obj_.Call<int>("SetUrl", handle, url);}/// <summary>/// 開始播放/// </summary>public int NT_U3D_StartPlay(long handle){return player_obj_.Call<int>("StartPlay", handle);}/// <summary>/// 獲取YUV數(shù)據(jù)/// </summary>public AndroidJavaObject NT_U3D_GetVideoFrame(long handle){return player_obj_.Call<AndroidJavaObject>("GetVideoFrame", handle);}/// <summary>/// 停止播放/// </summary>public int NT_U3D_StopPlay(long handle){return player_obj_.Call<int>("StopPlay", handle);}/// <summary>/// 開始錄像/// </summary>public int NT_U3D_StartRecorder(long handle){return player_obj_.Call<int>("StartRecorder", handle);}/// <summary>/// 停止錄像/// </summary>public int NT_U3D_StopRecorder(long handle){return player_obj_.Call<int>("StopRecorder", handle);}/// <summary>/// 關(guān)閉播放/// </summary>public int NT_U3D_Close(long handle){return player_obj_.Call<int>("Close", handle);}/// <summary>/// UnInit Player/// </summary>public int NT_U3D_UnInit(){return DANIULIVE_RETURN_OK;}
技術(shù)總結(jié)
通過(guò)實(shí)際測(cè)試來(lái)看,VR頭顯端,如果設(shè)備性能尚可的話,播放RTMP或RTSP,可實(shí)現(xiàn)毫秒級(jí)的延遲,可滿足大多數(shù)有交互訴求的技術(shù)場(chǎng)景,此外,如果頭顯端支持硬解碼的話,可以優(yōu)先考慮硬解碼。