gpt4 book ai didi

java - FFmpeg 从视频中提取 MP3 时出错

转载 作者:行者123 更新时间:2023-11-30 00:51:42 24 4
gpt4 key购买 nike

我想执行 FFmpeg 命令以从应用程序 Assets 文件夹中的视频中提取 MP3 格式的音频。更多请引用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();
}

但是我得到一个错误。请提出任何解决方案。

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)

最佳答案

下面的命令适用于我从视频中提取音频-

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

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

关于java - FFmpeg 从视频中提取 MP3 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40925080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com