FFmpeg gives an error while extract MP3 from video

时间:2016-12-02 04:57:17

标签: java android android-studio ffmpeg

I want to execute FFmpeg command for extract audio in MP3 format from video that is in asset folder of the app. For more, refer http://writingminds.github.io/ffmpeg-android-java/

String sourceFilePath = "file:///android_asset/SampleVideo.mp4";
destFilePath = mp3File.getAbsolutePath();

FFmpeg ffmpeg = FFmpeg.getInstance(MainActivity.this);
    try {

        String cmd[] = new String[]{"/data/data/com.example.bansi_vasundhara.videotomp3_demo/files/ffmpeg", "-i", sourceFilePath, "-vn", "-acodec copy", destFilePath};

        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {
                Log.e("gc", "Command Started");
            }

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

            @Override
            public void onFailure(String message) {
                Log.e("gc", "onFailure command" + message);
            }

            @Override
            public void onSuccess(String message) {
                Log.e("gc", "onSuccess command" + message);
            }

            @Override
            public void onFinish() {
                Log.e("gc", "onFinish command");
            }
        });

    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
        e.printStackTrace();
    }

but I get an error. Please suggest any solution.

java.io.IOException: Error running exec(). Command: [/data/data/com.example.bansi_vasundhara.videotomp3_demo/files/ffmpeg, /data/data/com.example.bansi_vasundhara.videotomp3_demo/files/ffmpeg, -i, file:///android_asset/SampleVideo.mp4, -vn, -acodec copy, /storage/sdcard0/VideoToMP3/SampleMP3.mp3] Working Directory: null Environment: null at java.lang.ProcessManager.exec(ProcessManager.java:211) at java.lang.Runtime.exec(Runtime.java:173) at java.lang.Runtime.exec(Runtime.java:128) at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10) at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38) at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.io.IOException: No such file or directory at java.lang.ProcessManager.exec(Native Method) at java.lang.ProcessManager.exec(ProcessManager.java:209)

1 个答案:

答案 0 :(得分:1)

以下命令适用于从视频中提取音频 -

String[] complexCommand = {"-y", "-i", inputFileAbsolutePath, "-vn", "-ar", "44100", "-ac", "2", "-b:a", "256k", "-f", "mp3", outputFileAbsolutePath};

使用ffmpeg编辑视频的完整代码在我的存储库中发布here,其中包括从视频中提取音频