android.media.MediaCodecInfo Java Examples

The following examples show how to use android.media.MediaCodecInfo. 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: CodecUtil.java    From EZFilter with MIT License 6 votes vote down vote up
private static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
    int result = 0;
    final MediaCodecInfo.CodecCapabilities capabilities;
    try {
        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        capabilities = codecInfo.getCapabilitiesForType(mimeType);
    } finally {
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
    }

    int colorFormat;
    for (int i = 0; i < capabilities.colorFormats.length; i++) {
        colorFormat = capabilities.colorFormats[i];
        if (isRecognizedViewFormat(colorFormat)) {
            result = colorFormat;
            break;
        }
    }
    if (result == 0) {
        Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
    }
    return result;
}
 
Example #2
Source File: MediaController.java    From Telegram 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: 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 #4
Source File: MediaAudioEncoder.java    From Fatigue-Detection 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 #5
Source File: MediaVideoEncoder.java    From EZFilter with MIT License 6 votes vote down vote up
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;
}
 
Example #6
Source File: VideoUtils.java    From SoloPi with Apache License 2.0 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 #7
Source File: MediaSurfaceEncoder.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 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 #8
Source File: StreamingAudioEncoder.java    From live-transcribe-speech-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Searches for a codec that implements the requested format conversion. Android framework encoder
 * only.
 */
private static MediaCodecInfo searchAmongAndroidSupportedCodecs(String mimeType) {
  int numCodecs = MediaCodecList.getCodecCount();
  for (int i = 0; i < numCodecs; i++) {
    MediaCodecInfo codecAndBitrate = MediaCodecList.getCodecInfoAt(i);
    if (!codecAndBitrate.isEncoder()) {
      continue;
    }
    String[] codecTypes = codecAndBitrate.getSupportedTypes();
    for (int j = 0; j < codecTypes.length; j++) {
      if (codecTypes[j].equalsIgnoreCase(mimeType)) {
        return codecAndBitrate;
      }
    }
  }
  return null;
}
 
Example #9
Source File: MediaVideoEncoder.java    From Fatigue-Detection 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 #10
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 #11
Source File: ScreenRecordThread.java    From ScreenCapture with MIT License 6 votes vote down vote up
private void prepareEncoder() {
    MediaFormat format = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, mWidth, mHeight);
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);

    Log.d(TAG, "created video format: " + format);
    try {
        mEncoder = MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
    } catch (IOException e) {
        e.printStackTrace();
    }
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    mSurface = mEncoder.createInputSurface();
    Log.d(TAG, "created input surface: " + mSurface);
    mEncoder.start();
}
 
Example #12
Source File: MediaAudioEncoder.java    From MegviiFacepp-Android-SDK 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: MediaAudioEncoderRunable.java    From GLES2_AUDIO_VIDEO_RECODE with Apache License 2.0 6 votes vote down vote up
/**
 * 录制前的准备
 *
 * @throws IOException
 */
@Override
public void prepare() throws IOException {

    mTrackIndex = -1;
    mMuxerStarted = mIsEndOfStream = false;

    // mediaFormat配置
    final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLE_RATE, 1);
    audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
    audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
    audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
    //
    mMediaCodec = MediaCodec.createEncoderByType(MIME_TYPE);
    mMediaCodec.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    mMediaCodec.start();

    if (mMediaEncoderListener != null) {
        try {
            mMediaEncoderListener.onPrepared(this);
        } catch (final Exception e) {
            LogUtils.e(TAG, "prepare:", e);
        }
    }
}
 
Example #14
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 #15
Source File: RecordUtil.java    From WeiXinRecordedDemo with MIT License 6 votes vote down vote up
private void initVideoMediaCodec()throws Exception{
    MediaFormat mediaFormat;
    if(rotation==90 || rotation==270){
        //设置视频宽高
        mediaFormat = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, videoHeight, videoWidth);
    }else{
        mediaFormat = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, videoWidth, videoHeight);
    }
    //图像数据格式 YUV420
    mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar);
    //码率
    mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, videoWidth*videoHeight*3);
    //每秒30帧
    mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
    //1秒一个关键帧
    mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
    videoMediaCodec = MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
    videoMediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    videoMediaCodec.start();
}
 
