Search in sources :

Example 41 with MediaCodecInfo

use of android.media.MediaCodecInfo in project edx-app-android by edx.

the class MediaCodecUtil method isH264ProfileSupported.

/**
 * @param profile An AVC profile constant from {@link CodecProfileLevel}.
 * @param level An AVC profile level from {@link CodecProfileLevel}.
 * @return Whether the specified profile is supported at the specified level.
 */
public static boolean isH264ProfileSupported(int profile, int level) {
    Pair<MediaCodecInfo, CodecCapabilities> info = getMediaCodecInfo(MimeTypes.VIDEO_H264);
    if (info == null) {
        return false;
    }
    CodecCapabilities capabilities = info.second;
    for (int i = 0; i < capabilities.profileLevels.length; i++) {
        CodecProfileLevel profileLevel = capabilities.profileLevels[i];
        if (profileLevel.profile == profile && profileLevel.level >= level) {
            return true;
        }
    }
    return false;
}
Also used : CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities)

Example 42 with MediaCodecInfo

use of android.media.MediaCodecInfo in project edx-app-android by edx.

the class MediaCodecUtil method maxH264DecodableFrameSize.

/**
 * @return the maximum frame size for an H264 stream that can be decoded on the device.
 */
public static int maxH264DecodableFrameSize() {
    Pair<MediaCodecInfo, CodecCapabilities> info = getMediaCodecInfo(MimeTypes.VIDEO_H264);
    if (info == null) {
        return 0;
    }
    int maxH264DecodableFrameSize = 0;
    CodecCapabilities capabilities = info.second;
    for (int i = 0; i < capabilities.profileLevels.length; i++) {
        CodecProfileLevel profileLevel = capabilities.profileLevels[i];
        maxH264DecodableFrameSize = Math.max(avcLevelToMaxFrameSize(profileLevel.level), maxH264DecodableFrameSize);
    }
    return maxH264DecodableFrameSize;
}
Also used : CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities)

Example 43 with MediaCodecInfo

use of android.media.MediaCodecInfo in project LanSoEditor_advance by LanSoSdk.

the class VideoEditor method isSupportNV21ColorFormat.

public static boolean isSupportNV21ColorFormat() {
    if (isSupportNV21) {
        return true;
    }
    MediaCodecInfo codecInfo = selectCodec(MIME_TYPE_AVC);
    if (codecInfo == null) {
        return false;
    }
    isSupportNV21 = selectColorFormat(codecInfo, MIME_TYPE_AVC);
    return isSupportNV21;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo)

Example 44 with MediaCodecInfo

use of android.media.MediaCodecInfo in project LanSoEditor_advance by LanSoSdk.

the class VideoEditor method selectCodec.

private static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo)

Example 45 with MediaCodecInfo

use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.

the class SettingsManager method getSupportedVideoSize.

private List<String> getSupportedVideoSize(int cameraId) {
    StreamConfigurationMap map = mCharacteristics.get(cameraId).get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] sizes = map.getOutputSizes(MediaRecorder.class);
    boolean isHeifEnabled = getSavePictureFormat() == HEIF_FORMAT;
    VideoCapabilities heifCap = null;
    if (isHeifEnabled) {
        MediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        for (MediaCodecInfo info : list.getCodecInfos()) {
            if (info.isEncoder() && info.getName().contains("heic")) {
                heifCap = info.getCapabilitiesForType(MediaFormat.MIMETYPE_IMAGE_ANDROID_HEIC).getVideoCapabilities();
                Log.d(TAG, "supported heif height range =" + heifCap.getSupportedHeights().toString() + " width range =" + heifCap.getSupportedWidths().toString());
            }
        }
    }
    List<String> res = new ArrayList<>();
    for (int i = 0; i < sizes.length; i++) {
        if (isHeifEnabled && heifCap != null) {
            if (!heifCap.getSupportedWidths().contains(sizes[i].getWidth()) || !heifCap.getSupportedHeights().contains(sizes[i].getHeight())) {
                continue;
            }
        }
        if (CameraSettings.VIDEO_QUALITY_TABLE.containsKey(sizes[i].toString())) {
            Integer profile = CameraSettings.VIDEO_QUALITY_TABLE.get(sizes[i].toString());
            if (profile != null && CamcorderProfile.hasProfile(cameraId, profile)) {
                res.add(sizes[i].toString());
            }
        }
    }
    return res;
}
Also used : Size(android.util.Size) MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) ArrayList(java.util.ArrayList) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) VideoCapabilities(android.media.MediaCodecInfo.VideoCapabilities) Point(android.graphics.Point)

Aggregations

MediaCodecInfo (android.media.MediaCodecInfo)108 ArrayList (java.util.ArrayList)33 MediaCodecList (android.media.MediaCodecList)22 SuppressLint (android.annotation.SuppressLint)20 MediaFormat (android.media.MediaFormat)17 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)15 IOException (java.io.IOException)14 TargetApi (android.annotation.TargetApi)10 Point (android.graphics.Point)9 VideoCapabilities (android.media.MediaCodecInfo.VideoCapabilities)6 Size (android.util.Size)6 Nullable (androidx.annotation.Nullable)6 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 Config (org.robolectric.annotation.Config)5 SparseIntArray (android.util.SparseIntArray)4 NonNull (androidx.annotation.NonNull)4 TreeMap (java.util.TreeMap)4 MediaCodec (android.media.MediaCodec)3 Bundle (android.os.Bundle)3