使用FFMPEG在Android中合并两个音频文件

时间:2016-04-06 19:29:15

标签: android audio ffmpeg

我正在开发一个带有两个音频文件的应用程序,并将它们合并到受尊重的频道中。它们被均衡的方式并不像我希望的那样好,所以我想在混合阶段调整每个文件的音量。我在网上看到了几个例子,例如utilitiesthis04-06 12:17:34.079 30975-30975/me.rapchat.rapchat E/Studio Process: WARNING: linker: /data/user/0/me.rapchat.rapchat/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix. 04-06 12:17:34.306 30975-30975/me.rapchat.rapchat E/Studio Process: ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers 04-06 12:17:34.306 30975-30975/me.rapchat.rapchat E/Studio Process: built on Oct 7 2014 15:08:46 with gcc 4.8 (GCC) 04-06 12:17:34.306 30975-30975/me.rapchat.rapchat E/Studio Process: configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags= 04-06 12:17:34.307 30975-30975/me.rapchat.rapchat E/Studio Process: libavutil 54. 7.100 / 54. 7.100 04-06 12:17:34.307 30975-30975/me.rapchat.rapchat E/Studio Process: libavcodec 56. 1.100 / 56. 1.100 04-06 12:17:34.307 30975-30975/me.rapchat.rapchat E/Studio Process: libavformat 56. 4.101 / 56. 4.101 04-06 12:17:34.307 30975-30975/me.rapchat.rapchat E/Studio Process: libavdevice 56. 0.100 / 56. 0.100 04-06 12:17:34.308 30975-30975/me.rapchat.rapchat E/Studio Process: libavfilter 5. 1.100 / 5. 1.100 04-06 12:17:34.308 30975-30975/me.rapchat.rapchat E/Studio Process: libswscale 3. 0.100 / 3. 0.100 04-06 12:17:34.308 30975-30975/me.rapchat.rapchat E/Studio Process: libswresample 1. 1.100 / 1. 1.100 04-06 12:17:34.308 30975-30975/me.rapchat.rapchat E/Studio Process: libpostproc 53. 0.100 / 53. 0.100 04-06 12:17:34.372 30975-30975/me.rapchat.rapchat E/Studio Process: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/me.rapchat.rapchat/cache/recording.m4a': 04-06 12:17:34.373 30975-30975/me.rapchat.rapchat E/Studio Process: Metadata: 04-06 12:17:34.373 30975-30975/me.rapchat.rapchat E/Studio Process: major_brand : mp42 04-06 12:17:34.373 30975-30975/me.rapchat.rapchat E/Studio Process: minor_version : 0 04-06 12:17:34.374 30975-30975/me.rapchat.rapchat E/Studio Process: compatible_brands: isommp42 04-06 12:17:34.374 30975-30975/me.rapchat.rapchat E/Studio Process: creation_time : 2016-04-06 19:17:33 04-06 12:17:34.374 30975-30975/me.rapchat.rapchat E/Studio Process: Duration: 00:00:01.56, start: 0.000000, bitrate: 144 kb/s 04-06 12:17:34.375 30975-30975/me.rapchat.rapchat E/Studio Process: Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s (default) 04-06 12:17:34.375 30975-30975/me.rapchat.rapchat E/Studio Process: Metadata: 04-06 12:17:34.375 30975-30975/me.rapchat.rapchat E/Studio Process: creation_time : 2016-04-06 19:17:33 04-06 12:17:34.375 30975-30975/me.rapchat.rapchat E/Studio Process: handler_name : SoundHandle 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/me.rapchat.rapchat/cache/beats/d3c37d60-ed50-4c00-b454-4e399a7858ff.m4a': 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: Metadata: 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: major_brand : mp42 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: minor_version : 0 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: compatible_brands: mp42isom 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: creation_time : 1993-11-24 14:46:42 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: encoder : Max 0.9.1 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: iTunSMPB : 00000000 00000840 000003c0 000000000035dc00 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: date : 2015 04-06 12:17:34.401 30975-30975/me.rapchat.rapchat E/Studio Process: Duration: 00:01:20.04, start: 0.047891, bitrate: 129 kb/s 04-06 12:17:34.402 30975-30975/me.rapchat.rapchat E/Studio Process: Stream #1:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default) 04-06 12:17:34.402 30975-30975/me.rapchat.rapchat E/Studio Process: Metadata: 04-06 12:17:34.402 30975-30975/me.rapchat.rapchat E/Studio Process: creation_time : 1993-11-24 14:46:42 04-06 12:17:34.404 30975-30975/me.rapchat.rapchat E/Studio Process: [NULL @ 0xb5e4fc00] Unable to find a suitable output format for '[a1][a2]amerge,pan=stereo|c0<c0+c1|c1<c2+c3[aout]' 04-06 12:17:34.404 30975-30975/me.rapchat.rapchat E/Studio Process: [a1][a2]amerge,pan=stereo|c0<c0+c1|c1<c2+c3[aout]: Invalid argument 04-06 12:17:34.407 30975-30975/me.rapchat.rapchat E/Studio Status Failed: WARNING: linker: /data/user/0/me.rapchat.rapchat/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix. ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers built on Oct 7 2014 15:08:46 with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags= libavutil 54. 7.100 / 54. 7.100 libavcodec 56. 1.100 / 56. 1.100 libavformat 56. 4.101 / 56. 4.101 libavdevice 56. 0.100 / 56. 0.100 libavfilter 5. 1.100 / 5. 1.100 libswscale 3. 0.100 / 3. 0.100 libswresample 1. 1.100 / 1. 1.100 libpostproc 53. 0.100 / 53. 0.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/me.rapchat.rapchat/cache/recording.m4a': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2016-04-06 19:17:33 Duration: 00:00:01.56, start: 0.000000, bitrate: 144 kb/s Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s (default) Metadata: creation_time : 2016-04-06 19:17:33 handler_name : SoundHandle Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/data/user/0/me.rapchat.rapchat/cache/beats/d3c37d60-ed50-4c00-b454-4e399a7858ff.m4a': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42isom creation_time : 1993-11-24 14:46:42 encoder : Max 0.9.1 iTunSMPB : 00000000 00000840 000003c0 000000000035dc00 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 date : 2015 Duration: 00:01:20.04, start: 0.047891, bitrate: 129 kb/s Stream #1:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default) Metadata: creation_time : 1993-11-24 14:46:42 [NULL @ 0xb5e4fc00] Unable to find a suitable output format for '[a1][a2]amerge,pan=stereo|c0<c0+c1|c1<c2+c3[aout]' [a1][a2]amerge,pan=stereo|c0<c0+c1|c1<c2+c3[aout]: Invalid argument ..但它们都不适用于我。有人可以指导我朝着正确的方向发展吗?非常感谢!

