Java Code Examples for android.media.MediaCodecInfo#CodecProfileLevel

The following examples show how to use android.media.MediaCodecInfo#CodecProfileLevel . 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: Utils.java    From ScreenCapture with MIT License 6 votes vote down vote up
/**
 * @param avcProfileLevel AVC CodecProfileLevel
 */
static String avcProfileLevelToString(MediaCodecInfo.CodecProfileLevel avcProfileLevel) {
    if (sAVCProfiles.size() == 0 || sAVCLevels.size() == 0) {
        initProfileLevels();
    }
    String profile = null, level = null;
    int i = sAVCProfiles.indexOfKey(avcProfileLevel.profile);
    if (i >= 0) {
        profile = sAVCProfiles.valueAt(i);
    }

    i = sAVCLevels.indexOfKey(avcProfileLevel.level);
    if (i >= 0) {
        level = sAVCLevels.valueAt(i);
    }

    if (profile == null) {
        profile = String.valueOf(avcProfileLevel.profile);
    }
    if (level == null) {
        level = String.valueOf(avcProfileLevel.level);
    }
    return profile + '-' + level;
}
 
Example 2
Source File: MediaCodecHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * プロファイル・レベルが低ければtrueを返す
 * @param mimeType
 * @param info
 * @return
 */
@Deprecated
public static boolean checkProfileLevel(final String mimeType,
	final MediaCodecInfo info) {

	if (info != null) {
		if (mimeType.equalsIgnoreCase("video/avc")) {
			//noinspection deprecation
			final MediaCodecInfo.CodecCapabilities caps = getCodecCapabilities(info, mimeType);
			final MediaCodecInfo.CodecProfileLevel[] profileLevel = caps.profileLevels;
			for (int j = 0; j < profileLevel.length; j++) {
				if (profileLevel[j].level >= MediaCodecInfo.CodecProfileLevel.AVCLevel5)
					return false;
			}
		}
	}
	return true;
}
 
Example 3
Source File: MediaCodecUtils.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * プロファイル・レベルが低ければtrueを返す
 * @param mimeType
 * @param info
 * @return
 */
public static boolean checkProfileLevel(final String mimeType,
	final MediaCodecInfo info) {

	if (info != null) {
		if (mimeType.equalsIgnoreCase("video/avc")) {
			final MediaCodecInfo.CodecCapabilities caps = getCodecCapabilities(info, mimeType);
			final MediaCodecInfo.CodecProfileLevel[] profileLevel = caps.profileLevels;
			for (int j = 0; j < profileLevel.length; j++) {
				if (profileLevel[j].level >= MediaCodecInfo.CodecProfileLevel.AVCLevel5)
					return false;
			}
		}
	}
	return true;
}
 
