android.media.MediaCodecList Java Examples

The following examples show how to use android.media.MediaCodecList. 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: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 7 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 #2
Source File: MediaController.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                String name = lastCodecInfo.getName();
                if (name != null) {
                    if (!name.equals("OMX.SEC.avc.enc")) {
                        return lastCodecInfo;
                    } else if (name.equals("OMX.SEC.AVC.Encoder")) {
                        return lastCodecInfo;
                    }
                }
            }
        }
    }
    return lastCodecInfo;
}
 
Example #3
Source File: MediaCodecBridge.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static String getSecureDecoderNameForMime(String mime) {
    int count = MediaCodecList.getCodecCount();
    for (int i = 0; i < count; ++i) {
        MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
        if (info.isEncoder()) {
            continue;
        }

        String[] supportedTypes = info.getSupportedTypes();
        for (int j = 0; j < supportedTypes.length; ++j) {
            if (supportedTypes[j].equalsIgnoreCase(mime)) {
                return info.getName() + ".secure";
            }
        }
    }

    return null;
}
 
Example #4
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 #5
Source File: MediaAudioEncoder.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 */
private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
    if (DEBUG) Log.v(TAG, "selectAudioCodec:");

    MediaCodecInfo result = null;
    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    LOOP:
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
            if (types[j].equalsIgnoreCase(mimeType)) {
                if (result == null) {
                    result = codecInfo;
                    break LOOP;
                }
            }
        }
    }
    return result;
}
 
Example #6
Source File: MediaConverter.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the first codec capable of encoding the specified MIME type, or null if no match was
 * found.
 */
static MediaCodecInfo selectCodec(final String mimeType) {
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {
            continue;
        }

        final String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
 
Example #7
Source File: VideoController.java    From VideoCompressor with Apache License 2.0 6 votes vote down vote up
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
 
Example #8
Source File: SettingsActivity.java    From echo with GNU General Public License v3.0 6 votes vote down vote up
private void debugPrintCodecs() {
    final int codecCount = MediaCodecList.getCodecCount();
    for(int i = 0; i < codecCount; ++i) {
        final MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
        if(!info.isEncoder()) continue;
        boolean audioFound = false;
        String types = "";
        final String[] supportedTypes = info.getSupportedTypes();
        for(int j = 0; j < supportedTypes.length; ++j) {
            if(j > 0)
                types += ", ";
            types += supportedTypes[j];
            if(supportedTypes[j].startsWith("audio")) audioFound = true;
        }
        if(!audioFound) continue;
        Log.d(TAG, "Codec " + i + ": " + info.getName() + " (" + types + ") encoder: " + info.isEncoder());
    }
}
 
Example #9
Source File: HardwareVideoEncoderFactory.java    From webrtc_android with MIT License 6 votes vote down vote up
private MediaCodecInfo findCodecForType(VideoCodecType type) {
    for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
        MediaCodecInfo info = null;
        try {
            info = MediaCodecList.getCodecInfoAt(i);
        } catch (IllegalArgumentException e) {
            Logging.e(TAG, "Cannot retrieve encoder codec info", e);
        }

        if (info == null || !info.isEncoder()) {
            continue;
        }

        if (isSupportedCodec(info, type)) {
            return info;
        }
    }
    return null; // No support for this type.
}
 
Example #10
Source File: MediaCodecVideoDecoderFactory.java    From webrtc_android with MIT License 6 votes vote down vote up
private
MediaCodecInfo findCodecForType(VideoCodecType type) {
    // HW decoding is not supported on builds before KITKAT.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return null;
    }

    for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
        MediaCodecInfo info = null;
        try {
            info = MediaCodecList.getCodecInfoAt(i);
        } catch (IllegalArgumentException e) {
            Logging.e(TAG, "Cannot retrieve decoder codec info", e);
        }

        if (info == null || info.isEncoder()) {
            continue;
        }

        if (isSupportedCodec(info, type)) {
            return info;
        }
    }

    return null; // No support for this type.
}
 
