Java Code Examples for android.media.MediaCodecList#getCodecInfos()

The following examples show how to use android.media.MediaCodecList#getCodecInfos() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaVideoEncoder.java    From GPUVideo-android with MIT License 6 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 *
 * @param mimeType
 * @return null if no codec matched
 */
private static MediaCodecInfo selectVideoCodec(final String mimeType) {
    Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] codecInfos = list.getCodecInfos();

    final int numCodecs = codecInfos.length;
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = codecInfos[i];

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
 
Example 2
Source File: VideoUtils.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
/**
 * Find an encoder supported specified MIME type
 *
 * @return Returns empty array if not found any encoder supported specified MIME type
 */
public static MediaCodecInfo[] findEncodersByType(String mimeType) {
    MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    List<MediaCodecInfo> infos = new ArrayList<>();
    for (MediaCodecInfo info : codecList.getCodecInfos()) {
        if (!info.isEncoder()) {
            continue;
        }
        try {
            MediaCodecInfo.CodecCapabilities cap = info.getCapabilitiesForType(mimeType);
            if (cap == null) continue;
        } catch (IllegalArgumentException e) {
            // unsupported
            continue;
        }
        infos.add(info);
    }

    return infos.toArray(new MediaCodecInfo[infos.size()]);
}
 
Example 3
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@NonNull
public static String getAvcDecoderCapabilities(@NonNull Context context) {
    StringBuilder codecListStr = new StringBuilder();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        for (MediaCodecInfo mediaCodecInfo: mediaCodecList.getCodecInfos()) {
            String codecName = mediaCodecInfo.getName().toLowerCase(Locale.ROOT); {
                if ((codecName.contains(TYPE_AVC) || codecName.contains(TYPE_H264)) && codecName.contains(TYPE_DECODER)) {
                    codecListStr.append(printCodecCapabilities(context, mediaCodecInfo));
                }
            }
        }
    }

    return codecListStr.toString();
}
 
Example 4
Source File: Utils.java    From ScreenCapture with MIT License 6 votes vote down vote up
/**
 * Find an encoder supported specified MIME type
 *
 * @return Returns empty array if not found any encoder supported specified MIME type
 */
public static MediaCodecInfo[] findEncodersByType(String mimeType) {
    MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    List<MediaCodecInfo> infos = new ArrayList<>();
    for (MediaCodecInfo info : codecList.getCodecInfos()) {
        if (!info.isEncoder()) {
            continue;
        }
        try {
            MediaCodecInfo.CodecCapabilities cap = info.getCapabilitiesForType(mimeType);
            if (cap == null) continue;
        } catch (IllegalArgumentException e) {
            // unsupported
            continue;
        }
        infos.add(info);
    }

    return infos.toArray(new MediaCodecInfo[infos.size()]);
}
 
Example 5
Source File: AudioUtils.java    From AlexaAndroid with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(MediaFormatFactory.Type.FLAC, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                if (info.getName().equals(encoderAsStr)) {
                    encoders.add("*** " + info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                } else {
                    encoders.add(info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                }
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
 
Example 6
Source File: AudioUtils.java    From AlexaAndroid with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(MediaFormatFactory.Type.FLAC, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                if (info.getName().equals(encoderAsStr)) {
                    encoders.add("*** " + info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                } else {
                    encoders.add(info.getName() + ": " + TextUtils.join(", ", info.getSupportedTypes()));
                }
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
 
Example 7
Source File: AudioUtils.java    From speechutils with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(String mime, int sampleRate) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaFormat format = MediaFormatFactory.createMediaFormat(mime, sampleRate);
        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        String encoderAsStr = mcl.findEncoderForFormat(format);
        List<String> encoders = new ArrayList<>();
        for (MediaCodecInfo info : mcl.getCodecInfos()) {
            if (info.isEncoder()) {
                String name = info.getName();
                String infoAsStr = name + ": " + TextUtils.join(", ", info.getSupportedTypes());
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                    infoAsStr += String.format(": %s/%s/%s/%s", info.isHardwareAccelerated(), info.isSoftwareOnly(), info.isAlias(), info.isVendor());
                }
                if (name.equals(encoderAsStr)) {
                    infoAsStr = '#' + infoAsStr;
                }
                encoders.add(infoAsStr);
            }
        }
        return encoders;
    }
    return Collections.emptyList();
}
 
Example 8
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NonNull
public static String getCodecList() {
    StringBuilder codecListStr = new StringBuilder();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        for (MediaCodecInfo mediaCodecInfo: mediaCodecList.getCodecInfos()) {
            codecListStr.append(mediaCodecInfo.getName());
            codecListStr.append('\n');
        }
    }

    return codecListStr.toString();
}
 
Example 9
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NonNull
public static String getAvcEncoderCapabilities(@NonNull Context context) {
    StringBuilder codecListStr = new StringBuilder();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        for (MediaCodecInfo mediaCodecInfo : mediaCodecList.getCodecInfos()) {
            String codecName = mediaCodecInfo.getName().toLowerCase(Locale.ROOT);
            if ((codecName.contains(TYPE_AVC) || codecName.contains(TYPE_H264)) && codecName.contains(TYPE_ENCODER)) {
                codecListStr.append(printCodecCapabilities(context, mediaCodecInfo));
            }
        }
    }

    return codecListStr.toString();
}
 
Example 10
Source File: MediaCodecCapabilitiesTest.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private boolean supports(
        String mime, boolean isEncoder, int profile, int level) {
    MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
    for (MediaCodecInfo info : mcl.getCodecInfos()) {
        if (isEncoder != info.isEncoder()) {
            continue;
        }
        try {
            MediaCodecInfo.CodecCapabilities caps = info.getCapabilitiesForType(mime);
            for (MediaCodecInfo.CodecProfileLevel pl : caps.profileLevels) {
                if (pl.profile != profile) {
                    continue;
                }
                // H.263 levels are not completely ordered:
                // Level45 support only implies Level10 support
                if (mime.equalsIgnoreCase(MIMETYPE_VIDEO_H263)) {
                    if (pl.level != level && pl.level == H263Level45 && level > H263Level10) {
                        continue;
                    }
                }
                if (pl.level >= level) {
                    return true;
                }
            }
        } catch (IllegalArgumentException e) {
            Timber.e(e);
        }
    }
    return false;
}
 
Example 11
Source File: MediaVideoEncoder.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 *
 * @param mimeType
 * @return null if no codec matched
 */
private static MediaCodecInfo selectVideoCodec(final String mimeType) {
    Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] codecInfos = list.getCodecInfos();

    final int numCodecs = codecInfos.length;
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = codecInfos[i];

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
 
Example 12
Source File: CodecUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public static List<MediaCodecInfo> getAllCodecs(boolean filterBroken) {
  List<MediaCodecInfo> mediaCodecInfoList = new ArrayList<>();
  if (Build.VERSION.SDK_INT >= 21) {
    MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] mediaCodecInfos = mediaCodecList.getCodecInfos();
    mediaCodecInfoList.addAll(Arrays.asList(mediaCodecInfos));
  } else {
    int count = MediaCodecList.getCodecCount();
    for (int i = 0; i < count; i++) {
      MediaCodecInfo mci = MediaCodecList.getCodecInfoAt(i);
      mediaCodecInfoList.add(mci);
    }
  }
  return filterBroken ? filterBrokenCodecs(mediaCodecInfoList) : mediaCodecInfoList;
}