[英]What is MediaCodec, MediaExtractor and MediaMuxer in android?
[英]getInpuBuffer in Android MediaCodec and MediaMuxer
以下是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函數?
在這種情況下, getInputBuffer
是一個假設的用戶定義函數。 它不是API函數。 上面的評論解釋了它應該做什么。 (注意它實際上不會以它的編寫方式工作,因為isAudioSample變量不能被函數以完全寫入的方式更新。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.