I'm wondering if it's possible to get pixel data from a video frame decoded by ExoPLaye without using any UI-elements(SurfaceView, TextureView etc).
I want to show video frames in a game that contains only one top level GlSurfaceView. And I want to render video frames via regular OpenGL ES texture on my rendering thread instead of main UI thread.
Currently I'm using Xamarin.Android but any ideas for 'pure' Android would be also great!
Here is how I'm trying to reach my goals:
Create video player and its media source
var videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(_bandwidthMeter); _trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); _player = ExoPlayerFactory.NewSimpleInstance(Application.Context, _trackSelector);DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter(); var dataSrcFacroty = new DefaultDataSourceFactory(Application.Context, "blablabla", bandwidthMeterA); var chunkSrcFactory = new DefaultDashChunkSource.Factory(dataSrcFacroty); var mediaSource = new HlsMediaSource(_uri, dataSrcFacroty, 1, null, null);
Create OpenGL ES Texture2D of desired size and format and keep its texName.
GL.Enable(EnableCap.Texture2D); GL.GenTextures(1, _textures); GL.BindTexture(TextureTarget.Texture2D, _textures[0]); GL.TexImage2D( TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Width, Height, 0, OpenTK.Graphics.ES20.PixelFormat.Rgb, PixelType.UnsignedByte, _data); GL.BindTexture(TextureTarget.Texture2D, 0);
- Create SurfaceTexture and Surface from it
var st = new SurfaceTexture(_textures[0], true); _surface = new Surface(st);
- Set created Surface to player, and start it when ready
_player.Prepare(mediaSource); _player.SetVideoSurface(_surface); _player.PlayWhenReady = true;
My player processes video, I hear a sound and can see progress via callbacks attached to it. I suppose that after all my texture should also contain decoded video frame but I see nothing when render it.
Any advices, suggestion and thoughts will be greatly appreciated.