《圖說VR入門》——360全景視頻

本文章由cartzhang編寫,轉載請註明出處。 所有權利保留。
文章連接:http://blog.csdn.net/cartzhang/article/details/53674647
做者:cartzhang
css

《圖說VR入門》——360全景視頻

本章用使用較早的Unity OC 插件來實現一個360全景視頻。且經過使用不一樣的路徑配置,可以任意切換視頻內容。這樣省去了屢次打包的過程。簡單易用。git


固然,你可以花費40刀來購買一個。
https://www.assetstore.unity3d.com/cn/#!/content/35102
這個仍是聽貴的。
github


仍是製做一個免費的吧!!
ruby

markdown


打包後的可下載地址,沒有password:
OC 版本號 0.8.0 雲盤地址:
http://pan.baidu.com/s/1nv4QLuD
OC版本號0.4.4雲盤地址:
http://pan.baidu.com/s/1jI8uDRC
app

1、所需資源


簡單製做一個360的全景視頻,需要資源有:
AVPro Windows Media2.9.0 unity插件
下載地址:
http://pan.baidu.com/s/1bz7pc6

需要安裝OC的0.4.4runtime:
http://pan.baidu.com/s/1jIJPXCa
less

這裏寫圖片描寫敘述
圖1

Untiy所使用版本號:
ide

這裏寫圖片描寫敘述
圖2函數

2、製做一個360的VR視頻

1.導入插件


導入AVPro Windows Media2.9.0插件
oop

這裏寫圖片描寫敘述
圖6

找到他給出的預製體例如如下圖:

這裏寫圖片描寫敘述
圖7

而後選擇視頻文件:

這裏寫圖片描寫敘述
圖8

2.解碼器安裝


若這時候執行,就會報錯,例如如下
依據報錯:
For MP4 files you need an MP4 splitter such as Haali Media Splitter or GDCL.

這裏寫圖片描寫敘述
圖9

若感興趣想深刻了解的,可以看看例如如下地址:

http://haali.su/mkv/

若來這裏直接下載所需要的解碼器:
下載地址:

而後安裝:

這裏寫圖片描寫敘述
圖10

這裏寫圖片描寫敘述
圖11

而後再次載入Load測試:
若看到例如如下就說明解碼器成功安裝

這裏寫圖片描寫敘述
圖12

3.設置視頻載入配置和執行設置


首先,需要把原來的主相機屏蔽,而後加入OC的相機預製體

這裏寫圖片描寫敘述
圖13

而後,加入寫好的配置文件代碼:

這裏寫圖片描寫敘述
圖15

最後要注意。不要勾選Virtual Reality supported選項。因爲咱們使用的是低版本號的OCruntime插件。

這裏寫圖片描寫敘述
圖14

固然,我也打包測試了OC 0.8.0的Runtime,可能相對與0.4.4版本號,OC形成的崩潰可能性會小點。這個沒有具體測試,僅僅是相信Unity嵌入和OC的版本號升級優化能力。
打包後的文件也會在後面給出下載連接地址。

3、使用配置文件來打包後隨時改動視頻內容


直接改動AVProWindowsMediaMovie.cs中的LoadMovie函數。

bool allowNativeFormat = (_colourFormat != ColourFormat.RGBA32);

        //string filePath = GetFilePath();
        string filePath = ConfigFile.Cconfig.VediofullPathName;

        if (_moviePlayer.StartVideo(filePath, allowNativeFormat, _colourFormat == ColourFormat.YCbCr_HD, _allowAudio, _useAudioDelay, _useAudioMixer, _useDisplaySync, _ignoreFlips, _textureFilterMode, _textureWrapMode))
        {
            if (_allowAudio)
            {
                _moviePlayer.Volume = _volume;
                _moviePlayer.AudioBalance = _audioBalance;
            }
            _moviePlayer.Loop = _loop;
            if (autoPlay)
            {
                _moviePlayer.Play();
            }
        }
        else

事實上所要改動的僅僅是視頻的載入路徑。僅此而已。
僅僅需更改:

//string filePath = GetFilePath();
        string filePath = ConfigFile.Cconfig.VediofullPathName;

這樣就可以了。

配置文件的腳本:

using UnityEngine;
using System;
using System.IO;
using System.Xml.Serialization;

public class ConfigFile : MonoBehaviour {

    public static ConfigFile Instance { private set; get; }
    public static ClientConfigReference Cconfig;

    void Awake()
    {
        try
        {
            ReadConfigFile(Application.streamingAssetsPath + "/Configfile.xml");
        }
        catch (Exception ex)
        {
            Debug.LogError("Read XML Failed ! " + ex.Message);
        }
    }

    void ReadConfigFile(string filePath)
    {
        try
        {
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            XmlSerializer xs = new XmlSerializer(typeof(ClientConfigReference));
            Cconfig = xs.Deserialize(fs) as ClientConfigReference;
            fs.Dispose();
            Debug.Log("Configfile :" + filePath);
        }
        catch (Exception ex)
        {
            Debug.LogError("Read ConfigFile Failed ! " + ex.Message);
        }
    }
}

// configure class
public class ClientConfigReference
{
    public string VediofullPathName;
}


這個僅僅需要掛載在場景中就能夠。不需要不論什麼操做。


這裏寫圖片描寫敘述
圖15

4、球內使用的shader


360SphereVideo中sphere中使用的材質的Shader.