我正在使用此库执行:this

这是我的代码(编辑)

In [1]: df.head()
Out[1]: 
                   smos_vwc   map_vwc
timestamp  dgg                       
2015-03-31 233862  0.195203  0.315370
           233348  0.321409  0.271887
           233349  0.272508  0.275955
           233350  0.249663  0.279324
           232833  0.269949  0.266547

在这里输入代码

这是我跑步时的错误。

df.groupby(df.index.month)

3 个答案:

答案 0 :(得分:2)

整个过滤器复合体应该是一个字符串,没有空格,或者用引号"括起来,如果有的话。现在,ffmpeg认为复合体在第二个卷过滤器之后结束,并且正在尝试将复合体的其余部分解析为输出标记。

答案 1 :(得分:0)

添加依赖项 实施'com.writingminds:FFmpegAndroid:0.3.2'

布尔布尔mergeAudio(Context context,File [] voiceFile){

    final boolean[] isSuccess = {false};
    File ffmpegFile = new File(getMusicFilename());
    if (ffmpegFile.exists()) {
        ffmpegFile.delete();
    }
    String s = "";
    String s_index = "";
    String fileSize = "n=" + voiceFile.length;

    for (int i = 0; i < voiceFile.length; i++) {

        s = s + "-i " + voiceFile[i].getPath() + " ";
        s_index = s_index + "[" + i + ":0]";

    }

    String str_cmd = s + "-filter_complex " + s_index + "concat=" + fileSize + ":v=0:a=1[out] -map [out] " + getMusicFilename();

    String[] cmd = str_cmd.split(" ");
    FFmpeg ffmpeg = FFmpeg.getInstance(context);
    try {
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
            @Override
            public void onStart() {
            }

            @Override
            public void onFailure() {
            }

            @Override
            public void onSuccess() {
            }

            @Override
            public void onFinish() {
            }
        });
    } catch (FFmpegNotSupportedException e) {
        Log.d("FFmpegNotException_", e.getMessage());
    }


    try {
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
            @Override
            public void onStart() {
            }

            @Override
            public void onProgress(String message) {
                Log.v("onProgress", message);
            }

            @Override
            public void onFailure(String message) {
                Log.v("onFailure", message);
            }

            @Override
            public void onSuccess(String message) {
                isSuccess[0] = true;
                Log.v("onSuccess", message);
            }

            @Override
            public void onFinish() {
                Log.v("finsish", "finish");
            }
        });
    } catch (Exception e) {
        Log.d("NotException_", e.getMessage());
        // Handle if FFmpeg is already running
    } finally {
        if (ffmpeg.isFFmpegCommandRunning()) {
            ffmpeg.killRunningProcesses();
        }
    }

    return isSuccess[0];

}

public static String getMusicFilename() {
    return "/sdcard/podmod/merged_audio.wav";
}

答案 2 :(得分:0)

String[] ffCommand = (cmd).split(" ");
ffmpeg.execute(ffCommand, new ExecuteBinary.....

确保文件路径中没有任何其他空间。