1

下面是一段 Android MediaMuxer API 示例代码: https ://developer.android.com/reference/android/media/MediaMuxer.html

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);我在 MediaCodec.java 和 MediaMuxer.java 中都没有找到这个函数 getInputBuffer,这是用户定义的函数还是 API 函数?

4

1 回答 1

0

在这种情况下,getInputBuffer是一个假设的用户定义函数。它不是 API 函数。它上面的评论解释了它应该做什么。(请注意它实际上不会以它的编写方式工作,因为 isAudioSample 变量也不能由函数以它的确切编写方式更新。)

于 2017-02-08T12:41:53.523 回答