本文整理汇总了Java中android.media.MediaCodecInfo.getCapabilitiesForType方法的典型用法代码示例。如果您正苦于以下问题:Java MediaCodecInfo.getCapabilitiesForType方法的具体用法?Java MediaCodecInfo.getCapabilitiesForType怎么用?Java MediaCodecInfo.getCapabilitiesForType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaCodecInfo
的用法示例。
在下文中一共展示了MediaCodecInfo.getCapabilitiesForType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
/**
* 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);
}
示例2: selectColorFormat
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
/**
* select color format available on specific codec and we can use.
* @return 0 if no colorFormat is matched
*/
protected static final int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
if (DEBUG) Log.i(TAG, "selectColorFormat: ");
int result = 0;
final MediaCodecInfo.CodecCapabilities caps;
try {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
caps = codecInfo.getCapabilitiesForType(mimeType);
} finally {
Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
}
int colorFormat;
for (int i = 0; i < caps.colorFormats.length; i++) {
colorFormat = caps.colorFormats[i];
if (isRecognizedViewoFormat(colorFormat)) {
if (result == 0)
result = colorFormat;
break;
}
}
if (result == 0)
Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
return result;
}
示例3: selectColorFormat
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
private static int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
int result = 0;
final MediaCodecInfo.CodecCapabilities caps;
try {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
caps = codecInfo.getCapabilitiesForType(mimeType);
} finally {
Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
}
for (int colorFormat : caps.colorFormats) {
if (isRecognizedVideoFormat(colorFormat)) {
result = colorFormat;
break;
}
}
if (result == 0) {
Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
}
return result;
}
示例4: selectColorFormat
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
/**
* select color format available on specific codec and we can use.
*
* @return 0 if no colorFormat is matched
*/
protected static final int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
if (DEBUG) Log.i(TAG, "selectColorFormat: ");
int result = 0;
final MediaCodecInfo.CodecCapabilities caps;
try {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
caps = codecInfo.getCapabilitiesForType(mimeType);
} finally {
Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
}
int colorFormat;
for (int i = 0; i < caps.colorFormats.length; i++) {
colorFormat = caps.colorFormats[i];
if (isRecognizedViewoFormat(colorFormat)) {
if (result == 0)
result = colorFormat;
break;
}
}
if (result == 0)
Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
return result;
}
示例5: selectColorFormat
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
int lastColorFormat = 0;
for (int i = 0; i < capabilities.colorFormats.length; i++) {
int colorFormat = capabilities.colorFormats[i];
if (isRecognizedFormat(colorFormat)) {
lastColorFormat = colorFormat;
if (!(codecInfo.getName().equals("OMX.SEC.AVC.Encoder") && colorFormat == 19)) {
return colorFormat;
}
}
}
return lastColorFormat;
}
示例6: getAVCLevel
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
public static int getAVCLevel() {
int maxAVCLevel = 0;
if (VERSION.SDK_INT >= 16) {
int mediaCodecListCount = MediaCodecList.getCodecCount();
for (int i = 0; i < mediaCodecListCount; i++) {
MediaCodecInfo mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
if (!(mediaCodecInfo.isEncoder() || mediaCodecInfo.getName().startsWith("OMX.google") || mediaCodecInfo.getName().startsWith("OMX.TI."))) {
Log.d(LOG_TAG, "getAVCLevel()->name:" + mediaCodecInfo.getName());
for (String type : mediaCodecInfo.getSupportedTypes()) {
if (type.contains("avc")) {
Log.d(LOG_TAG, "getAVCLevel()->type:" + type);
try {
CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(type);
for (int colorFormat : codecCapabilities.colorFormats) {
Log.d(LOG_TAG, "getAVCLevel()->Color Format: " + colorFormat + " " + colorFormatToString(colorFormat));
}
for (CodecProfileLevel codecProfileLevel : codecCapabilities.profileLevels) {
String level = "unknown type";
String sprofile = "unknown type";
Log.d(LOG_TAG, "getAVCLevel()->Codec Profile Level:" + avcLevelToString(codecProfileLevel.level) + " profile:" + avcProfileToString(codecProfileLevel.profile));
if (codecProfileLevel.level > maxAVCLevel) {
maxAVCLevel = codecProfileLevel.level;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Log.d(LOG_TAG, "getAVCLevel()->Max AVCLevel:" + maxAVCLevel + " " + avcProfileToString(maxAVCLevel));
}
return maxAVCLevel;
}
示例7: getProfile
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
public static int getProfile() {
int maxProfile = 0;
Log.d(LOG_TAG, "getProfile()->Build.VERSION.SDK_INT:" + String.valueOf(VERSION.SDK_INT));
if (VERSION.SDK_INT >= 16) {
int mediaCodecListCount = MediaCodecList.getCodecCount();
for (int i = 0; i < mediaCodecListCount; i++) {
MediaCodecInfo mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
if (!(mediaCodecInfo.isEncoder() || mediaCodecInfo.getName().startsWith("OMX.google") || mediaCodecInfo.getName().startsWith("OMX.TI."))) {
Log.d(LOG_TAG, "getProfile()->name:" + mediaCodecInfo.getName());
for (String type : mediaCodecInfo.getSupportedTypes()) {
if (type.contains("avc")) {
Log.d(LOG_TAG, "getProfile()->type:" + type);
try {
CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(type);
for (int colorFormat : codecCapabilities.colorFormats) {
Log.d(LOG_TAG, "getProfile()->Color Format: " + colorFormat + " " + colorFormatToString(colorFormat));
}
for (CodecProfileLevel codecProfileLevel : codecCapabilities.profileLevels) {
String level = "unknown type";
String sprofile = "unknown type";
Log.d(LOG_TAG, "getProfile()->Codec Profile Level:" + avcLevelToString(codecProfileLevel.level) + " profile:" + avcProfileToString(codecProfileLevel.profile));
if (codecProfileLevel.profile > maxProfile) {
maxProfile = codecProfileLevel.profile;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Log.d(LOG_TAG, "getProfile()->Max profile:" + maxProfile + " " + avcProfileToString(maxProfile));
}
return maxProfile;
}
示例8: chooseColorDynamically
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
private FormatVideoEncoder chooseColorDynamically(MediaCodecInfo mediaCodecInfo) {
for (int color : mediaCodecInfo.getCapabilitiesForType(mime).colorFormats) {
if (color == FormatVideoEncoder.YUV420PLANAR.getFormatCodec()) {
return FormatVideoEncoder.YUV420PLANAR;
} else if (color == FormatVideoEncoder.YUV420SEMIPLANAR.getFormatCodec()) {
return FormatVideoEncoder.YUV420SEMIPLANAR;
} else if (color == FormatVideoEncoder.YUV420PACKEDPLANAR.getFormatCodec()) {
return FormatVideoEncoder.YUV420PACKEDPLANAR;
}
}
return null;
}
示例9: chooseVideoEncoderAPI21
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
/**
* choose the video encoder by mime. API 21+
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private MediaCodecInfo chooseVideoEncoderAPI21(String mime) {
MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
MediaCodecInfo[] mediaCodecInfos = mediaCodecList.getCodecInfos();
for (MediaCodecInfo mci : mediaCodecInfos) {
if (!mci.isEncoder()) {
continue;
}
String[] types = mci.getSupportedTypes();
for (String type : types) {
if (type.equalsIgnoreCase(mime)) {
Log.i(TAG, String.format("videoEncoder %s type supported: %s", mci.getName(), type));
MediaCodecInfo.CodecCapabilities codecCapabilities = mci.getCapabilitiesForType(mime);
for (int color : codecCapabilities.colorFormats) {
Log.i(TAG, "Color supported: " + color);
//check if encoder support any yuv420 color
if (color == FormatVideoEncoder.YUV420PLANAR.getFormatCodec()
|| color == FormatVideoEncoder.YUV420SEMIPLANAR.getFormatCodec()
|| color == FormatVideoEncoder.YUV420PACKEDPLANAR.getFormatCodec()) {
return mci;
}
}
}
}
}
return null;
}
示例10: chooseVideoEncoder
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
/**
* choose the video encoder by mime. API < 21
*/
private MediaCodecInfo chooseVideoEncoder(String mime) {
int count = MediaCodecList.getCodecCount();
for (int i = 0; i < count; i++) {
MediaCodecInfo mci = MediaCodecList.getCodecInfoAt(i);
if (!mci.isEncoder()) {
continue;
}
String[] types = mci.getSupportedTypes();
for (String type : types) {
if (type.equalsIgnoreCase(mime)) {
Log.i(TAG, String.format("videoEncoder %s type supported: %s", mci.getName(), type));
MediaCodecInfo.CodecCapabilities codecCapabilities = mci.getCapabilitiesForType(mime);
for (int color : codecCapabilities.colorFormats) {
Log.i(TAG, "Color supported: " + color);
//check if encoder support any yuv420 color
if (color == FormatVideoEncoder.YUV420PLANAR.getFormatCodec()
|| color == FormatVideoEncoder.YUV420SEMIPLANAR.getFormatCodec()
|| color == FormatVideoEncoder.YUV420PACKEDPLANAR.getFormatCodec()) {
return mci;
}
}
}
}
}
return null;
}
示例11: createDecoder
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
@Override
public VideoDecoder createDecoder(String codecType) {
VideoCodecType type = VideoCodecType.valueOf(codecType);
MediaCodecInfo info = findCodecForType(type);
if (info == null) {
return null; // No support for this codec type.
}
CodecCapabilities capabilities = info.getCapabilitiesForType(type.mimeType());
return new HardwareVideoDecoder(info.getName(), type,
MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS, capabilities),
sharedContext);
}
示例12: getEncodVieoeCapability
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
public static EncodeVideoCapability getEncodVieoeCapability(MediaCodec mediaCodec, String mime)
{
if( mediaCodec == null || Build.VERSION.SDK_INT < 18) {
return null;
}
EncodeVideoCapability retCapability = new EncodeVideoCapability();
//String mime = mEncodeFormat.getValue();
MediaCodecInfo codecInfo = mediaCodec.getCodecInfo();
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mime);
int[] deviceColor = capabilities.colorFormats;
retCapability.colorFormat = deviceColor;
MediaCodecInfo.CodecProfileLevel[] profileLevels = capabilities.profileLevels;
if(null != profileLevels)
{
retCapability.profileLevel = new EncodeVideoCapability.ProfileLevel[profileLevels.length];
for(int i = 0; i < profileLevels.length; ++i)
{
retCapability.profileLevel[i] = new EncodeVideoCapability.ProfileLevel(profileLevels[i].profile, profileLevels[i].level);
}
}
Range<Integer> widthRange = null;
Range<Integer> heightRange = null;
if(Build.VERSION.SDK_INT >= 21) {
MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
heightRange = videoCapabilities.getSupportedHeights();
widthRange = videoCapabilities.getSupportedWidths();
retCapability.heightAlignment = videoCapabilities.getHeightAlignment();
retCapability.widthAlignment = videoCapabilities.getWidthAlignment();
}
else //for old device limite max width / height
{
// retCapability.widthUpper = 1280;
// retCapability.widthLower = 176;
// retCapability.heightUpper = 720;
// retCapability.heightLower = 144;
retCapability.heightAlignment = 2;
retCapability.widthAlignment = 2;
}
if(null != widthRange)
{
retCapability.widthUpper = widthRange.getUpper();
retCapability.widthLower = widthRange.getLower();
}
if(null != heightRange)
{
retCapability.heightUpper = heightRange.getUpper();
retCapability.heightLower = heightRange.getLower();
}
return retCapability;
}
示例13: getCapbility
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
public static int getCapbility() {
int maxProfile = 0;
int tsType = -1;
Log.d(LOG_TAG, "getCapbility()->Build.VERSION.SDK_INT:" + String.valueOf(VERSION.SDK_INT));
if (VERSION.SDK_INT < 16) {
return -1;
}
int mediaCodecListCount = MediaCodecList.getCodecCount();
for (int i = 0; i < mediaCodecListCount; i++) {
MediaCodecInfo mediaCodecInfo = MediaCodecList.getCodecInfoAt(i);
if (!(mediaCodecInfo.isEncoder() || mediaCodecInfo.getName().startsWith("OMX.google") || mediaCodecInfo.getName().startsWith("OMX.TI."))) {
Log.d(LOG_TAG, "getCapbility()->name:" + mediaCodecInfo.getName());
for (String type : mediaCodecInfo.getSupportedTypes()) {
if (type.contains("avc")) {
Log.d(LOG_TAG, "getCapbility()->type:" + type);
try {
CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(type);
for (int colorFormat : codecCapabilities.colorFormats) {
Log.d(LOG_TAG, "getCapbility()->Color Format: " + colorFormat + " " + colorFormatToString(colorFormat));
}
for (CodecProfileLevel codecProfileLevel : codecCapabilities.profileLevels) {
String level = "unknown type";
String sprofile = "unknown type";
Log.d(LOG_TAG, "getCapbility()->Codec Profile Level:" + avcLevelToString(codecProfileLevel.level) + " profile:" + avcProfileToString(codecProfileLevel.profile));
if (codecProfileLevel.profile > maxProfile) {
maxProfile = codecProfileLevel.profile;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Log.d(LOG_TAG, "getCapbility()->Max profile:" + maxProfile + " " + avcProfileToString(maxProfile));
if (maxProfile >= 8) {
tsType = 16;
}
return tsType;
}
示例14: setupCandidate
import android.media.MediaCodecInfo; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static IjkMediaCodecInfo setupCandidate(MediaCodecInfo codecInfo,
String mimeType) {
if (codecInfo == null
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
return null;
String name = codecInfo.getName();
if (TextUtils.isEmpty(name))
return null;
name = name.toLowerCase(Locale.US);
int rank = RANK_NO_SENSE;
if (!name.startsWith("omx.")) {
rank = RANK_NON_STANDARD;
} else if (name.startsWith("omx.pv")) {
rank = RANK_SOFTWARE;
} else if (name.startsWith("omx.google.")) {
rank = RANK_SOFTWARE;
} else if (name.startsWith("omx.ffmpeg.")) {
rank = RANK_SOFTWARE;
} else if (name.startsWith("omx.k3.ffmpeg.")) {
rank = RANK_SOFTWARE;
} else if (name.startsWith("omx.avcodec.")) {
rank = RANK_SOFTWARE;
} else if (name.startsWith("omx.ittiam.")) {
// unknown codec in qualcomm SoC
rank = RANK_NO_SENSE;
} else if (name.startsWith("omx.mtk.")) {
// 1. MTK only works on 4.3 and above
// 2. MTK works on MIUI 6 (4.2.1)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
rank = RANK_NO_SENSE;
else
rank = RANK_TESTED;
} else {
Integer knownRank = getKnownCodecList().get(name);
if (knownRank != null) {
rank = knownRank;
} else {
try {
CodecCapabilities cap = codecInfo
.getCapabilitiesForType(mimeType);
if (cap != null)
rank = RANK_ACCEPTABLE;
else
rank = RANK_LAST_CHANCE;
} catch (Throwable e) {
rank = RANK_LAST_CHANCE;
}
}
}
IjkMediaCodecInfo candidate = new IjkMediaCodecInfo();
candidate.mCodecInfo = codecInfo;
candidate.mRank = rank;
candidate.mMimeType = mimeType;
return candidate;
}