Example #16
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private MediaCodecInfo getVideoCodecInfo(String codecName) {
    if (codecName == null) {
        return null;
    }
    if (mAvcCodecInfo == null) {
        mAvcCodecInfo = VideoUtils.findEncodersByType(ScreenRecorder.VIDEO_AVC);
    }
    MediaCodecInfo codec = null;
    for (int i = 0; i < mAvcCodecInfo.length; i++) {
        MediaCodecInfo info = mAvcCodecInfo[i];
        if (info.getName().equals(codecName)) {
            codec = info;
            break;
        }
    }
    if (codec == null) {
        return null;
    }
    return codec;
}
 
Example #17
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 #18
Source File: MediaAudioEncoder.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
     */
    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 #19
Source File: ComposerAudioEffectCoreActivity.java    From media-for-mobile with Apache License 2.0 6 votes vote down vote up
@Override
protected void setTranscodeParameters(MediaComposer mediaComposer) throws IOException {
    mediaComposer.addSourceFile(mediaUri1);
    mediaComposer.setTargetFile(dstMediaPath);

    configureVideoEncoder(mediaComposer, videoWidthOut, videoHeightOut);

    AudioFormatAndroid audioFormat = new AudioFormatAndroid(audioMimeType, audioSampleRate, audioChannelCount);
    audioFormat.setKeyMaxInputSize(48 * 1024);
    audioFormat.setAudioBitrateInBytes(audioBitRate);
    audioFormat.setAudioProfile(MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    mediaComposer.setTargetAudioFormat(audioFormat);


    SubstituteAudioEffect effect = new SubstituteAudioEffect();
    effect.setFileUri(this, mediaUri2, this.audioFormat);
    mediaComposer.addAudioEffect(effect);
}
 
Example #20
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;
}
 
Example #21
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 #22
Source File: HardwareVideoEncoderFactory.java    From webrtc_android with MIT License 5 votes vote down vote up
/**
 * Creates a HardwareVideoEncoderFactory that supports surface texture encoding.
 *
 * @param sharedContext         The textures generated will be accessible from this context. May be null,
 *                              this disables texture support.
 * @param enableIntelVp8Encoder true if Intel's VP8 encoder enabled.
 * @param enableH264HighProfile true if H264 High Profile enabled.
 * @param codecAllowedPredicate optional predicate to filter codecs. All codecs are allowed
 *                              when predicate is not provided.
 */
public HardwareVideoEncoderFactory(EglBase.Context sharedContext, boolean enableIntelVp8Encoder,
                                   boolean enableH264HighProfile, Predicate<MediaCodecInfo> codecAllowedPredicate) {
    // Texture mode requires EglBase14.
    if (sharedContext instanceof EglBase14.Context) {
        this.sharedContext = (EglBase14.Context) sharedContext;
    } else {
        Logging.w(TAG, "No shared EglBase.Context.  Encoders will not use texture mode.");
        this.sharedContext = null;
    }
    this.enableIntelVp8Encoder = enableIntelVp8Encoder;
    this.enableH264HighProfile = enableH264HighProfile;
    this.codecAllowedPredicate = codecAllowedPredicate;
}
 
Example #23
Source File: AudioEncoder.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 指定された MediaCodecInfo のマイムタイプとカラーフォーマットが一致するか確認します.
 *
 * @param codecInfo 確認する MediaCodecInfo
 * @param mimeType マイムタイプ
 * @return 一致する場合はtrue、それ以外はfalse
 */
private boolean isMediaCodecInfo(MediaCodecInfo codecInfo, String mimeType) {
    if (!codecInfo.isEncoder()) {
        return false;
    }

    String[] types = codecInfo.getSupportedTypes();
    for (String type : types) {
        if (type.equalsIgnoreCase(mimeType)) {
            return true;
        }
    }

    return false;
}
 
