Java tutorial
//package com.java2s; import android.graphics.ImageFormat; import android.media.MediaCodecInfo; import android.os.Build; public class Main { public static int getEncoderColorFormat(int previewFormat) { if (Build.VERSION.SDK_INT >= 21) { return MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Flexible; } switch (previewFormat) { case ImageFormat.NV21: return MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar; case ImageFormat.YV12: return MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar; } return -1; } }