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(); } }
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(); } }
private Texture ExtractFrame(float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000) { Texture result = null; if (m_Control != null) { if (timeSeconds >= 0f) { Pause(); float num = timeSeconds * 1000f; if (TextureProducer.GetTexture() != null && m_Control.GetCurrentTimeMs() == num) { result = TextureProducer.GetTexture(); } else { int textureFrameCount = TextureProducer.GetTextureFrameCount(); if (accurateSeek) { m_Control.Seek(num); } else { m_Control.SeekFast(num); } ForceWaitForNewFrame(textureFrameCount, (float)timeoutMs); result = TextureProducer.GetTexture(); } } else { result = TextureProducer.GetTexture(); } } return result; }
private Texture ExtractFrame(float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000) { Texture result = null; if (m_Control != null) { if (timeSeconds >= 0f) { Pause(); float seekTimeMs = timeSeconds * 1000f; // If the frame is already avaiable just grab it if (TextureProducer.GetTexture() != null && m_Control.GetCurrentTimeMs() == seekTimeMs) { result = TextureProducer.GetTexture(); } else { // Store frame count before seek int frameCount = TextureProducer.GetTextureFrameCount(); // Seek to the frame if (accurateSeek) { m_Control.Seek(seekTimeMs); } else { m_Control.SeekFast(seekTimeMs); } // Wait for frame to change ForceWaitForNewFrame(frameCount, timeoutMs); result = TextureProducer.GetTexture(); } } else { result = TextureProducer.GetTexture(); } } return(result); }
private Texture ExtractFrame(double timeSeconds = -1.0, bool accurateSeek = true, int timeoutMs = 1000, int timeThresholdMs = 100) { Texture result = null; if (_controlInterface != null) { if (timeSeconds >= 0f) { Pause(); // If the right frame is already available (or close enough) just grab it if (TextureProducer.GetTexture() != null && (System.Math.Abs(_controlInterface.GetCurrentTime() - timeSeconds) < (timeThresholdMs / 1000.0))) { result = TextureProducer.GetTexture(); } else { // Store frame count before seek int frameCount = TextureProducer.GetTextureFrameCount(); // Seek to the frame if (accurateSeek) { _controlInterface.Seek(timeSeconds); } else { _controlInterface.SeekFast(timeSeconds); } // Wait for frame to change ForceWaitForNewFrame(frameCount, timeoutMs); result = TextureProducer.GetTexture(); } } else { result = TextureProducer.GetTexture(); } } return(result); }
private IEnumerator ExtractFrameCoroutine(Texture2D target, ProcessExtractedFrame callback, double timeSeconds = -1.0, bool accurateSeek = true, int timeoutMs = 1000, int timeThresholdMs = 100) { #if (!UNITY_EDITOR && UNITY_ANDROID) || UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_IOS || UNITY_TVOS Texture2D result = target; Texture frame = null; if (_controlInterface != null) { if (timeSeconds >= 0f) { Pause(); // If the right frame is already available (or close enough) just grab it if (TextureProducer.GetTexture() != null && (System.Math.Abs(_controlInterface.GetCurrentTime() - timeSeconds) < (timeThresholdMs / 1000.0))) { frame = TextureProducer.GetTexture(); } else { int preSeekFrameCount = _textureInterface.GetTextureFrameCount(); // Seek to the frame if (accurateSeek) { _controlInterface.Seek(timeSeconds); } else { _controlInterface.SeekFast(timeSeconds); } // Wait for the new frame to arrive if (!_controlInterface.WaitForNextFrame(GetDummyCamera(), preSeekFrameCount)) { // If WaitForNextFrame fails (e.g. in android single threaded), we run the below code to asynchronously wait for the frame int currFc = TextureProducer.GetTextureFrameCount(); int iterations = 0; int maxIterations = 50; //+1 as often there will be an extra frame produced after pause (so we need to wait for the second frame instead) while ((currFc + 1) >= TextureProducer.GetTextureFrameCount() && iterations++ < maxIterations) { yield return(null); } } frame = TextureProducer.GetTexture(); } } else { frame = TextureProducer.GetTexture(); } } if (frame != null) { result = Helper.GetReadableTexture(frame, TextureProducer.RequiresVerticalFlip(), Helper.GetOrientation(Info.GetTextureTransform()), target); } #else Texture2D result = ExtractFrame(target, timeSeconds, accurateSeek, timeoutMs, timeThresholdMs); #endif callback(result); yield return(null); }
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(); } }