我在应用程序中使用WritingMinds/ffmpeg-android-java

这是我的代码

loadFFmpeg();
String cmd="ffmpeg -i /storage/emulated/0/media/audio/a.mp3 -i  /storage/emulated/0/recording.3gp -filter_complex \"[0:a][1:a]amerge=inputs=2[aout]\" -map \"[aout]\" " + outputFile;
executeFFmpeg(cmd.split(" "));


private void loadFFmpeg() {
    FFmpeg ffmpeg = FFmpeg.getInstance(MainActivity.this.getApplicationContext());
    try {
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onFailure() {}

            @Override
            public void onSuccess() {}

            @Override
            public void onFinish() {}
        });
    } catch (FFmpegNotSupportedException e) {
        // Handle if FFmpeg is not supported by device
    }
}

private void executeFFmpeg(String[] cmd)
{
    /*String workFolder = getApplicationContext().getFilesDir() + "/ffmpeg";
    String environment = Environment.getExternalStorageDirectory().getAbsolutePath();
    Map<String, String> map = new HashMap<String, String>();
    map.put("Working Directory", workFolder);
    map.put("Environment",environment);*/
    FFmpeg ffmpeg = FFmpeg.getInstance(MainActivity.this.getApplicationContext());
    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {}

            @Override
            public void onSuccess(String message) {}

            @Override
            public void onFinish() {
                stop.setEnabled(false);
                play.setEnabled(true);
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }
}

但我收到以下错误



我也加了
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />

最佳答案

您的问题是,您在 loadFFmpeg()方法中一次清除了FFmpeg,在中一次执行executeFFmpeg()中取消了FFmpeg的操作。因此在 executeFFmpeg()中,您的ojit_code未加载。

解决方案 :

您的代码应如下所示:

public class Main extends Activity{

FFmpeg ffmpeg;
Context context;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = this;

    loadFFmpeg();
    String cmd="ffmpeg -i /storage/emulated/0/media/audio/a.mp3 -i  /storage    /emulated/0/recording.3gp -filter_complex \"[0:a][1:a]amerge=inputs=2[aout]\" -map \"[aout]\" " + outputFile;
    executeFFmpeg(cmd.split(" "));

}

private void loadFFmpeg() {
    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) {
        // Handle if FFmpeg is not supported by device
    }
}

private void executeFFmpeg(String[] cmd)
{
    try {
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {}

            @Override
            public void onSuccess(String message) {}

            @Override
            public void onFinish() {
                stop.setEnabled(false);
                play.setEnabled(true);
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }
}
}

08-28 22:38