【问题标题】:concat - audio files using FFmpeg not working in above Android 5.1concat - 使用 FFmpeg 的音频文件无法在 Android 5.1 以上运行
【发布时间】:2016-06-15 06:06:36
【问题描述】:

我正在使用FFmpeg 将三个音频文件合并为一个

  1. audio.m4a(从资产中获取)
  2. 录制的音频.m4a(使用 MediaRecorder 录制)
  3. 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


【解决方案1】:

这对我有用

  val cmd = arrayOf("-y", "-i", audio1!!.path, "-i", audio2!!.path, "-filter_complex"," 
   [0:a] [1:a] concat=n=2:v=0:a=1 [a]","-map","[a]", "-c:a","mp3", outputLocation.path)

【讨论】:

    猜你喜欢
    • 2020-10-17
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多