我正在尝试使用来自Github的WritingMinds的Ffmpeg库以编程方式在Android中为视频添加水印:
https://github.com/WritingMinds/ffmpeg-android-java
我做了他们在文档中说的所有内容,并在Android Studio中导入了库。
但是,它给了我一个带有“没有这样的文件或目录”的IOExeption。
CODE
public class MainActivity extends Activity {
Button btn;
Context context;
String str;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
context = this;
str = "ffmpeg -i /storage/extSdCard/DCIM/Camera/video.avi -i /storage/extSdCard/DCIM/Camera/logo.png -filter_complex 'overlay=10:main_h overlay_h-10' /storage/extSdCard/DCIM/Camera/watermarked.avi";
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
doFfmpeg(str.split(" "));
}
});
}
}
public void doFfmpeg(String[] loc){
FFmpeg ffmpeg = FFmpeg.getInstance(context);
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
ffmpeg.execute(loc, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onProgress(String message) {
}
@Override
public void onFailure(String message) {
}
@Override
public void onSuccess(String message) {
Toast.makeText(getApplicationContext(), "Success !", Toast.LENGTH_LONG).show();
}
@Override
public void onFinish() {
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
} catch (Exception e){
}
}
}
日志
691 5092-5311/com.app.watermark.watermark E/FFmpeg: Exception while trying to run: [Ljava.lang.String;@338dbc60
java.io.IOException: Error running exec(). Command: [/data/data/com.app.watermark.watermark/files/ffmpeg, -i, /storage/extSdCard/DCIM/Camera/video.avi, -i, /storage/extSdCard/DCIM/Camera/logo.png, -filter_complex, 'overlay=10:main_h-overlay_h-10', /storage/extSdCard/DCIM/Camera/watermarked.avi] 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)
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)
我该如何做到这一点?
答案 0 :(得分:1)
我用稍微不同的方法解决了它。
我在WarZone上使用了Ffmpeg4Android:
http://androidwarzone.blogspot.ro/2011/12/ffmpeg4android.html
这里告诉你应该如何配置Ffmpeg4Android:
https://docs.google.com/document/d/1FWMAT3FbCXlW_91d6Ek_UCD_CtYJWxYaDVY2hE6Onig/edit
缺点是,如果您想要导入他们的项目,您必须手动将其包含在项目中,这将导致巨大的apk。
虽然目前它运作良好并且确实有效。