当我尝试使用ffmpeg android合并文件时出现此错误:
D/myapp: /data/data/myapp/files/concat.txt: Invalid data found when processing input
E/FFmpeg: Error running FFmpeg binary
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Process.exitValue()' on a null object reference
at nl.bravobit.ffmpeg.CommandResult.getOutputFromProcess(CommandResult.java:18)
at nl.bravobit.ffmpeg.FFcommandExecuteAsyncTask.doInBackground(FFcommandExecuteAsyncTask.java:49)
at nl.bravobit.ffmpeg.FFcommandExecuteAsyncTask.doInBackground(FFcommandExecuteAsyncTask.java:12)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
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)
这是我正在使用的图书馆
implementation 'nl.bravobit:android-ffmpeg:1.1.7'
这是我的代码中生成“ concat.txt”文件的部分:
File concatF = new File(dirPath, "concat.txt");
try{
fileWriter = new FileWriter(concatF);
}catch (Exception exc){
return;
}
for(String file : filesToConcat){
try {
fileWriter.append("file '" + file + "'\n");
}catch (Exception exc){
Log.d("myapp", exc);
}
}
try {
fileWriter.append("#");
fileWriter.close();
}catch (Exception exc){
return;
}
这是输出的“ concat.txt”文件(这些文件位于concat.txt文件的同一文件夹中,因此仅输入名称而不包含路径也应起作用):
file 'video1.ts'
file 'video2.ts'
file 'video3.ts'
file 'video4.ts'
file 'video5.ts'
#
这是我的concat命令:
File concatF = new File(dirPath, "concat.txt");
File output = new File(dirPath, "output.ts");
String[] command = new String[]{"-f", "concat", "-safe", "0", "-i", concatF.toString(), "-c", "copy", output.toString()};
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onProgress(String message) {}
@Override
public void onFailure(String message) {}
@Override
public void onSuccess(String message) {
Log.d("myapp", "Success");
}
@Override
public void onFinish() {}
});
此外,在Windows上使用相同的“ concat.txt”和视频文件,上述命令也可以正常工作。 有帮助吗?