当前位置: 首页>>代码示例>>Java>>正文


Java MediaCodec.createEncoderByType方法代码示例

本文整理汇总了Java中android.media.MediaCodec.createEncoderByType方法的典型用法代码示例。如果您正苦于以下问题:Java MediaCodec.createEncoderByType方法的具体用法?Java MediaCodec.createEncoderByType怎么用?Java MediaCodec.createEncoderByType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaCodec的用法示例。


在下文中一共展示了MediaCodec.createEncoderByType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: VideoEncoderCore

import android.media.MediaCodec; //导入方法依赖的package包/类
/**
 * Configures encoder and muxer state, and prepares the input Surface.
 */
public VideoEncoderCore(int width, int height, int bitRate, MMediaMuxer MMediaMuxer)
        throws IOException {
    super(MMediaMuxer);

    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);

    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, calcBitRate(width,height));
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
    if (VERBOSE) Log.d(TAG, "format: " + format);

    // Create a MediaCodec encoder, and configure it with our format.  Get a Surface
    // we can use for input and wrap it with a class that handles the EGL work.
    mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

    mInputSurface = mEncoder.createInputSurface();
    mEncoder.start();
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:27,代码来源:VideoEncoderCore.java

示例2: openVideoEncoder

import android.media.MediaCodec; //导入方法依赖的package包/类
private void openVideoEncoder(){
    AvLog.d(TAG,"openVideoEncoder startTime-->");
    if(mVideoEncoder==null){
        try {
            MediaFormat format=convertVideoConfigToFormat(mConfig.mVideo);
            mVideoEncoder= MediaCodec.createEncoderByType(mConfig.mVideo.mime);
            mVideoEncoder.configure(format,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
            super.setSurface(mVideoEncoder.createInputSurface());
            super.setOutputSize(mConfig.mVideo.width,mConfig.mVideo.height);
            mVideoEncoder.start();
            isEncodeStarted=true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    AvLog.d(TAG,"openVideoEncoder endTime-->");
}
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:18,代码来源:SurfaceEncoder.java

示例3: createMediaCodec

import android.media.MediaCodec; //导入方法依赖的package包/类
private MediaCodec createMediaCodec(int bufferSize) throws IOException {
  MediaCodec  mediaCodec  = MediaCodec.createEncoderByType("audio/mp4a-latm");
  MediaFormat mediaFormat = new MediaFormat();

  mediaFormat.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, SAMPLE_RATE);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, CHANNELS);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, bufferSize);
  mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
  mediaFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);

  try {
    mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
  } catch (Exception e) {
    Log.w(TAG, e);
    mediaCodec.release();
    throw new IOException(e);
  }

  return mediaCodec;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:22,代码来源:AudioCodec.java

示例4: setup

import android.media.MediaCodec; //导入方法依赖的package包/类
@Override
    public void setup() throws IOException {
        mExtractor.selectTrack(mTrackIndex);
        mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
        mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mEncoderInputSurfaceWrapper = new InputSurface(mEncoder.createInputSurface());
        mEncoder.start();
        mEncoderStarted = true;
        mEncoderOutputBuffers = mEncoder.getOutputBuffers();

        MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
//        if (inputFormat.containsKey(MediaUtil.KEY_ROTATION)) {
//            // Decoded video is rotated automatically in Android 5.0 lollipop.
//            // Turn off here because we don't want to encode rotated one.
//            // refer: https://android.googlesource
//            // .com/platform/frameworks/av/+blame/lollipop-release/media/libstagefright/Utils.cpp
//            inputFormat.setInteger(MediaUtil.KEY_ROTATION, 0);
//        }

        mDecoderOutputSurfaceWrapper = new OutputSurface(mSurfaceRender);
        mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
        mDecoder.configure(inputFormat, mDecoderOutputSurfaceWrapper.getSurface(), null, 0);
        mDecoder.start();
        mDecoderStarted = true;
        mDecoderInputBuffers = mDecoder.getInputBuffers();
    }
 