Shader "Unlit/InsideSphere"
{
    Properties
    {
        // we have removed support for texture tiling/offset,
        // so make them not be displayed in material inspector
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Cull Off

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION; // vertex position
                float2 uv : TEXCOORD0; // texture coordinate
            };

            struct v2f
            {
                float2 uv : TEXCOORD0; // texture coordinate
                float4 vertex : SV_POSITION; // clip space position
            };

            uniform float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);                
                o.uv.xy = TRANSFORM_TEX(float2(1-v.uv.x, v.uv.y), _MainTex);

                return o;
            }

            sampler2D _MainTex;

            fixed4 frag (v2f i) : SV_Target
            {
                // sample texture and return it
                fixed4 col = tex2D(_MainTex, i.uv);
                return col;
            }
            ENDCG
        }
    }
}


有興趣的自行研究下。

5、打包後執行測試:

1. 先使用的星空:

資源可以在文章後面地址下載:
看看漂亮星空:
這裏寫圖片描寫敘述
圖16

這裏寫圖片描寫敘述
圖17

這裏寫圖片描寫敘述
圖18

這裏寫圖片描寫敘述
圖19

可以看到。這是單眼效果,因爲使用大鵬頭盔,使用複製屏的效果,分辨率不正確形成的。但是在直接執行過中。不影響使用和體驗。

2. 來看美女了

經過切換配置文件裏

<VediofullPathName>H:\Unity\UnitySay\360Video\360Demo\360VedioTest\Assets\StreamingAssets\貓耳娘SEASON 2.mp4</VediofullPathName>

來切換視頻內容了。
這裏寫圖片描寫敘述
圖20

這裏寫圖片描寫敘述
圖21

這裏寫圖片描寫敘述
圖22

這裏寫圖片描寫敘述
圖23

因爲紋理清晰度不是很是高,這個需要提升的。
還有就是因爲使用舊版的OC,因此可能會崩潰。崩潰日誌例如如下:
檢重要的貼出來

========== OUTPUTING STACK TRACE ================== ERROR: SymGetSymFromAddr64, GetLastError: '試圖訪問無效的地址。

' (Address: 6CF02036) 6CF02036 (OculusPlugin) 6CF03012 (OculusPlugin) OVR_SetViewport 6CF030D3 (OculusPlugin) UnitySetGraphicsDevice 01040016 (001) RectT<int>::Contains 01040058 (001) RectT<int>::Contains 0104054B (001) RectT<int>::Contains 100399D8 (mono) mono_lookup_pinvoke_call 100484DE (mono) mono_marshal_string_to_utf16 100CF9DD (mono) mono_inst_name 100EF02C (mono) mono_set_defaults 100EFE79 (mono) mono_set_defaults 100F03D4 (mono) mono_set_defaults 100F059D (mono) mono_set_defaults 1005D872 (mono) mono_runtime_invoke 00FC47FE (001) scripting_gchandle_get_target 01077709 (001) ScriptingArguments::AddString 0107777E (001) ScriptingArguments::AddString 010777DC (001) ScriptingArguments::AddString 00FB3462 (001) ReportScriptingObjectsTransfer::TransferTypeless 00FB3669 (001) ReportScriptingObjectsTransfer::TransferTypeless 00FB5988 (001) GetMonoBehaviourInConstructor 00FB3B7C (001) ReportScriptingObjectsTransfer::TransferTypeless 0109768B (001) RegisterAllowNameConversionInDerivedTypes 0109785D (001) RegisterAllowNameConversionInDerivedTypes 01050908 (001) CallbackArray3<std::basic_string<char,std::char_traits<char>,stl_allocator<char,59,16> > const &,AwakeFromLoadQueue &,enum LoadSceneOperation::LoadingMode>::Invoke 01050B0F (001) CallbackArray3<std::basic_string<char,std::char_traits<char>,stl_allocator<char,59,16> > const &,AwakeFromLoadQueue &,enum LoadSceneOperation::LoadingMode>::Invoke .... ========== END OF STACKTRACE ===========

就這樣。



因此,仍是剛纔說的。你可以使用更高版本號的OC的0.8.0版本號的打包版本號。

6、資源下載地址:


貓耳娘視頻地址雲盤下載: https://pan.baidu.com/s/1qYtVhfe

星空視頻雲盤下載:https://pan.baidu.com/s/1c2rBNo8

不少其它可地址:http://vr.diyiapp.com/vrsp/

project下載github地址:
https://github.com/cartzhang/ImgSayVRabc/tree/master/360Vedio/360Demo/360VedioTest

project下載後,需要把視頻文件放在StreamingAssets下。而後使用配置文件Configfile.xml就可以使用了。



projectrelease地址:打包後,直接在StreamingAssets下加入新的視頻文件,而後使用配置文件Configfile.xml就可以使用。就是這麼簡單,快捷。


解碼器下載地址:
http://pan.baidu.com/s/1o80fjXS
http://pan.baidu.com/s/1mhVbk5U

OC 0.4.4插件下載地址:
http://pan.baidu.com/s/1gfA2TwR

AVPro Windows Media2.9.0 下載地址:
http://pan.baidu.com/s/1gfPvXyr

360視頻遊戲打包完整地址:
OC版本號0.4.4雲盤地址:
http://pan.baidu.com/s/1jI8uDRC

OC 版本號 0.8.0 雲盤地址:
http://pan.baidu.com/s/1nv4QLuD

7、參考

[1]. http://www.panduoduo.net/s/name/%E5%85%A8%E6%99%AF%E8%A7%86%E9%A2%91

[2]. http://bernieroehl.com/360stereoinunity/

[3]. http://download.videolan.org/pub/videolan/x264/binaries/win64/

[4]. http://www.divx.com/zh-hans/software/download/start

[5].http://vr.diyiapp.com/vrsp/

相關文章
相關標籤/搜索