찾다

 >  Q&A  >  본문

Android MediaCodec and MediaMuxer

Android MediaMuxer API 中有这样一段sample code
https://developer.android.com...

 MediaMuxer muxer = new MediaMuxer("temp.mp4", OutputFormat.MUXER_OUTPUT_MPEG_4);
 // More often, the MediaFormat will be retrieved from MediaCodec.getOutputFormat()
 // or MediaExtractor.getTrackFormat().
 MediaFormat audioFormat = new MediaFormat(...);
 MediaFormat videoFormat = new MediaFormat(...);
 int audioTrackIndex = muxer.addTrack(audioFormat);
 int videoTrackIndex = muxer.addTrack(videoFormat);
 ByteBuffer inputBuffer = ByteBuffer.allocate(bufferSize);
 boolean finished = false;
 BufferInfo bufferInfo = new BufferInfo();

 muxer.start();
 while(!finished) {
   // getInputBuffer() will fill the inputBuffer with one frame of encoded
   // sample from either MediaCodec or MediaExtractor, set isAudioSample to
   // true when the sample is audio data, set up all the fields of bufferInfo,
   // and return true if there are no more samples.
   finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo);
   if (!finished) {
     int currentTrackIndex = isAudioSample ? audioTrackIndex : videoTrackIndex;
     muxer.writeSampleData(currentTrackIndex, inputBuffer, bufferInfo);
   }
 };
 muxer.stop();
 muxer.release();
 

这段代码 finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo); 似乎不是API提供的函数,xref里没有搜到,是自定义的函数吗?还是新版本去掉了这个API?

Thanks

ringa_leeringa_lee2772일 전451

모든 응답(2)나는 대답할 것이다

  • 高洛峰

    高洛峰2017-04-18 09:07:59

    MediaCodec의 기능, 이 클래스에 존재하는지 확인

    회신하다
    0
  • 高洛峰

    高洛峰2017-04-18 09:07:59

    샘플 코드이므로 분명히 API 메소드가 아닌 사용자 정의 함수입니다.

    회신하다
    0
  • 취소회신하다