int framesValue = 0; //获得视频第几帧的图片....the firstth picture... /// <summary> /// Raises the new frame event. /// 采集第几帧的视,default 10th frame.... /// </summary> /// <param name="source">Source.</param> /// <param name="frameIdx">Frame index.</param> void OnNewFrame(VideoPlayer source, long frameIdx) { framesValue++; if (framesValue == 10) { //Debug.Log ("OnNewFrame====================="); renderTexture = source.texture as RenderTexture; Texture2D videoFrameTexture = new Texture2D(renderTexture.width, renderTexture.height); if (videoFrameTexture.width != renderTexture.width || videoFrameTexture.height != renderTexture.height) { videoFrameTexture.Resize(renderTexture.width, renderTexture.height); } //To modify... RenderTexture.active = renderTexture; videoFrameTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); videoFrameTexture.Apply(); RenderTexture.active = null; //vpPreivew.frameReady -= OnNewFrame; //vpPreivew.sendFrameReadyEvents = false; //for test... ScaleTexture(videoFrameTexture, source.url); Sprite preViewSprite = Sprite.Create(videoFrameTexture, new Rect(0, 0, videoFrameTexture.width, videoFrameTexture.height), new Vector2(0.5f, 0.5f)); PreViewEvent e = new PreViewEvent(source.url, preViewSprite); enqueueToMessageEventQueue(e); AddSprite(source.url, preViewSprite); Log.debug(this, "add sprite source:" + source.url + " preViewSprite:" + preViewSprite.GetHashCode()); //dicSpriteList.Add (source.url, preViewSprite); framesValue = 0; //source.enabled = false; //Test: //imageTest.sprite = PreViewSprite; source.Stop(); } }
private void enqueueToMessageEventQueue(PreViewEvent e) { //lock (_forMessageEventQueue) //coroutine not need lock.. eventQueue.Enqueue(e); }