2
我當前想要替換.mp4視頻文件的音頻,與另一個.mp3音頻文件。如果替換原始視頻的音頻軌道是不可能的,請給我解決方案以便如何保留兩個音軌並讓用戶在播放時選擇所需的音軌。 我試過使用MediaMuxer和mediaExtractor,但我仍然找不到正確的解決方案。可以請任何人幫助我。替換.mp4文件的音頻軌
在媒體複用器示例程序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();
我使用Android的API 23,我得到錯誤說getInputBuffer和isAudioSample不能得到解決。
MediaFormat audioFormat=new MediaFormat(...);
要我寫什麼內部paranthesis.Where我要提到我的視頻和音頻file.I搜查了很多,請給我一些解決這個問題