Convert byte[] to VideoFrame or VideoFrame.I420Buffer WebRtc class

Viewed 1395

Is there any method to convert byte[] NV21Data to WebRtc VideoFrame ?

I try to do it with TextureBufferImpl and seems its the only way, but it looks really complex.

YuvConverter yuvConverter = new YuvConverter(); 
TextureBufferImpl buffer = new TextureBufferImpl(composedBitmap.getWidth(), 
composedBitmap.getHeight(),VideoFrame.TextureBuffer.Type.RGB, 
textures[0], new Matrix(), surfaceTextureHelper.getHandler(), yuvConverter, null);


VideoFrame.I420Buffer i420Buf = yuvConverter.convert(buffer);
VideoFrame CONVERTED_FRAME = new VideoFrame(i420Buf, 0, System.nanoTime());

This question has info how to convert VideoFrame to byte[] Android org.webrtc.VideoRenderer.I420Frame arrays to PreviewCallback.onPreviewFrame byte[]

This way gives VideoFrame as black, seems not working as intended.

This question is converting to webRtc VideoFrame from surface Converting a Bitmap to a WebRTC VideoFrame

https://gist.github.com/n1xx1/2cd38043838e259969bce983ce21ffaa

0 Answers
Related