Java 类android.media.MediaMuxer 实例源码

项目:LiveMultimedia    文件:AudioEncoder.java   
public synchronized void createAudioMuxer() throws IllegalStateException{
    if (Thread.currentThread().isInterrupted()) {
            release();
    }
    if ( isExternalStorageWritable()) {
        File encodedFile = new File(OUTPUT_FILENAME_DIR, "/movies/EncodedAudio.mp4");
        if (encodedFile.exists()) {
            boolean result = encodedFile.delete();
            if (!result)
                 throw new IllegalStateException("Unable to delete video file");
        }
        String outputPath = encodedFile.toString();
        int format = MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4;
        try {
            mAudioMuxer = new MediaMuxer(outputPath, format);
        } catch (IOException e) {
            Log.e(TAG, "Audio temp Muxer failed to create!!");
        }
    }
}
项目:LiveMultimedia    文件:GPUEncoder.java   
/********************************************************************************
 * 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.
 **********************************************************************************/
@SuppressWarnings("all")
private synchronized void createMuxer() {
    Log.d(TAG, "--->createMuxer()");
    if ( isExternalStorageWritable()) {
        File encodedFile = new File(OUTPUT_FILENAME_DIR, "/movies/EncodedAV" + "-" + mEncodingWidth + "x" + mEncodingHeight + ".mp4");
        if (encodedFile.exists()) {
            encodedFile.delete();
        }
        String outputPath = encodedFile.toString();
        int format = MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4;
        try {
            mMuxer = new MediaMuxer(outputPath, format);
        } catch (IOException e) {
            Log.e(TAG, e.getLocalizedMessage());
        }
        mVideoTrackIndex = -1;
        mMuxerStarted = false;
    }
}
项目:cineio-broadcast-android    文件:AndroidMuxer.java   
@Override
public void prepare(EncodingConfig config) {
    super.prepare(config);

    try {
        switch (config.getFormat()) {
            case MPEG4:
                mMuxer = new MediaMuxer(config.getOutputPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
                break;
            default:
                throw new IllegalArgumentException("Unrecognized format!");
        }
    } catch (IOException e) {
        throw new RuntimeException("MediaMuxer creation failed", e);
    }

}
项目:AndroidVideoSamples    文件:SurfaceEncoder.java   
private void prepareEncoder() {
   mBufferInfo = new MediaCodec.BufferInfo();

   MediaFormat format = MediaFormat.createVideoFormat( MIME_TYPE, mSource.getWidth(), mSource.getHeight() );

   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 );

   mEncoder = MediaCodec.createEncoderByType( MIME_TYPE );
   mEncoder.configure( format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE );
   mSurface = mEncoder.createInputSurface();
   mEncoder.start();

   try {
      mMuxer = new MediaMuxer( mUri.toString(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4 );
   } catch ( IOException ioe ) {
      throw new RuntimeException( "MediaMuxer creation failed", ioe );
   }

   mTrackIndex = -1;
   mMuxerStarted = false;
}
项目:AAVT    文件:StrengthenMp4MuxStore.java   
@Override
public int addTrack(MediaFormat mediaFormat) {
    int ret=-1;
    synchronized (Lock){
        if(!muxStarted){
            if(audioTrack==-1&&videoTrack==-1){
                try {
                    mMuxer=new MediaMuxer(path,MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
                } catch (IOException e) {
                    e.printStackTrace();
                    AvLog.e("create MediaMuxer failed:"+e.getMessage());
                }
            }
            String mime=mediaFormat.getString(MediaFormat.KEY_MIME);
            if(mime.startsWith("audio")){
                audioTrack=mMuxer.addTrack(mediaFormat);
                ret=audioTrack;
            }else if(mime.startsWith("video")){
                videoTrack=mMuxer.addTrack(mediaFormat);
                ret=videoTrack;
            }
            startMux();
        }
    }
    return ret;
}
项目:Hotspot-master-devp    文件:ScreenRecorder.java   
@SuppressLint("NewApi")
@Override
public void run() {
    try {
        try {
            prepareEncoder();
            mMuxer = new MediaMuxer(mDstPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG + "-display",
                mWidth, mHeight, mDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
                mSurface, null, null);
        Log.d(TAG, "created virtual display: " + mVirtualDisplay);
        recordVirtualDisplay();

    } finally {
        release();
    }
}
项目:rtmp-rtsp-stream-client-java    文件:Camera2Base.java   
/**
 * Start record a MP4 video. Need be called while stream.
 *
 * @param path where file will be saved.
 * @throws IOException If you init it before start stream.
 */
public void startRecord(String path) throws IOException {
  if (streaming) {
    mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    if (videoFormat != null) {
      videoTrack = mediaMuxer.addTrack(videoFormat);
    }
    if (audioFormat != null) {
      audioTrack = mediaMuxer.addTrack(audioFormat);
    }
    mediaMuxer.start();
    recording = true;
  } else {
    throw new IOException("Need be called while stream");
  }
}
项目:rtmp-rtsp-stream-client-java    文件:Camera1Base.java   
/**
 * Start record a MP4 video. Need be called while stream.
 *
 * @param path where file will be saved.
 * @throws IOException If you init it before start stream.
 */
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public void startRecord(String path) throws IOException {
  if (streaming) {
    mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    if (videoFormat != null) {
      videoTrack = mediaMuxer.addTrack(videoFormat);
    }
    if (audioFormat != null) {
      audioTrack = mediaMuxer.addTrack(audioFormat);
    }
    mediaMuxer.start();
    recording = true;
  } else {
    throw new IOException("Need be called while stream");
  }
}
项目:GLES2_AUDIO_VIDEO_RECODE    文件:SohuMediaMuxerManager.java   
/**
 * Constructor
 *
 * @param ext extension of output file
 * @throws IOException
 */
public SohuMediaMuxerManager(String ext) throws IOException {
    if (TextUtils.isEmpty(ext)) {
        ext = ".mp4";
    }
    try {
        // 输出文件路径
        mOutputPath = getCaptureFile(ext).toString();
        //
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    // 编码器
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    //
    mEncoderCount = mStatredCount = 0;
    //
    mIsStarted = false;
}
项目:EffectCamera    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:AAVT    文件:CameraRecorder.java   
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;
        }
    }
项目:AAVT    文件:MediaMuxerWraper.java   
public MediaMuxerWraper(String path, int format) throws IOException {
    mMuxer=new MediaMuxer(path,format);
    datas=new LinkedBlockingQueue<>(30);
    recycler=new Recycler<>();
    ThreadFactory factory= Executors.defaultThreadFactory();
    mExec=new ThreadPoolExecutor(1,1,1,TimeUnit.MINUTES,new LinkedBlockingQueue<Runnable>(16),factory);
}
项目:Fatigue-Detection    文件:MMediaMuxer.java   
public MMediaMuxer(File outputFile) {
    // 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.
    try {
        mMuxer = new MediaMuxer(outputFile.toString(),
                MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
        startCount=0;
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:mpeg-encoder    文件:MpegEncoder.java   
/** 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();
}
项目:grafika    文件:SoftInputSurfaceActivity.java   
/**
 * Prepares the video encoder, muxer, and an input surface.
 */
private void prepareEncoder(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, BIT_RATE);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAMES_PER_SECOND);
    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.
    if (VERBOSE) Log.d(TAG, "output will go to " + outputFile);
    mMuxer = new MediaMuxer(outputFile.toString(),
            MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

    mTrackIndex = -1;
    mMuxerStarted = false;
}
项目:grafika    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:MediaCodecRecorder    文件:SyncMediaMuxer.java   
public SyncMediaMuxer(String output) {
    try {
        Log.d(TAG, "SyncMediaMuxer");
        mMediaMuxer = new MediaMuxer(output, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    } catch (IOException e) {
        e.printStackTrace();
    }
    isStarted = false;
}
项目:EasyScreenRecorder    文件:MediaMuxerWrapper.java   
/**
 * Constructor
 * @param file   output file path with file name
 * @throws IOException
 */
public MediaMuxerWrapper(String file) throws IOException {
    try {
        mOutputPath = file;
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStatredCount = 0;
    mIsStarted = false;
}
项目:rtmp-rtsp-stream-client-java    文件:DisplayBase.java   
/**
 * Start record a MP4 video. Need be called while stream.
 *
 * @param path where file will be saved.
 * @throws IOException If you init it before start stream.
 */
public void startRecord(String path) throws IOException {
  if (streaming) {
    mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    videoTrack = mediaMuxer.addTrack(videoFormat);
    audioTrack = mediaMuxer.addTrack(audioFormat);
    mediaMuxer.start();
    recording = true;
  } else {
    throw new IOException("Need be called while stream");
  }
}
项目:rtmp-rtsp-stream-client-java    文件:FromFileBase.java   
/**
 * Start record a MP4 video. Need be called while stream.
 *
 * @param path where file will be saved.
 * @throws IOException If you init it before start stream.
 */
public void startRecord(String path) throws IOException {
  if (streaming) {
    mediaMuxer = new MediaMuxer(path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    videoTrack = mediaMuxer.addTrack(videoFormat);
    mediaMuxer.start();
    recording = true;
  } else {
    throw new IOException("Need be called while stream");
  }
}
项目:EditPhoto    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:EZFilter    文件:MediaMuxerWrapper.java   
/**
 * @param outPath 视频输出路径
 * @throws IOException
 */
public MediaMuxerWrapper(String outPath) throws IOException {
    mOutputPath = outPath;
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStartedCount = 0;
    mIsStarted = false;
}
项目:ScreenRecordCaptureMaster    文件:YXMuxerWrapper.java   
public void prepar(String mOutputPath) {
    try {
        mMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}
项目:MegviiFacepp-Android-SDK    文件:MediaMuxerWrapper.java   
/**
 * Constructor
 * @param ext extension of output file
 * @throws IOException
 */
public MediaMuxerWrapper(String ext) throws IOException {
    if (TextUtils.isEmpty(ext)) ext = ".mp4";
    try {
        mOutputPath = getCaptureFile(Environment.DIRECTORY_MOVIES, ext).toString();
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStatredCount = 0;
    mIsStarted = false;
}
项目:OpenGLESRecorder    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:UVCCameraZxing    文件:MediaMuxerWrapper.java   
/**
 * Constructor
 * @param ext extension of output file
 * @throws IOException
 */
public MediaMuxerWrapper(String ext) throws IOException {
    if (TextUtils.isEmpty(ext)) ext = ".mp4";
    try {
        mOutputPath = getCaptureFile(Environment.DIRECTORY_MOVIES, ext).toString();
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStatredCount = 0;
    mIsStarted = false;
}
项目:libcommon    文件:MediaMovieRecorder.java   
public MediaMovieRecorder(final String output_path,
    final boolean audio_recording, final boolean useVideoMuxer) throws IOException {
    super(output_path);
    mMuxer = useVideoMuxer
        ? new VideoMuxer(output_path)   // API >= 16
        : new MediaMuxerWrapper(output_path, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);  // API >= 18
    new MediaVideoEncoder(this, mMediaCodecCallback);
    if (audio_recording) {
        new MediaAudioEncoder(this, mMediaCodecCallback);
    }
    hasAudioEncoder = audio_recording;
}
项目:Android-Audio-Recorder    文件:MuxerMP4.java   
public void create(EncoderInfo info, MediaFormat format, File out) {
    this.info = info;

    try {
        encoder = MediaCodec.createEncoderByType(format.getString(MediaFormat.KEY_MIME));
        encoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        encoder.start();

        muxer = new MediaMuxer(out.getAbsolutePath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:mediacodec    文件:SoftInputSurfaceActivity.java   
/**
 * Prepares the video encoder, muxer, and an input surface.
 */
private void prepareEncoder(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, BIT_RATE);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAMES_PER_SECOND);
    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.
    if (VERBOSE) Log.d(TAG, "output will go to " + outputFile);
    mMuxer = new MediaMuxer(outputFile.toString(),
            MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

    mTrackIndex = -1;
    mMuxerStarted = false;
}
项目:mediacodec    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:pause-resume-video-recording    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:ScreenRecordingSample    文件:MediaMuxerWrapper.java   
/**
 * Constructor
 * @param _ext extension of output file
 * @throws IOException
 */
public MediaMuxerWrapper(final Context context, final String _ext) throws IOException {
    String ext = _ext;
    if (TextUtils.isEmpty(ext)) ext = ".mp4";
    try {
        mOutputPath = FileUtils.getCaptureFile(context, Environment.DIRECTORY_MOVIES, ext, 0).toString();
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStatredCount = 0;
    mIsStarted = false;
}
项目:HardwareEncodingTest    文件:SoftInputSurfaceActivity.java   
/**
 * Prepares the video encoder, muxer, and an input surface.
 */
private void prepareEncoder(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, BIT_RATE);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAMES_PER_SECOND);
    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.
    if (VERBOSE) Log.d(TAG, "output will go to " + outputFile);
    mMuxer = new MediaMuxer(outputFile.toString(),
            MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

    mTrackIndex = -1;
    mMuxerStarted = false;
}
项目:aimbrain-android-sdk    文件:VideoResizer.java   
private void setupMuxer() {

      try {
         mMuxer = new MediaMuxer( mOutputUri.toString(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4 );
      } catch ( IOException ioe ) {
         throw new RuntimeException( "MediaMuxer creation failed", ioe );
      }
   }
项目:binea_project_for_android    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:binea_project_for_android    文件:MediaMuxerWrapper.java   
/**
 * Constructor
 * @param ext extension of output file
 * @throws IOException
 */
public MediaMuxerWrapper(String ext) throws IOException {
    if (TextUtils.isEmpty(ext)) ext = ".mp4";
    try {
        mOutputPath = getCaptureFile(Environment.DIRECTORY_MOVIES, ext).toString();
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStatredCount = 0;
    mIsStarted = false;
}
项目:binea_project_for_android    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:AndroidPlayground    文件:VideoEncoderCore.java   
/**
 * 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;
}
项目:PerchBroadcast-Android-SDK    文件:AndroidMuxer.java   
private AndroidMuxer(String outputFile, Format format){
    super(outputFile, format);
    try {
        switch(format){
            case MPEG4:
                mMuxer = new MediaMuxer(outputFile, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
                break;
            default:
                throw new IllegalArgumentException("Unrecognized format!");
        }
    } catch (IOException e) {
        throw new RuntimeException("MediaMuxer creation failed", e);
    }
    mStarted = false;
}
项目:AudioVideoRecordingSample    文件:MediaMuxerWrapper.java   
/**
 * Constructor
 * @param ext extension of output file
 * @throws IOException
 */
public MediaMuxerWrapper(String ext) throws IOException {
    if (TextUtils.isEmpty(ext)) ext = ".mp4";
    try {
        mOutputPath = getCaptureFile(Environment.DIRECTORY_MOVIES, ext).toString();
    } catch (final NullPointerException e) {
        throw new RuntimeException("This app has no permission of writing external storage");
    }
    mMediaMuxer = new MediaMuxer(mOutputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mEncoderCount = mStatredCount = 0;
    mIsStarted = false;
}