开发者ID:uestccokey,项目名称:EZFilter,代码行数:27,代码来源:VideoTrackTranscoder.java

示例5: checkMediaCodecAudioEncoderSupport

import android.media.MediaCodec; //导入方法依赖的package包/类
@TargetApi(MIN_API_LEVEL_AUDIO)
public static int checkMediaCodecAudioEncoderSupport(){
    if(getApiLevel()<MIN_API_LEVEL_AUDIO){
        Log.d(TAG, "checkMediaCodecAudioEncoderSupport: Min API is 16");
        return CODEC_REQ_API_NOT_SATISFIED;
    }
    final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE_AUDIO, TEST_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, TEST_AUDIO_BIT_RATE);
    audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
    MediaCodec mediaCodec;
    try {
        mediaCodec = MediaCodec.createEncoderByType(MIME_TYPE_AUDIO);
        mediaCodec.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mediaCodec.start();
        mediaCodec.stop();
        mediaCodec.release();
        mediaCodec = null;
    } catch (Exception ex) {
        Log.e(TAG, "Failed on creation of codec #", ex);
        return CODEC_ERROR;
    }
    return CODEC_SUPPORTED;
}
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:26,代码来源:MediaCodecUtils.java

示例6: AudioEncoderCore

import android.media.MediaCodec; //导入方法依赖的package包/类
public AudioEncoderCore(MMediaMuxer MMediaMuxer) throws IOException {
        super(MMediaMuxer);
        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);
//		audioFormat.setLong(MediaFormat.KEY_MAX_INPUT_SIZE, inputFile.length());
//      audioFormat.setLong(MediaFormat.KEY_DURATION, (long)durationInMs );
        if (VERBOSE) Log.i(TAG, "format: " + audioFormat);
        mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
        mEncoder.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mEncoder.start();
        if (mAudioThread == null) {
            mAudioThread = new AudioThread();
            mAudioThread.start();
            capturing=true;
            stopped=false;
        }
    }
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:21,代码来源:AudioEncoderCore.java

示例7: startRecord

