Java Code Examples for android.media.MediaCodecInfo#VideoCapabilities

The following examples show how to use android.media.MediaCodecInfo#VideoCapabilities . 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: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private void onResolutionChanged(int selectedPosition, String resolution) {
    String codecName = getSelectedVideoCodec();
    MediaCodecInfo codec = getVideoCodecInfo(codecName);
    if (codec == null) return;
    MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
    MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
    String[] xes = resolution.split("x");
    if (xes.length != 2) throw new IllegalArgumentException();
    int width = Integer.parseInt(xes[1]);
    int height = Integer.parseInt(xes[0]);

    double selectedFramerate = getSelectedFramerate();
    int resetPos = Math.max(selectedPosition - 1, 0);
    if (!videoCapabilities.isSizeSupported(width, height)) {
        mVideoResolution.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_size,
                codecName, width, height));
        LogUtil.w(TAG, codecName +
                " height range: " + videoCapabilities.getSupportedHeights() +
                "\n width range: " + videoCapabilities.getSupportedHeights());
    } else if (!videoCapabilities.areSizeAndRateSupported(width, height, selectedFramerate)) {
        mVideoResolution.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_size_framerate,
                codecName, width, height, (int) selectedFramerate));
    }
}
 
Example 2
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private void onBitrateChanged(int selectedPosition, String bitrate) {
    String codecName = getSelectedVideoCodec();
    MediaCodecInfo codec = getVideoCodecInfo(codecName);
    if (codec == null) return;
    MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
    MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
    int selectedBitrate = Integer.parseInt(bitrate) * 1000;

    int resetPos = Math.max(selectedPosition - 1, 0);
    if (!videoCapabilities.getBitrateRange().contains(selectedBitrate)) {
        mVideoBitrate.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_bitrate, codecName, selectedBitrate));
        LogUtil.w(TAG, codecName +
                " bitrate range: " + videoCapabilities.getBitrateRange());
    }
}
 
Example 3
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private void onFramerateChanged(int selectedPosition, String rate) {
    String codecName = getSelectedVideoCodec();
    MediaCodecInfo codec = getVideoCodecInfo(codecName);
    if (codec == null) return;
    MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
    MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
    int[] selectedWithHeight = getSelectedWidthHeight();
    int selectedFramerate = Integer.parseInt(rate);
    int width = selectedWithHeight[1];
    int height = selectedWithHeight[0];

    int resetPos = Math.max(selectedPosition - 1, 0);
    if (!videoCapabilities.getSupportedFrameRates().contains(selectedFramerate)) {
        mVideoFrameRate.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_framerate, codecName, selectedFramerate));
    } else if (!videoCapabilities.areSizeAndRateSupported(width, height, selectedFramerate)) {
        mVideoFrameRate.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_size_framerate,
                codecName, width, height, selectedFramerate));
    }
}
 
Example 4
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 5
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NonNull
private static String printCodecCapabilities(@NonNull Context context, @NonNull MediaCodecInfo mediaCodecInfo) {
    StringBuilder codecCapabilitiesStr = new StringBuilder();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        codecCapabilitiesStr.append(mediaCodecInfo.getName());
        codecCapabilitiesStr.append('\n');

        String[] supportedTypes = mediaCodecInfo.getSupportedTypes();
        for (String supportedType : supportedTypes) {
            MediaCodecInfo.CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(supportedType);
            codecCapabilitiesStr.append(context.getString(R.string.supported_mime_type, codecCapabilities.getMimeType()));

            codecCapabilitiesStr.append(context.getString(R.string.color_formats));
            for (int colorFormat : codecCapabilities.colorFormats) {
                codecCapabilitiesStr.append('\t');
                codecCapabilitiesStr.append(getColorFormat(colorFormat));
                codecCapabilitiesStr.append('\n');
            }

            if (mediaCodecInfo.isEncoder()) {
                MediaCodecInfo.EncoderCapabilities encoderCapabilities = codecCapabilities.getEncoderCapabilities();
                codecCapabilitiesStr.append(context.getString(R.string.encoder_complexity_range, encoderCapabilities.getComplexityRange()));
            }

            MediaCodecInfo.VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
            codecCapabilitiesStr.append(context.getString(R.string.bitrate_range, videoCapabilities.getBitrateRange()));
            codecCapabilitiesStr.append(context.getString(R.string.supported_heights, videoCapabilities.getSupportedHeights()));
            codecCapabilitiesStr.append(context.getString(R.string.supported_widths, videoCapabilities.getSupportedWidths()));
            codecCapabilitiesStr.append(context.getString(R.string.supported_frame_rates, videoCapabilities.getSupportedFrameRates()));
        }
        codecCapabilitiesStr.append('\n');
    }

    return codecCapabilitiesStr.toString();
}
 
