private void OnNewMediaReady()
        {
            IMediaInfo info = _mediaPlayer.Info;

            // Create a texture the same resolution as our video
            if (_texture != null)
            {
                Texture2D.Destroy(_texture);
                _texture = null;
            }

            int textureWidth  = info.GetVideoWidth();
            int textureHeight = info.GetVideoHeight();

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE || UNITY_IOS || UNITY_TVOS
            Orientation ori = Helper.GetOrientation(_mediaPlayer.Info.GetTextureTransform());
            if (ori == Orientation.Portrait || ori == Orientation.PortraitFlipped)
            {
                textureWidth  = info.GetVideoHeight();
                textureHeight = info.GetVideoWidth();
            }
#endif

            _texture = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false);

            _timeStepSeconds = (_mediaPlayer.Info.GetDurationMs() / 1000f) / (float)NumFrames;

#if AVPRO_FILESYSTEM_SUPPORT
            _filenamePrefix = System.IO.Path.GetFileName(_mediaPlayer.m_VideoPath);
#endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Raises the new media ready event.
        /// </summary>
        private void OnNewMediaReady()
        {
            IMediaInfo info = mediaPlayer.Info;

            Debug.Log("GetVideoWidth " + info.GetVideoWidth() + " GetVideoHeight() " + info.GetVideoHeight());

            // Create a texture the same resolution as our video
            if (targetTexture != null)
            {
                Texture2D.Destroy(targetTexture);
                targetTexture = null;
            }
            if (texture != null)
            {
                Texture2D.Destroy(texture);
                texture = null;
            }

            targetTexture = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);

            texture = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.RGBA32, false);

            colors = new Color32[texture.width * texture.height];

            rgbaMat = new Mat(texture.height, texture.width, CvType.CV_8UC4);


            gameObject.GetComponent <Renderer> ().material.mainTexture = texture;
        }
        /// <summary>
        /// Raises the new media ready event.
        /// </summary>
        private void OnNewMediaReady()
        {
            IMediaInfo info = mediaPlayer.Info;

            Debug.Log("GetVideoWidth " + info.GetVideoWidth() + " GetVideoHeight() " + info.GetVideoHeight());

            // Create a texture the same resolution as our video
            if (targetTexture != null)
            {
                Texture2D.Destroy(targetTexture);
                targetTexture = null;
            }
            if (texture != null)
            {
                Texture2D.Destroy(texture);
                texture = null;
            }

            targetTexture = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);

            texture = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.RGBA32, false);

            colors = new Color32[texture.width * texture.height];

            rgbaMat = new Mat(texture.height, texture.width, CvType.CV_8UC4);


            gameObject.GetComponent <Renderer> ().material.mainTexture = texture;


            _timeStepSeconds = (mediaPlayer.Info.GetDurationMs() / 1000f) / (float)NumFrames;
            _frameIndex      = Random.Range(0, NumFrames);
        }
Exemplo n.º 4
0
        void OnGUI()
        {
            if (m_Info != null && m_DebugGui)
            {
                GUI.depth  = -1;
                GUI.matrix = Matrix4x4.TRS(new Vector3(m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(s_GuiScale, s_GuiScale, 1.0f));

                GUILayout.BeginVertical("box", GUILayout.MaxWidth(s_GuiWidth));
                GUILayout.Label(System.IO.Path.GetFileName(m_VideoPath));
                GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + " x " + m_Info.GetVideoHeight());
                GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s");
                GUILayout.Label("Rate: " + m_Info.GetVideoPlaybackRate().ToString("F2") + "Hz");

                if (TextureProducer != null && TextureProducer.GetTexture() != null)
                {
                    // Show texture without and with alpha blending
                    GUILayout.BeginHorizontal();
                    Rect r1 = GUILayoutUtility.GetRect(32f, 32f);
                    GUILayout.Space(8f);
                    Rect r2 = GUILayoutUtility.GetRect(32f, 32f);
                    if (TextureProducer.RequiresVerticalFlip())
                    {
                        GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, r1.y + (r1.height / 2)));
                    }
                    GUI.DrawTexture(r1, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, false);
                    GUI.DrawTexture(r2, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, true);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndVertical();
            }
        }