import android.media.MediaCodec; //导入方法依赖的package包/类
public void startRecord() throws IOException {
        synchronized (REC_LOCK){
            isRecordStarted=true;
            MediaFormat audioFormat=mConfig.getAudioFormat();
            mAudioEncoder=MediaCodec.createEncoderByType(audioFormat.getString(MediaFormat.KEY_MIME));
            mAudioEncoder.configure(audioFormat,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
            MediaFormat videoFormat=mConfig.getVideoFormat();
            mVideoEncoder=MediaCodec.createEncoderByType(videoFormat.getString(MediaFormat.KEY_MIME));
            //此处不能用mOutputSurface,会configure失败
            mVideoEncoder.configure(videoFormat,null,null,MediaCodec.CONFIGURE_FLAG_ENCODE);
            mEncodeSurface=mVideoEncoder.createInputSurface();

            mAudioEncoder.start();
            mVideoEncoder.start();
            mMuxer=new MediaMuxer(mOutputPath,MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
            mRecordBufferSize = AudioRecord.getMinBufferSize(mRecordSampleRate,
                    mRecordChannelConfig, mRecordAudioFormat)*2;
//        buffer=new byte[bufferSize];
            mAudioRecord=new AudioRecord(MediaRecorder.AudioSource.MIC,mRecordSampleRate,mRecordChannelConfig,
                    mRecordAudioFormat,mRecordBufferSize);

            mAudioThread=new Thread(new Runnable() {
                @Override
                public void run() {
                    mAudioRecord.startRecording();
                    while (!audioEncodeStep(isTryStopAudio)){};
                    mAudioRecord.stop();
                }
            });
            mAudioThread.start();
            isRecordAudioStarted=true;
        }
    }
 
开发者ID:aiyaapp,项目名称:AAVT,代码行数:34,代码来源:CameraRecorder.java

示例8: getAudioMediaCodec

import android.media.MediaCodec; //导入方法依赖的package包/类
@TargetApi(18)
public static MediaCodec getAudioMediaCodec(){
    MediaFormat format = MediaFormat.createAudioFormat(
            Options.getInstance().audio.mime,
            Options.getInstance().audio.frequency,
            Options.getInstance().audio.channelCount);
    if(Options.getInstance().audio.mime.equals(Options.DEFAULT_MIME)) {
        format.setInteger(MediaFormat.KEY_AAC_PROFILE, Options.getInstance().audio.aacProfile);
    }
    format.setInteger(MediaFormat.KEY_BIT_RATE, Options.getInstance().audio.maxBps * 1024);
    format.setInteger(MediaFormat.KEY_SAMPLE_RATE, Options.getInstance().audio.frequency);
    int maxInputSize = getRecordBufferSize();
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
    format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, Options.getInstance().audio.channelCount);

    MediaCodec mediaCodec = null;
    try {
        mediaCodec = MediaCodec.createEncoderByType(Options.getInstance().audio.mime);
        mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    } catch (Exception e) {
        e.printStackTrace();
        if (mediaCodec != null) {
            mediaCodec.stop();
            mediaCodec.release();
            mediaCodec = null;
        }
    }
    return mediaCodec;
}
 
开发者ID:wuyisheng,项目名称:libRtmp,代码行数:30,代码来源:AndroidUntil.java

示例9: createMediaCodecEncoder

import android.media.MediaCodec; //导入方法依赖的package包/类
public static MediaCodec createMediaCodecEncoder(String mime) throws IOException {

        return MediaCodec.createEncoderByType(mime);
    	
    	
        /*String hardwareEncoderName = findHardwareEncodeeName(mime);
        if(null == hardwareEncoderName || hardwareEncoderName.equals("AACEncoder")){
            return MediaCodec.createEncoderByType(mime);
        }
        else{
        	Log.i(TAG,"hardwareEncoderName = " + hardwareEncoderName);
            return MediaCodec.createByCodecName(hardwareEncoderName);
        }*/
    }
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:15,代码来源:EncodeUtils.java

示例10: getMediaCodec

import android.media.MediaCodec; //导入方法依赖的package包/类
public static MediaCodec getMediaCodec () {
    MediaCodec encoder = null;
    try {
        encoder = MediaCodec.createEncoderByType(AccessConstants.FORMAT);
    } catch (IOException e) {
        e.printStackTrace();
    }
    encoder.configure(DeEncodecCommon.getFormat(), null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    return encoder;
}
 
开发者ID:kaixuanluo,项目名称:pc-android-controller-android,代码行数:11,代码来源:DeEncodecCommon.java

示例11: H264Encoder

import android.media.MediaCodec; //导入方法依赖的package包/类
/**
     *
     * @param eglCtx can be EGL10.EGL_NO_CONTEXT or outside context
     */
    public H264Encoder(final StreamPublisher.StreamPublisherParam params, final EglContextWrapper eglCtx) throws IOException {

//        MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, params.width, params.height);
        MediaFormat format = params.createVideoMediaFormat();


        // Set some properties.  Failing to specify some of these can cause the MediaCodec
        // configure() call to throw an unhelpful exception.
        format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
                MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
        format.setInteger(MediaFormat.KEY_BIT_RATE, params.videoBitRate);
        format.setInteger(MediaFormat.KEY_FRAME_RATE, params.frameRate);
        format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, params.iframeInterval);
        mEncoder = MediaCodec.createEncoderByType(params.videoMIMEType);
        mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mInputSurface = mEncoder.createInputSurface();
        mEncoder.start();
        mediaCodecInputStream = new MediaCodecInputStream(mEncoder, new MediaCodecInputStream.MediaFormatCallback() {
            @Override
            public void onChangeMediaFormat(MediaFormat mediaFormat) {
                params.setVideoOutputMediaFormat(mediaFormat);
            }
        });

        offScreenCanvas = new EncoderCanvas(params.width, params.height, eglCtx);
    }
 
开发者ID:ChillingVan,项目名称:AndroidInstantVideo,代码行数:31,代码来源:H264Encoder.java

示例12: MpegEncoder

import android.media.MediaCodec; //导入方法依赖的package包/类
/** Constructs a new {@link MpegEncoder} */
private MpegEncoder(@NonNull Builder builder, @NonNull MediaFormat format,
        @NonNull String path) throws IOException {
    checkState();

    mFrameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);

    mEncoder = MediaCodec.createEncoderByType(format.getString(MediaFormat.KEY_MIME));
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

    mSurface = mEncoder.createInputSurface();
    mInputSurface =
            InputSurface.create (
                    mSurface,
                    builder.inputBuffer,
                    builder.width,
                    builder.height
            )
                    .autoSwap()
                    .build();

    mMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    if (builder.mLocation != null) {
        mMuxer.setLocation(builder.mLocation.x, builder.mLocation.y);
    }
    if (builder.mOrientation != 0) {
        mMuxer.setOrientationHint(builder.mOrientation);
    }

    mOutputBuffers = start();
}
 
