【发布时间】:2016-06-15 06:06:36
【问题描述】:
我正在使用FFmpeg 将三个音频文件合并为一个
- audio.m4a(从资产中获取)
- 录制的音频.m4a(使用 MediaRecorder 录制)
- audio.m4a(从资产中获取)
它在 Android 5.1 以下工作正常,但在 Android 5.1 以上不工作, 在上述 5.1 录制的音频文件中未连接(当我从保存的内部存储中播放时,它的播放良好,它没有损坏的录音)。
我正在使用以下命令来连接音频文件。
File mergedFile = new File(cacheDir + "/" + String.format("merged_file_%s.m4a", System.currentTimeMillis()));
final String[] ffmpegCommand = new String[]{ /* this concat only 1st audio*/
"ffmpeg",
"-f",
"concat",
"-i",
list, /* text file which contains full path of audio files*/
"-c",
"copy",
mergedFile.toString()};
final String[] ffmpegCommand = new String[]{ /*its working but not concat recorded file*/
"-y",
"-i",
"concat:" + getStaticFilePath() + "|" + getRecordedFilePath() + "|" + getStaticFilePath(),
"-c",
"copy",
mergedFile.toString()};
FFmpeg ffmpeg = FFmpeg.getInstance(this);
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onFailure() {
showUnsupportedExceptionDialog();
}
});
} catch (FFmpegNotSupportedException e) {
showUnsupportedExceptionDialog();
}
try {
ffmpeg.execute(ffmpegCommand, new FFmpegExecuteResponseHandler() {
@Override
public void onFailure(String s) {
Log.d(TAG, "FAILED with output : " + s);
}
@Override
public void onSuccess(String s) {
Log.d(TAG, "SUCCESS with output : " + s);
}
@Override
public void onProgress(String s) {
Log.d(TAG, "Started command : ffmpeg " + ffmpegCommand);
}
@Override
public void onStart() {
Log.d(TAG, "Started command : ffmpeg " + ffmpegCommand);
Log.d(TAG, "Processing...");
}
@Override
public void onFinish() {
Log.d(TAG, "Finished command : ffmpeg " + ffmpegCommand);
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
}
列表是一个文本文件,包含我连接的所有音频的路径
#ffmpeg.txt
file '/storage/emulated/0/AudioRecorder/radioStatic.m4a'
file '/storage/emulated/0/AudioRecorder/recordedFile.m4a'
file '/storage/emulated/0/AudioRecorder/radioStatic.m4a'
【问题讨论】:
-
Android 5.1 或 6.0 以上需要运行时权限才能访问存储有获得它们吗?
-
已经为此设置了运行时权限。
-
我找到了解决这个问题的替代方案。我使用
MediaPlayer依次播放所有三个音频。
标签: android audio ffmpeg concatenation android-mediarecorder