Search code examples
androidiosvideo-streamingh.264android-mediacodec

Android Mediacodec encode h264 and decode in different platforms (Android,iOS, Web)


I am developing an Android app (min sdk=21) which required to stream real-time video(capture from an Android device camera) to different platform(Android/IOS/web).
I decided to use Media codec to encode the video to h.264 and send the raw data by TCP socket to other devices.

I created an input surface from Media codec and I set the color format to MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface.

Android devices should be able to decode this raw data, but is it possible to decode this raw data in iOS or Web if I choose this color format?


Solution

  • Yes, the input color type shouldn't matter. Even if you use COLOR_FormatSurface, it still is encoded as a normal YUV 4:2:0 video as if you'd use the other, non-surface color formats.

    If you'd manually choose a more uncommon color format like YUV 4:4:4 (when not using surface input), the encoder could either choose to actually downsample this into YUV 4:2:0 (and all decoders would support it) or keep it as is and encode into the more uncommon variants of H264, which not all decoders might be able to decode.