Example 4
Source File: VideoUtil.java    From VideoProcessor with Apache License 2.0 6 votes vote down vote up
public static boolean trySetProfileAndLevel(MediaCodec codec, String mime, MediaFormat format, int profileInt, int levelInt) {
    MediaCodecInfo codecInfo = codec.getCodecInfo();
    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mime);
    MediaCodecInfo.CodecProfileLevel[] profileLevels = capabilities.profileLevels;
    if (profileLevels == null) {
        return false;
    }
    for (MediaCodecInfo.CodecProfileLevel level : profileLevels) {
        if (level.profile == profileInt) {
            if (level.level == levelInt) {
                format.setInteger(MediaFormat.KEY_PROFILE, profileInt);
                format.setInteger(MediaFormat.KEY_LEVEL, levelInt);
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: Api16Builder.java    From jellyfin-androidtv with GNU General Public License v2.0 6 votes vote down vote up
private String[] getProfiles(MediaCodecInfo.CodecProfileLevel level){
    switch (level.level) {
        case MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline:
            return new String[]{"constrained baseline", "baseline"};
        case MediaCodecInfo.CodecProfileLevel.AVCProfileExtended:
            return new String[]{"extended"};
        case MediaCodecInfo.CodecProfileLevel.AVCProfileHigh:
            return new String[]{"high"};
        case MediaCodecInfo.CodecProfileLevel.AVCProfileHigh10:
            // TODO: Verify. Maybe high 10?
            return new String[]{"high"};
        case MediaCodecInfo.CodecProfileLevel.AVCProfileHigh422:
            // TODO: Verify
            return new String[]{"high"};
        case MediaCodecInfo.CodecProfileLevel.AVCProfileHigh444:
            // TODO: Verify
            return new String[]{"high"};
        case MediaCodecInfo.CodecProfileLevel.AVCProfileMain:
            return new String[]{"main"};
        default:
            return new String[]{};
    }
}
 
Example 6
Source File: VideoUtils.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
/**
 * @param avcProfileLevel AVC CodecProfileLevel
 */
public static String avcProfileLevelToString(MediaCodecInfo.CodecProfileLevel avcProfileLevel) {
    if (sAVCProfiles.size() == 0 || sAVCLevels.size() == 0) {
        initProfileLevels();
    }
    String profile = null, level = null;
    int i = sAVCProfiles.indexOfKey(avcProfileLevel.profile);
    if (i >= 0) {
        profile = sAVCProfiles.valueAt(i);
    }

    i = sAVCLevels.indexOfKey(avcProfileLevel.level);
    if (i >= 0) {
        level = sAVCLevels.valueAt(i);
    }

    if (profile == null) {
        profile = String.valueOf(avcProfileLevel.profile);
    }
    if (level == null) {
        level = String.valueOf(avcProfileLevel.level);
    }
    return profile + '-' + level;
}
 
Example 7
Source File: ScreenRecordByCodecActivity.java    From ScreenCapture with MIT License 6 votes vote down vote up
private VideoEncodeConfig createVideoConfig() {

        MediaCodecInfo[] mci = Utils.findEncodersByType(VIDEO_AVC);
        for (int i = 0; i < mci.length; i++) {
            MediaCodecInfo info = mci[i];
            Log.d("WOW", info.getName());
        }

        final String codec = mci[0].getName(); //getSelectedVideoCodec();
        if (codec == null) {
            // no selected codec ??
            return null;
        }
        // video size
        int[] selectedWithHeight = new int[]{832, 480};//getSelectedWithHeight();
        boolean isLandscape = false;//isLandscape();
        int width = selectedWithHeight[isLandscape ? 0 : 1];
        int height = selectedWithHeight[isLandscape ? 1 : 0];
        int framerate = 30;//getSelectedFramerate();
        int iframe = 1;//getSelectedIFrameInterval();
        int bitrate = 800;//getSelectedVideoBitrate();
        MediaCodecInfo.CodecProfileLevel profileLevel = null;//getSelectedProfileLevel();
        return new VideoEncodeConfig(width, height, bitrate,
                framerate, iframe, codec, VIDEO_AVC, profileLevel);
    }
 
Example 8
Source File: RecordService.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private VideoEncodeConfig createVideoConfig() {
    final String codec = mCodec;
    if (codec == null) {
        return null;
    }
    int width = mWidth;
    int height = mHeight;
    int framerate = mFrameRate;
    int iframe = 1;
    int bitrate = mBitrate;
    double exceptDiff = mExceptDiff;
    MediaCodecInfo.CodecProfileLevel profileLevel = null;

    return new VideoEncodeConfig(width, height, bitrate,
            framerate, iframe, codec, ScreenRecorder.VIDEO_AVC, profileLevel,exceptDiff);
}
 
Example 9
Source File: SimpleRecordService.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private VideoEncodeConfig createVideoConfig(Intent intent) {
    // 不同系统,不同硬件,codec不一样,无法传递
    MediaCodecInfo[] codecs = VideoUtils.findEncodersByType(ScreenRecorder.VIDEO_AVC);
    if (codecs.length == 0) {
        return null;
    }

    String codec = codecs[0].getName();

    int framerate = intent.getIntExtra(INTENT_FRAME_RATE, 0);
    int bitrate = intent.getIntExtra(INTENT_VIDEO_BITRATE, 0);
    int height = intent.getIntExtra(INTENT_WIDTH, 0);
    int width = intent.getIntExtra(INTENT_HEIGHT, 0);
    double exceptDiff = intent.getDoubleExtra(INTENT_EXCEPT_DIFF, 0);


    int iframe = 1;
    MediaCodecInfo.CodecProfileLevel profileLevel = null;

    return new VideoEncodeConfig(width, height, bitrate,
            framerate, iframe, codec, ScreenRecorder.VIDEO_AVC, profileLevel, exceptDiff);
}
 
Example 10
Source File: VideoEncodeConfig.java    From ScreenCapture with MIT License 5 votes vote down vote up
/**
 * @param codecName         selected codec name, maybe null
 * @param mimeType          video MIME type, cannot be null
 * @param codecProfileLevel profile level for video encoder nullable
 */
public VideoEncodeConfig(@NonNull int width, @NonNull int height, int bitrate,
                         int framerate, int iframeInterval,
                         String codecName, @NonNull String mimeType,
                         MediaCodecInfo.CodecProfileLevel codecProfileLevel) {
    this.width = width;
    this.height = height;
    this.bitrate = bitrate;
    this.framerate = framerate;
    this.iframeInterval = iframeInterval;
    this.codecName = codecName;
    this.mimeType = Objects.requireNonNull(mimeType);
    this.codecProfileLevel = codecProfileLevel;
}
 
Example 11
Source File: Api16Builder.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private String[] GetVideoProfiles(MediaCodecInfo.CodecCapabilities codecCapabilities) {
    ArrayList<String> profiles = new ArrayList<>();

    MediaCodecInfo.CodecProfileLevel[] levels = codecCapabilities.profileLevels;

    for (MediaCodecInfo.CodecProfileLevel level : levels){

        for (String value : getProfiles(level)){
            // Insert at the beginning to put the most complex profile at the front
            profiles.add(0, value);
        }
    }

    return profiles.toArray(new String[profiles.size()]);
}
 
Example 12
Source File: Api16Builder.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private int getMaxLevel(MediaCodecInfo.CodecCapabilities codecCapabilities) {
    MediaCodecInfo.CodecProfileLevel[] levels = codecCapabilities.profileLevels;
    int max = 0;

    for (MediaCodecInfo.CodecProfileLevel level : levels){
        int value = getLevel(level);

        max = Math.max(max, value);
    }

    return max;
}
 
Example 13
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 5 votes vote down vote up
private static void logCodecInfos(MediaCodecInfo[] codecInfos, String mimeType) {
    for (MediaCodecInfo info : codecInfos) {
        StringBuilder builder = new StringBuilder(512);
        MediaCodecInfo.CodecCapabilities caps = info.getCapabilitiesForType(mimeType);
        builder.append("Encoder '").append(info.getName()).append('\'')
                .append("\n  supported : ")
                .append(Arrays.toString(info.getSupportedTypes()));
        MediaCodecInfo.VideoCapabilities videoCaps = caps.getVideoCapabilities();
        if (videoCaps != null) {
            builder.append("\n  Video capabilities:")
                    .append("\n  Widths: ").append(videoCaps.getSupportedWidths())
                    .append("\n  Heights: ").append(videoCaps.getSupportedHeights())
                    .append("\n  Frame Rates: ").append(videoCaps.getSupportedFrameRates())
                    .append("\n  Bitrate: ").append(videoCaps.getBitrateRange());
            if (ScreenRecorder.VIDEO_AVC.equals(mimeType)) {
                MediaCodecInfo.CodecProfileLevel[] levels = caps.profileLevels;

                builder.append("\n  Profile-levels: ");
                for (MediaCodecInfo.CodecProfileLevel level : levels) {
                    builder.append("\n  ").append(VideoUtils.avcProfileLevelToString(level));
                }
            }
            builder.append("\n  Color-formats: ");
            for (int c : caps.colorFormats) {
                builder.append("\n  ").append(VideoUtils.toHumanReadable(c));
            }
        }
        MediaCodecInfo.AudioCapabilities audioCaps = caps.getAudioCapabilities();
        if (audioCaps != null) {
            builder.append("\n Audio capabilities:")
                    .append("\n Sample Rates: ").append(Arrays.toString(audioCaps.getSupportedSampleRates()))
                    .append("\n Bit Rates: ").append(audioCaps.getBitrateRange())
                    .append("\n Max channels: ").append(audioCaps.getMaxInputChannelCount());
        }
        LogUtil.i(TAG, builder.toString());
    }
}
 
Example 14
Source File: Api16Builder.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private int getLevel(MediaCodecInfo.CodecProfileLevel level){
    switch (level.level) {
        case MediaCodecInfo.CodecProfileLevel.AVCLevel1:
            return 1;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel11:
            return 11;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel12:
            return 12;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel13:
            return 13;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel1b:
            // TODO: Verify this
            return 10;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel2:
            return 20;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel21:
            return 21;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel22:
            return 22;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel3:
            return 30;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel31:
            return 31;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel32:
            return 32;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel4:
            return 40;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel41:
            return 41;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel42:
            return 42;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel5:
            return 50;
        case MediaCodecInfo.CodecProfileLevel.AVCLevel51:
            return 51;
        default:
            return 0;
    }
}
 
Example 15
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 16
Source File: VideoEncodeConfig.java    From SoloPi with Apache License 2.0 5 votes vote down vote up
/**
 * @param codecName         selected codec name, maybe null
 * @param mimeType          video MIME type, cannot be null
 * @param codecProfileLevel profile level for video encoder nullable
 */
public VideoEncodeConfig(int width, int height, int bitrate,
                         int framerate, int iframeInterval,
                         String codecName, String mimeType,
                         MediaCodecInfo.CodecProfileLevel codecProfileLevel,double exceptDiff) {
    this.width = width;
    this.height = height;
    this.bitrate = bitrate;
    this.framerate = framerate;
    this.iframeInterval = iframeInterval;
    this.codecName = codecName;
    this.mimeType = Objects.requireNonNull(mimeType);
    this.codecProfileLevel = codecProfileLevel;
    this.exceptDiff = exceptDiff;
}
 
Example 17
Source File: ScreenRecordByCodecActivity.java    From ScreenCapture with MIT License 4 votes vote down vote up
private MediaCodecInfo.CodecProfileLevel getSelectedProfileLevel() {
    return Utils.toProfileLevel("AVCProfileMain-AVCLevel41");
}