开发者ID:Nik-Gleb,项目名称:mpeg-encoder,代码行数:32,代码来源:MpegEncoder.java

示例13: clickStart

import android.media.MediaCodec; //导入方法依赖的package包/类
/**
 * onClick handler for "start" button.
 *
 * We create as many codecs as we can and return without releasing them.  The codecs
 * will remain in use until the next GC.
 */
public void clickStart(@SuppressWarnings("unused") View unused) {
    final String MIME_TYPE = "video/avc";
    final int WIDTH = 320;
    final int HEIGHT = 240;
    final int BIT_RATE = 1000000;
    final int FRAME_RATE = 15;
    final int IFRAME_INTERVAL = 1;
    final boolean START_CODEC = true;

    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, WIDTH, HEIGHT);

    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
    Log.d(TAG, "format: " + format);

    MediaCodec[] codecs = new MediaCodec[MAX_OPEN];
    int i;
    for (i = 0; i < MAX_OPEN; i++) {
        try {
            codecs[i] = MediaCodec.createEncoderByType(MIME_TYPE);
            codecs[i].configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
            if (START_CODEC) {
                codecs[i].createInputSurface();
                codecs[i].start();
            }
        } catch (Exception ex) {
            Log.i(TAG, "Failed on creation of codec #" + i, ex);
            break;
        }
    }

    showCountDialog(i);
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:43,代码来源:CodecOpenActivity.java

示例14: prepareEncoder

import android.media.MediaCodec; //导入方法依赖的package包/类
private void prepareEncoder() throws IOException {
    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, 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);
    RecordScreenLogUtil.i(TAG, "created video format: " + format);
    mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    mSurface = mEncoder.createInputSurface();
    mEncoder.start();
}
 
开发者ID:sunshinecoast,项目名称:ScreenRecordCaptureMaster,代码行数:13,代码来源:YixiaScreenEncoder.java

示例15: VideoEncoderCore

import android.media.MediaCodec; //导入方法依赖的package包/类
/**
 * Configures encoder and muxer state, and prepares the input Surface.
 */
public VideoEncoderCore(int width, int height, int bitRate, File outputFile)
        throws IOException {
    mBufferInfo = new MediaCodec.BufferInfo();

    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);

    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
    if (VERBOSE) Log.d(TAG, "format: " + format);

    // Create a MediaCodec encoder, and configure it with our format.  Get a Surface
    // we can use for input and wrap it with a class that handles the EGL work.
    mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    mInputSurface = mEncoder.createInputSurface();
    mEncoder.start();

    // Create a MediaMuxer.  We can't add the video track and start() the muxer here,
    // because our MediaFormat doesn't have the Magic Goodies.  These can only be
    // obtained from the encoder after it has started processing data.
    //
    // We're not actually interested in multiplexing audio.  We just want to convert
    // the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
    mMuxer = new MediaMuxer(outputFile.toString(),
            MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

    mTrackIndex = -1;
    mMuxerStarted = false;
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:38,代码来源:VideoEncoderCore.java


注:本文中的android.media.MediaCodec.createEncoderByType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。