gpt4 book ai didi

android - FFmpeg执行命令错误

转载 作者:行者123 更新时间:2023-12-04 23:04:23 24 4
gpt4 key购买 nike

当我使用 ffmpeg 命令将 mp4 转换为 mp3
FFmpeg 命令执行错误-工作目录 null IOEXception
执行下面的代码。

File path=Environment.getExternalStorageDirectory();    
try {
String ffmpegCommand="ffmpeg -i "+path.getAbsolutePath()+"/test/1.mp4 -f avi -acodec mp3 "+path.getAbsolutePath()+"/Songss.avi";
Process ffmpegProcess = new ProcessBuilder(ffmpegCommand).redirectErrorStream(true).start();

String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(ffmpegProcess.getInputStream()));
Log.d("tag", "*******Starting FFMPEG");

while((line = reader.readLine())!=null){

Log.d("tag", "***"+line+"***");
}
Log.d("tag","****ending FFMPEG****");

} catch (IOException e) {
e.printStackTrace(); }

LogCat


java.io.IOException: Error running exec(). Command: [/data/data/com.example.ffmpegcommandexecute/ffmpeg -i /mnt/sdcard/Songs.mp4 -vn -s 00:00:10 -acodec libmp3lame output.mp3]
Working Directory: null Environment: [ANDROID_SOCKET_zygote=10, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar, EXTERNAL_STORAGE_SD=/mnt/ext_card, EXTERNAL_STORAGE_ALL=/mnt/sdcard:/mnt/ext_card, WTLE_VERSION=3.2.0.patch6.1, ANDROID_DATA=/data, LD_LIBRARY_PATH=/vendor/lib:/system/lib, ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=9,65536]
at java.lang.ProcessManager.exec(ProcessManager.java:211)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
at com.example.ffmpegcommandexecute.MJPEGFFMPEGTest$ProcessVideo.doInBackground(MJPEGFFMPEGTest.java:301)
at com.example.ffmpegcommandexecute.MJPEGFFMPEGTest$ProcessVideo.doInBackground(MJPEGFFMPEGTest.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
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)

最佳答案

如果您只想执行命令并且对命令的输出不感兴趣,请使用以下代码:

    try {
Process process= Runtime.getRuntime().exec(YourStringCommand);
process.waitFor();
Log.d(TAG, "Process finished");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

请记住,您的字符串命令必须是这样的:

Your ffmpeg executable file path + all the rest of your command



问题是您需要将此可执行文件放入您的应用程序文件夹(/data/data/yourPackage/),因为权限问题。因此,您应该能够将您的 ffmpeg 文件放入您的包文件夹并更改其权限。

希望有用!!

关于android - FFmpeg执行命令错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20967806/

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