Example #11
Source File: MediaAudioEncoder.java    From ScreenRecordingSample with Apache License 2.0 6 votes vote down vote up
/**
     * select the first codec that match a specific MIME type
     * @param mimeType
     * @return
     */
    private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
    	if (DEBUG) Log.v(TAG, "selectAudioCodec:");

    	MediaCodecInfo result = null;
    	// get the list of available codecs
        final int numCodecs = MediaCodecList.getCodecCount();
LOOP:	for (int i = 0; i < numCodecs; i++) {
        	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
            if (!codecInfo.isEncoder()) {	// skipp decoder
                continue;
            }
            final String[] types = codecInfo.getSupportedTypes();
            for (int j = 0; j < types.length; j++) {
            	if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
                if (types[j].equalsIgnoreCase(mimeType)) {
                	if (result == null) {
                		result = codecInfo;
               			break LOOP;
                	}
                }
            }
        }
   		return result;
    }
 
Example #12
Source File: MediaAudioEncoder.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
/**
     * select the first codec that match a specific MIME type
     * @param mimeType
     * @return
     */
    private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
    	if (DEBUG) Log.v(TAG, "selectAudioCodec:");

    	MediaCodecInfo result = null;
    	// get the list of available codecs
        final int numCodecs = MediaCodecList.getCodecCount();
LOOP:	for (int i = 0; i < numCodecs; i++) {
        	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
            if (!codecInfo.isEncoder()) {	// skipp decoder
                continue;
            }
            final String[] types = codecInfo.getSupportedTypes();
            for (int j = 0; j < types.length; j++) {
            	if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
                if (types[j].equalsIgnoreCase(mimeType)) {
                	if (result == null) {
                		result = codecInfo;
               			break LOOP;
                	}
                }
            }
        }
   		return result;
    }
 
Example #13
Source File: AACEncodeConsumer.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
/**
 * 遍历所有编解码器,返回第一个与指定MIME类型匹配的编码器
 *  判断是否有支持指定mime类型的编码器
 * */
private MediaCodecInfo selectSupportCodec(String mimeType){
    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        // 判断是否为编码器,否则直接进入下一次循环
        if (!codecInfo.isEncoder()) {
            continue;
        }
        // 如果是编码器,判断是否支持Mime类型
        String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
 
Example #14
Source File: EncodeDecodeTest.java    From Android-MediaCodec-Examples with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the first codec capable of encoding the specified MIME type, or null if no
 * match was found.
 */
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;
}
 
Example #15
Source File: MediaSurfaceEncoder.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 * @param mimeType
 * @return null if no codec matched
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
	if (DEBUG) Log.v(TAG, "selectVideoCodec:");

	// get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
    	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(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)) {
            	if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
        		final int format = selectColorFormat(codecInfo, mimeType);
            	if (format > 0) {
            		return codecInfo;
            	}
            }
        }
    }
    return null;
}
 
Example #16
Source File: VideoController.java    From VideoCompressor with Apache License 2.0 6 votes vote down vote up
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
 
Example #17
Source File: MediaVideoEncoder.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 * @param mimeType
 * @return null if no codec matched
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
	if (DEBUG) Log.v(TAG, "selectVideoCodec:");

	// get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
    	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(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)) {
            	if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
        		final int format = selectColorFormat(codecInfo, mimeType);
            	if (format > 0) {
            		return codecInfo;
            	}
            }
        }
    }
    return null;
}
 
Example #18
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 #19
Source File: MediaVideoEncoder.java    From In77Camera 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
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
	if (DEBUG) Log.v(TAG, "selectVideoCodec:");

	// get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
    	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(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)) {
            	if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
        		final int format = selectColorFormat(codecInfo, mimeType);
            	if (format > 0) {
            		return codecInfo;
            	}
            }
        }
    }
    return null;
}
 
Example #20
Source File: MediaAudioEncoder.java    From In77Camera with MIT License 6 votes vote down vote up
/**
   * select the first codec that match a specific MIME type
   * @param mimeType
   * @return
   */
  private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
  	if (DEBUG) Log.v(TAG, "selectAudioCodec:");

  	MediaCodecInfo result = null;
  	// get the list of available codecs
      final int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
      	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
          if (!codecInfo.isEncoder()) {	// skipp decoder
              continue;
          }
          final String[] types = codecInfo.getSupportedTypes();
          for (int j = 0; j < types.length; j++) {
          	if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
              if (types[j].equalsIgnoreCase(mimeType)) {
              	if (result == null) {
              		result = codecInfo;
             			return result;
              	}
              }
          }
      }
 		return result;
  }
 
