2
votes

I meet a problem when i try to output a h.264 video with android MediaCodec. I get frame data from onPreviewFrame ,then i feed it to MediaCodec,and draw the frame on GLSurfaceView using OpenGL. it works correctly on some device and OS version such as Samsung s5 with 5.0 system ,Samsung note4 with 5.1 system and some android 4.4 devices.

But when i tried to run this app on other devices such as Samsung s6 with android 6.0 , Samsung note5 with android 6.0 and a 5.0 device,there's something wrong.Image i draw on GLSurfaceViewis correct and normal,but i got the wrong video which seems have no color or have wrong color.

I tried to find the answer and i finally realize that it may caused by the difference of the color format accepted by MediaCodec.In my program,I assumed that mediaCodec can accept YUV420SP,so i convert nv21 i420SemiPlanar and feed it to MediaCodec.i guess color format of mediaCodec is the key to solve problem, but is it true? Why mediaCodec on difference device and os version have such big difference?

Anybody meet the same problem?

What can i do to avoid this problem?

1

1 Answers

1
votes

Firstly, i was a little disappoint about this platform since it still useful and cool. i don't know why my question got -2 points.I show my research and things i know about this problem, how can you guys think it unclear and not useful?

I find the reason why MediaCodec lost color when output a video file.

Android camera output frames with NV21 format as we set when init camera. But MediaCodec on different device(or on different version of android system?) may support different color format. So if we only use the static color format parameter to init MediaCodec, MediaCodec will crash.

As to the the color-missing problem, it caused by my mistake.I loop the MediaCodecInfo.CodecCapabilities of the MediaCodec to catch the supported color format and use the first recognized color format to init mediaCodec.It won't crash, but it may don't match the color format of frames which we prepared to feed MediaCodec.

Android camera may only support NV21,so whatever what you want to do when you get the preview frame,you must design a program which match NV21 format.

Now nothing wrong.I hope my stupid fault can help anyone meet the same problem.