Exemplo n.º 5
0
		private void OnGUI()
		{
			if (m_Info != null && m_DebugGui)
			{
				GUI.depth = -1000;
				GUI.matrix = Matrix4x4.TRS(new Vector3((float)m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(1.5f, 1.5f, 1f));
				GUILayout.BeginVertical("box", GUILayout.MaxWidth(180f));
				GUILayout.Label(Path.GetFileName(m_VideoPath));
				GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + "x" + m_Info.GetVideoHeight() + "@" + m_Info.GetVideoFrameRate().ToString("F2"));
				GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s");
				GUILayout.Label("Rate: " + m_Info.GetVideoDisplayRate().ToString("F2") + "Hz");
				if (TextureProducer != null && TextureProducer.GetTexture() != null)
				{
					GUILayout.BeginHorizontal();
					Rect rect = GUILayoutUtility.GetRect(32f, 32f);
					GUILayout.Space(8f);
					Rect rect2 = GUILayoutUtility.GetRect(32f, 32f);
					Matrix4x4 matrix = GUI.matrix;
					if (TextureProducer.RequiresVerticalFlip())
					{
						GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0f, rect.y + rect.height / 2f));
					}
					GUI.DrawTexture(rect, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, alphaBlend: false);
					GUI.DrawTexture(rect2, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, alphaBlend: true);
					GUI.matrix = matrix;
					GUILayout.FlexibleSpace();
					GUILayout.EndHorizontal();
				}
				GUILayout.EndVertical();
			}
		}
Exemplo n.º 6
0
        private void OnNewMediaReady()
        {
            IMediaInfo info = _mediaPlayer.Info;

            // Create a texture the same resolution as our video
            if (_texture != null)
            {
                Texture2D.Destroy(_texture);
                _texture = null;
            }
            _texture = new Texture2D(info.GetVideoWidth(), info.GetVideoHeight(), TextureFormat.ARGB32, false);

            _timeStepSeconds = (_mediaPlayer.Info.GetDurationMs() / 1000f) / (float)NumFrames;
#if AVPRO_FILESYSTEM_SUPPORT
            _filenamePrefix = _mediaPlayer.m_VideoPath;
#endif
        }