Example #24
Source File: CodecUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public static List<MediaCodecInfo> getAllHardwareDecoders(String mime) {
  List<MediaCodecInfo> mediaCodecInfoList = getAllDecoders(mime);
  List<MediaCodecInfo> mediaCodecInfoHardware = new ArrayList<>();
  for (MediaCodecInfo mediaCodecInfo : mediaCodecInfoList) {
    if (isHardwareAccelerated(mediaCodecInfo)) {
      mediaCodecInfoHardware.add(mediaCodecInfo);
    }
  }
  return mediaCodecInfoHardware;
}
 
Example #25
Source File: Android16By9FormatStrategy.java    From android-transcoder with Apache License 2.0 5 votes vote down vote up
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
    if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;

    // Use original sample rate, as resampling is not supported yet.
    final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
            inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
    format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
    return format;
}
 
Example #26
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 #27
Source File: AndroidStandardFormatStrategy.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
    int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);
    int height = inputFormat.getInteger(MediaFormat.KEY_HEIGHT);
    ASPECT_RATIO = (float) width / height;
    Log.d(TAG, "Input video (" + width + "x" + height + " ratio: " + ASPECT_RATIO);
    int shorter, outWidth, outHeight;
    if (width >= height) {
        shorter = height;
        outWidth = Math.round(mVideoresolution * ASPECT_RATIO);
        outHeight = mVideoresolution;
    } else {
        shorter = width;
        outWidth = mVideoresolution;
        outHeight = Math.round(mVideoresolution * ASPECT_RATIO);
    }
    if (shorter < mVideoresolution) {
        Log.d(TAG, "This video is less to " + mVideoresolution + "p, pass-through. (" + width + "x" + height + ")");
        return null;
    }
    Log.d(TAG, "Converting video (" + outWidth + "x" + outHeight + " ratio: " + ASPECT_RATIO + ")");
    MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
    format.setInteger(MediaFormat.KEY_BIT_RATE, mVideoBitrate);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        format.setInteger(MediaFormat.KEY_PROFILE ,MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline);
        format.setInteger(MediaFormat.KEY_LEVEL, MediaCodecInfo.CodecProfileLevel.AVCLevel13);
    }
    return format;
}
 
Example #28
Source File: EncodeDecode.java    From videocreator with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if this is a color format that this test code understands
 * (i.e. we know how to read and generate frames in this format).
 */
private static boolean isRecognizedFormat(int colorFormat) {
    switch (colorFormat) {
        // these are the formats we know how to handle for
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar:
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedPlanar:
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar:
        case MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420PackedSemiPlanar:
        case MediaCodecInfo.CodecCapabilities.COLOR_TI_FormatYUV420PackedSemiPlanar:
            return true;
        default:
            return false;
    }
}
 
Example #29
Source File: AudioEncoder.java    From LiveMultimedia with Apache License 2.0 5 votes vote down vote up
public synchronized void createAudioFormat() {
    if (Thread.currentThread().isInterrupted()) {
        release();
    }
    mAudioFormat  = new MediaFormat();
    mAudioFormat.setString(MediaFormat.KEY_MIME, AUDIO_MIME_TYPE);
    mAudioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
    mAudioFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, 44100);
    mAudioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
    mAudioFormat.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
    mAudioFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16384);
}
 
Example #30
Source File: MediaCodecListCompat.java    From android-transcoder with Apache License 2.0 5 votes vote down vote up
public final MediaCodecInfo[] getCodecInfos() {
    int codecCount = getCodecCount();
    MediaCodecInfo[] codecInfos = new MediaCodecInfo[codecCount];
    Iterator<MediaCodecInfo> iterator = new MediaCodecInfoIterator();
    for (int i = 0; i < codecCount; i++) {
        codecInfos[i] = getCodecInfoAt(i);
    }
    return codecInfos;
}