我有一个从麦克风录制的3gp文件和一个mp4视频文件.我想将音频文件和视频文件复制到mp4文件并保存.我搜索了很多,但没有找到任何有助于使用Android的MediaMuxer api的东西. MediaMuxer api
更新:这是我的方法,mux两个文件,我有一个例外.原因是目标mp4文件没有任何轨道!someOne可以帮助我添加音频和视频轨道到多路复用器?
例外
java.lang.IllegalStateException: Failed to stop the muxer
Run Code Online (Sandbox Code Playgroud)
我的代码:
private void cloneMediaUsingMuxer( String dstMediaPath) throws IOException {
// Set up MediaExtractor to read from the source.
MediaExtractor soundExtractor = new MediaExtractor();
soundExtractor.setDataSource(audioFilePath);
MediaExtractor videoExtractor = new MediaExtractor();
AssetFileDescriptor afd2 = getAssets().openFd("Produce.MP4");
videoExtractor.setDataSource(afd2.getFileDescriptor() , afd2.getStartOffset(),afd2.getLength());
//PATH
//extractor.setDataSource();
int trackCount = soundExtractor.getTrackCount();
int trackCount2 = soundExtractor.getTrackCount();
//assertEquals("wrong number of tracks", expectedTrackCount, trackCount);
// Set up MediaMuxer for the destination.
MediaMuxer muxer;
muxer = new MediaMuxer(dstMediaPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
// Set …
Run Code Online (Sandbox Code Playgroud)