public Texture2D ExtractFrame(Texture2D target, float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000) { Texture2D result = target; Texture texture = ExtractFrame(timeSeconds, accurateSeek, timeoutMs); if (texture != null) { result = Helper.GetReadableTexture(texture, TextureProducer.RequiresVerticalFlip(), target); } return result; }
// "target" can be null or you can pass in an existing texture. public Texture2D ExtractFrame(Texture2D target, float timeSeconds = -1f, bool accurateSeek = true, int timeoutMs = 1000) { Texture2D result = target; // Extract frames returns the interal frame of the video player Texture frame = ExtractFrame(timeSeconds, accurateSeek, timeoutMs); if (frame != null) { result = Helper.GetReadableTexture(frame, TextureProducer.RequiresVerticalFlip(), target); } return result; }
// "target" can be null or you can pass in an existing texture. public Texture2D ExtractFrame(Texture2D target, double timeSeconds = -1.0, bool accurateSeek = true, int timeoutMs = 1000, int timeThresholdMs = 100) { Texture2D result = target; // Extract frames returns the internal frame of the video player Texture frame = ExtractFrame(timeSeconds, accurateSeek, timeoutMs, timeThresholdMs); if (frame != null) { result = Helper.GetReadableTexture(frame, TextureProducer.RequiresVerticalFlip(), Helper.GetOrientation(Info.GetTextureTransform()), target); } 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); }