Exemplo n.º 7
0
        void OnGUI()
        {
            if (m_Info != null && m_DebugGui)
            {
                GUI.depth = -1;

                float debugGuiScale = 1.5f;
                GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(debugGuiScale, debugGuiScale, 1.0f));

                GUILayout.BeginArea(new Rect(m_GuiPositionX, 10, (s_GuiWidth - 10), 150));
                GUILayout.BeginVertical("box");
                GUILayout.Label(System.IO.Path.GetFileName(m_VideoPath));
                GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + " x " + m_Info.GetVideoHeight());
                GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s");
                GUILayout.Label("Rate: " + m_Info.GetVideoPlaybackRate().ToString("F2") + "Hz");
                GUILayout.EndVertical();
                GUILayout.EndArea();
            }
        }
        private void OnInspectorGUI_MediaInfo()
        {
            MediaPlayer   media       = (this.target) as MediaPlayer;
            IMediaInfo    info        = media.Info;
            IMediaControl control     = media.Control;
            ITextTracks   textTracks  = media.TextTracks;
            IAudioTracks  audioTracks = media.AudioTracks;
            IVideoTracks  videoTracks = media.VideoTracks;

            if (info != null)
            {
                if (!info.HasVideo() && !info.HasAudio())                // && !info.HasText())
                {
                    GUILayout.Label("No media loaded");
                }
                else
                {
                    if (info.HasVideo())
                    {
                        GUILayout.BeginHorizontal();
                        {
                            string dimensionText = string.Format("{0}x{1}@{2:0.##}", info.GetVideoWidth(), info.GetVideoHeight(), info.GetVideoFrameRate());
                            GUILayout.Label(dimensionText);
                            GUILayout.FlexibleSpace();
                            string rateText = "0.00";
                            if (media.Info != null)
                            {
                                rateText = media.Info.GetVideoDisplayRate().ToString("F2");
                            }
                            GUILayout.Label(rateText + "FPS");
                        }
                        GUILayout.EndHorizontal();

                        EditorGUILayout.Space();
                    }
                    if (info.HasVideo())
                    {
                        VideoTracks tracks = videoTracks.GetVideoTracks();
                        if (tracks.Count > 0)
                        {
                            GUILayout.Label("Video Tracks: " + tracks.Count);
                            foreach (VideoTrack track in tracks)
                            {
                                bool isActiveTrack = (track == videoTracks.GetActiveVideoTrack());
                                GUI.color = isActiveTrack?Color.green:Color.white;
                                {
                                    if (GUILayout.Button(track.DisplayName))
                                    {
                                        if (isActiveTrack)
                                        {
                                            videoTracks.SetActiveVideoTrack(null);
                                        }
                                        else
                                        {
                                            videoTracks.SetActiveVideoTrack(track);
                                        }
                                    }
                                }
                            }
                            GUI.color = Color.white;
                            EditorGUILayout.Space();
                        }
                    }
                    if (info.HasAudio())
                    {
                        AudioTracks tracks = audioTracks.GetAudioTracks();
                        if (tracks.Count > 0)
                        {
                            GUILayout.Label("Audio Tracks: " + tracks.Count);
                            foreach (AudioTrack track in tracks)
                            {
                                bool isActiveTrack = (track == audioTracks.GetActiveAudioTrack());
                                GUI.color = isActiveTrack?Color.green:Color.white;
                                {
                                    if (GUILayout.Button(track.DisplayName))
                                    {
                                        if (isActiveTrack)
                                        {
                                            audioTracks.SetActiveAudioTrack(null);
                                        }
                                        else
                                        {
                                            audioTracks.SetActiveAudioTrack(track);
                                        }
                                    }
                                }
                            }
                            GUI.color = Color.white;

                            /*int channelCount = control.GetAudioChannelCount();
                             * if (channelCount > 0)
                             * {
                             *      GUILayout.Label("Audio Channels: " + channelCount);
                             *      AudioChannelMaskFlags audioChannels = control.GetAudioChannelMask();
                             *      GUILayout.Label("(" + audioChannels + ")", EditorHelper.IMGUI.GetWordWrappedTextAreaStyle());
                             * }*/
                            EditorGUILayout.Space();
                        }
                    }
                    {
                        TextTracks tracks = textTracks.GetTextTracks();
                        if (tracks.Count > 0)
                        {
                            GUILayout.Label("Text Tracks: " + tracks.Count);
                            foreach (TextTrack track in tracks)
                            {
                                bool isActiveTrack = (track == textTracks.GetActiveTextTrack());
                                GUI.color = isActiveTrack?Color.green:Color.white;
                                {
                                    if (GUILayout.Button(track.DisplayName))
                                    {
                                        if (isActiveTrack)
                                        {
                                            textTracks.SetActiveTextTrack(null);
                                        }
                                        else
                                        {
                                            textTracks.SetActiveTextTrack(track);
                                        }
                                    }
                                }
                            }
                            GUI.color = Color.white;

                            if (textTracks.GetActiveTextTrack() != null)
                            {
                                string text = string.Empty;
                                if (textTracks.GetCurrentTextCue() != null)
                                {
                                    text = textTracks.GetCurrentTextCue().Text;
                                    // Clip the text if it is too long
                                    if (text.Length >= 96)
                                    {
                                        text = string.Format("{0}...({1} chars)", text.Substring(0, 96), text.Length);
                                    }
                                }
                                GUILayout.Label(text, EditorHelper.IMGUI.GetWordWrappedTextAreaStyle(), GUILayout.Height(48f));
                            }

                            EditorGUILayout.Space();
                        }
                    }
                }
            }
            else
            {
                GUILayout.Label("No media loaded");
            }
        }
        void OnGUI()
        {
            if (Event.current.type == EventType.Layout)
            {
                SetGuiPositionFromVideoIndex(_debugOverlayCount++);
            }

            if (_mediaPlayer != null && _mediaPlayer.Info != null)
            {
                IMediaInfo     info            = _mediaPlayer.Info;
                IMediaControl  control         = _mediaPlayer.Control;
                IMediaProducer textureProducer = _mediaPlayer.TextureProducer;

                GUI.depth  = _guiDepth;
                GUI.matrix = Matrix4x4.TRS(new Vector3(m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(_displaySize, _displaySize, 1.0f));

                GUILayout.BeginVertical("box", GUILayout.MaxWidth(s_GuiWidth));
                GUILayout.Label(System.IO.Path.GetFileName(_mediaPlayer.m_VideoPath));
                GUILayout.Label("Dimensions: " + info.GetVideoWidth() + "x" + info.GetVideoHeight() + "@" + info.GetVideoFrameRate().ToString("F2"));
                GUILayout.Label("Time: " + (control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (info.GetDurationMs() * 0.001f).ToString("F1") + "s");
                GUILayout.Label("Rate: " + info.GetVideoDisplayRate().ToString("F2") + "Hz");

                if (_mediaPlayer.m_Resample && _mediaPlayer.FrameResampler != null)
                {
                    Resampler resampler = _mediaPlayer.FrameResampler;
                    GUILayout.BeginVertical();
                    GUILayout.Label("Resampler Info:");
                    GUILayout.Label("Resampler timestamp: " + resampler.TextureTimeStamp);
                    GUILayout.Label("Resampler frames dropped: " + resampler.DroppedFrames);
                    GUILayout.Label("Resampler frame displayed timer: " + resampler.FrameDisplayedTimer);
                    GUILayout.EndVertical();
                }

                if (textureProducer != null && textureProducer.GetTexture() != null)
                {
#if REAL_ANDROID
                    // In OES mode we can't display the texture without using a special shader, so just don't display it
                    if (!_optionsAndroid.useFastOesPath)
#endif
                    {
                        // Show texture without and with alpha blending
                        GUILayout.BeginHorizontal();
                        Rect r1 = GUILayoutUtility.GetRect(32f, 32f);
                        GUILayout.Space(8f);
                        Rect      r2         = GUILayoutUtility.GetRect(32f, 32f);
                        Matrix4x4 prevMatrix = GUI.matrix;
                        if (textureProducer.RequiresVerticalFlip())
                        {
                            GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, r1.y + (r1.height / 2f)));
                        }
                        GUI.DrawTexture(r1, textureProducer.GetTexture(), ScaleMode.ScaleToFit, false);
                        GUI.DrawTexture(r2, textureProducer.GetTexture(), ScaleMode.ScaleToFit, true);
                        GUI.matrix = prevMatrix;
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }
                }

                if (_displayControls)
                {
                    GUILayout.BeginHorizontal();
                    if (control.IsPaused())
                    {
                        if (GUILayout.Button("Play", GUILayout.Width(50)))
                        {
                            control.Play();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Pause", GUILayout.Width(50)))
                        {
                            control.Pause();
                        }
                    }

                    float duration = info.GetDurationMs();
                    float time     = control.GetCurrentTimeMs();
                    float newTime  = GUILayout.HorizontalSlider(time, 0f, duration);
                    if (newTime != time)
                    {
                        control.Seek(newTime);
                    }
                    GUILayout.EndHorizontal();
                }

#if AVPROVIDEO_DEBUG_DISPLAY_EVENTS
                // Dirty code to hack in an event monitor
                if (Event.current.type == EventType.Repaint)
                {
                    _mediaPlayer.Events.RemoveListener(OnMediaPlayerEvent);
                    _mediaPlayer.Events.AddListener(OnMediaPlayerEvent);
                    UpdateEventLogs();
                }

                if (_eventLog != null && _eventLog.Count > 0)
                {
                    GUILayout.Label("Recent Events: ");
                    GUILayout.BeginVertical("box");
                    int eventIndex = 0;
                    foreach (string eventString in _eventLog)
                    {
                        GUI.color = Color.white;
                        if (eventIndex == 0)
                        {
                            GUI.color = new Color(1f, 1f, 1f, _eventTimer);
                        }
                        GUILayout.Label(eventString);
                        eventIndex++;
                    }
                    GUILayout.EndVertical();
                    GUI.color = Color.white;
                }
#endif
                GUILayout.EndVertical();
            }
        }
Exemplo n.º 10
0
        public void OnGUI()
        {
            if (m_Info != null && m_DebugGui)
            {
                GUI.depth  = s_GuiDepth;
                GUI.matrix = Matrix4x4.TRS(new Vector3(m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(s_GuiScale, s_GuiScale, 1.0f));

                GUILayout.BeginVertical("box", GUILayout.MaxWidth(s_GuiWidth));
                GUILayout.Label(System.IO.Path.GetFileName(m_VideoPath));
                GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + "x" + m_Info.GetVideoHeight() + "@" + m_Info.GetVideoFrameRate().ToString("F2"));
                GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s");
                GUILayout.Label("Rate: " + m_Info.GetVideoDisplayRate().ToString("F2") + "Hz");

                if (TextureProducer != null && TextureProducer.GetTexture() != null)
                {
                    // Show texture without and with alpha blending
                    GUILayout.BeginHorizontal();
                    Rect r1 = GUILayoutUtility.GetRect(32f, 32f);
                    GUILayout.Space(8f);
                    Rect      r2         = GUILayoutUtility.GetRect(32f, 32f);
                    Matrix4x4 prevMatrix = GUI.matrix;
                    if (TextureProducer.RequiresVerticalFlip())
                    {
                        GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, r1.y + (r1.height / 2)));
                    }
                    GUI.DrawTexture(r1, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, false);
                    GUI.DrawTexture(r2, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, true);
                    GUI.matrix = prevMatrix;
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

#if AVPROVIDEO_DEBUG_DISPLAY_EVENTS
                // Dirty code to hack in an event monitor
                if (Event.current.type == EventType.Repaint)
                {
                    this.Events.RemoveListener(OnMediaPlayerEvent);
                    this.Events.AddListener(OnMediaPlayerEvent);
                    UpdateEventLogs();
                }

                if (_eventLog != null && _eventLog.Count > 0)
                {
                    GUILayout.Label("Recent Events: ");
                    GUILayout.BeginVertical("box");
                    int eventIndex = 0;
                    foreach (string eventString in _eventLog)
                    {
                        GUI.color = Color.white;
                        if (eventIndex == 0)
                        {
                            GUI.color = new Color(1f, 1f, 1f, _eventTimer);
                        }
                        GUILayout.Label(eventString);
                        eventIndex++;
                    }
                    GUILayout.EndVertical();
                    GUI.color = Color.white;
                }
#endif
                GUILayout.EndVertical();
            }
        }