Example #21
Source File: Api16Builder.java    From jellyfin-androidtv with GNU General Public License v2.0 6 votes vote down vote up
public void buildProfiles(DeviceProfile profile){
    ArrayList<DirectPlayProfile> directPlayProfiles = new ArrayList<>();
    ArrayList<CodecProfile> codecProfiles = new ArrayList<>();

    int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (codecInfo.isEncoder()) {
            continue;
        }

        ProcessMediaCodecInfo(codecInfo, directPlayProfiles, codecProfiles);
    }

    profile.setDirectPlayProfiles(directPlayProfiles.toArray(new DirectPlayProfile[directPlayProfiles.size()]));
    profile.setCodecProfiles(codecProfiles.toArray(new CodecProfile[codecProfiles.size()]));
}
 
Example #22
Source File: MainActivity.java    From AndroidPlayground with MIT License 6 votes vote down vote up
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;
}
 
Example #23
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 #24
Source File: VideoEncoder.java    From haven with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the first codec capable of encoding the specified MIME type, or
 * null if no match was found.
 */
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;
}
 
Example #25
Source File: MediaAudioEncoder.java    From UVCCameraZxing with Apache License 2.0 6 votes vote down vote up
/**
     * select the first codec that match a specific MIME type
     * @param mimeType
     * @return
     */
    private static final MediaCodecInfo selectAudioCodec(final String mimeType) {
    	if (DEBUG) Log.v(TAG, "selectAudioCodec:");

    	MediaCodecInfo result = null;
    	// get the list of available codecs
        final int numCodecs = MediaCodecList.getCodecCount();
LOOP:	for (int i = 0; i < numCodecs; i++) {
        	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
            if (!codecInfo.isEncoder()) {	// skipp decoder
                continue;
            }
            final String[] types = codecInfo.getSupportedTypes();
            for (int j = 0; j < types.length; j++) {
            	if (DEBUG) Log.i(TAG, "supportedType:" + codecInfo.getName() + ",MIME=" + types[j]);
                if (types[j].equalsIgnoreCase(mimeType)) {
                	if (result == null) {
                		result = codecInfo;
               			break LOOP;
                	}
                }
            }
        }
   		return result;
    }
 
Example #26
Source File: MediaVideoEncoder.java    From AudioVideoRecordingSample with Apache License 2.0 6 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 * @param mimeType
 * @return null if no codec matched
 */
protected static final MediaCodecInfo selectVideoCodec(final String mimeType) {
	if (DEBUG) Log.v(TAG, "selectVideoCodec:");

	// get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
    	final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(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)) {
            	if (DEBUG) Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
        		final int format = selectColorFormat(codecInfo, mimeType);
            	if (format > 0) {
            		return codecInfo;
            	}
            }
        }
    }
    return null;
}
 
Example #27
Source File: MediaAudioEncoder.java    From EZFilter with MIT License 6 votes vote down vote up
private static MediaCodecInfo selectAudioCodec(final String mimeType) {
    // get the list of available codecs
    final int numCodecs = MediaCodecList.getCodecCount();
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        final String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}
 
Example #28
Source File: MediaController.java    From SiliCompressor with Apache License 2.0 6 votes vote down vote up
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}
 
Example #29
Source File: VideoEditor.java    From WeiXinRecordedDemo with MIT License 6 votes vote down vote up
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;
}
 
Example #30
Source File: MediaController.java    From KrGallery with GNU General Public License v2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static MediaCodecInfo selectCodec(String mimeType) {
    int numCodecs = MediaCodecList.getCodecCount();
    MediaCodecInfo lastCodecInfo = null;
    for (int i = 0; i < numCodecs; i++) {
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if (!codecInfo.isEncoder()) {
            continue;
        }
        String[] types = codecInfo.getSupportedTypes();
        for (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                lastCodecInfo = codecInfo;
                if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
                    return lastCodecInfo;
                } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
                    return lastCodecInfo;
                }
            }
        }
    }
    return lastCodecInfo;
}