Example 6
Source File: Api21Builder.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private void addVideoCapabilities(MediaCodecInfo.CodecCapabilities codecCapabilities, CodecProfile profile) {
    MediaCodecInfo.VideoCapabilities videoCaps = codecCapabilities.getVideoCapabilities();

    ArrayList<ProfileCondition> conditions = new ArrayList<>();

    conditions.add(new ProfileCondition(ProfileConditionType.NotEquals, ProfileConditionValue.IsAnamorphic, "true"));

    if (profile.getCodec() != null && profile.getCodec().toLowerCase().contains(CodecTypes.H264)) {
        conditions.add(new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.VideoBitDepth, "8"));
    }

    // Video max bitrate
    Range<Integer> bitrateRange = videoCaps.getBitrateRange();
    String maxBitrate = String.valueOf(bitrateRange.getUpper());
    conditions.add(new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.VideoBitrate, maxBitrate));

    // Video min bitrate
    String minBitrate = String.valueOf(bitrateRange.getLower());
    conditions.add(new ProfileCondition(ProfileConditionType.GreaterThanEqual, ProfileConditionValue.VideoBitrate, minBitrate));

    // Video max height
    Range<Integer> heightRange = videoCaps.getSupportedHeights();
    String maxHeight = String.valueOf(heightRange.getUpper());
    //conditions.add(new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Height, maxHeight));

    // Video min height
    String minHeight = String.valueOf(heightRange.getLower());
    conditions.add(new ProfileCondition(ProfileConditionType.GreaterThanEqual, ProfileConditionValue.Height, minHeight));

    // Video max width
    Range<Integer> widthRange = videoCaps.getSupportedHeights();
    conditions.add(new ProfileCondition(ProfileConditionType.LessThanEqual, ProfileConditionValue.Width, String.valueOf(widthRange.getUpper())));

    // Video min width
    conditions.add(new ProfileCondition(ProfileConditionType.GreaterThanEqual, ProfileConditionValue.Width, String.valueOf(widthRange.getLower())));

    profile.setConditions(conditions.toArray(new ProfileCondition[conditions.size()]));

    AddProfileLevels(codecCapabilities, profile);
}
 
Example 7
Source File: HeifReader.java    From heifreader with MIT License 5 votes vote down vote up
/**
 * Initialize HeifReader module.
 *
 * @param context Context.
 */
public static void initialize(Context context) {
    mRenderScript = RenderScript.create(context);
    mCacheDir = context.getCacheDir();

    // find best HEVC decoder
    mDecoderName = null;
    mDecoderSupportedSize = new Size(0, 0);
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (codecInfo.isEncoder()) {
            continue;
        }
        for (String type : codecInfo.getSupportedTypes()) {
            if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
                MediaCodecInfo.CodecCapabilities cap = codecInfo.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_HEVC);
                MediaCodecInfo.VideoCapabilities vcap = cap.getVideoCapabilities();
                Size supportedSize = new Size(vcap.getSupportedWidths().getUpper(), vcap.getSupportedHeights().getUpper());
                Log.d(TAG, "HEVC decoder=\"" + codecInfo.getName() + "\""
                        + " supported-size=" + supportedSize
                        + " color-formats=" + Arrays.toString(cap.colorFormats)
                );
                if (mDecoderSupportedSize.getWidth() * mDecoderSupportedSize.getHeight() < supportedSize.getWidth() * supportedSize.getHeight()) {
                    mDecoderName = codecInfo.getName();
                    mDecoderSupportedSize = supportedSize;
                }
            }
        }
    }
    if (mDecoderName == null) {
        throw new RuntimeException("no HEVC decoding support");
    }
    Log.i(TAG, "HEVC decoder=\"" + mDecoderName + "\" supported-size=" + mDecoderSupportedSize);
}
 
Example 8
Source File: VideoEncoder.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private void printCodecInfo(MediaCodecInfo codecInfo) {
    Log.i(TAG, "CODEC: " + codecInfo.getName());

    String[] types = codecInfo.getSupportedTypes();
    for (String type : types) {
        if (!type.startsWith("video/")) {
            continue;
        }

        try {
            Log.i(TAG, "  TYPE: " + type);
            MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(type);
            for (int k = 0; k < capabilities.colorFormats.length; k++) {
                int format = capabilities.colorFormats[k];
                Log.i(TAG, "   FORMAT: " + format);
            }

            MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
            if (videoCapabilities != null) {
                Log.i(TAG, "    ----");
                Log.i(TAG, "    Bitrate range: "
                        + videoCapabilities.getBitrateRange().getLower()
                        + " - "
                        + videoCapabilities.getBitrateRange().getUpper());
                Log.i(TAG, "    Frame rate range: "
                        + videoCapabilities.getSupportedFrameRates().getLower()
                        + " - "
                        + videoCapabilities.getSupportedFrameRates().getUpper());
                Log.i(TAG, "    Width range: "
                        + videoCapabilities.getSupportedWidths().getLower()
                        + " - "
                        + videoCapabilities.getSupportedWidths().getUpper());
                Log.i(TAG, "    Height range: "
                        + videoCapabilities.getSupportedHeights().getLower()
                        + " - "
                        + videoCapabilities.getSupportedHeights().getUpper());
                Log.i(TAG, "    ----");
            }
        } catch (Exception e) {
            // ignore.
        }
    }
}