Eft*_*ari 1 android ffmpeg execute
在Windows上,我可以使用ffmpeg.exe用以下代码剪切视频
无法在Android中使用ffmpeg。我用gradle在我的应用程序中抓取ffmpeg。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'
}
Run Code Online (Sandbox Code Playgroud)
我的方法中有这些行
VideoIn = getInternalDirectoryPath() + "/Download/Ab.mp4";
VideoOut = getInternalDirectoryPath() + "/Download/Ab1.mp4";
try {
ffmpeg.execute("ffmpeg -i " + VideoIn + " -ss 00:00:03 -c:v libx264 -crf 17 -t 00:00:5 " + VideoOut + " -y",null);
}
catch (FFmpegCommandAlreadyRunningException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
显示此错误:运行exec()时出错。命令:[/ data / data / com.videoeditor.myname.myapp / files / ffmpeg,ffmpeg,-i,/ storage / emulated / 0 / Download / Ab.mp4,-ss,00:00:03,-c: v,libx264,-crf,17,-t,00:00:5,/ storage / emulated / 0 / Download / Ab1.mp4,-y]工作目录:null环境:null
这种方法有什么问题?谢谢你的帮助
好的,我找到了答案:这种使用ffmpeg的方法在cmd中不需要“ ffmpeg”
简单的视频剪辑示例:
/**
* Returns the path to internal storage ex:- /storage/emulated/0
*
* @return
*/
private String getInternalDirectoryPath() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
VideoIn = getInternalDirectoryPath() + "/Download/Ab.mp4";
VideoOut = getInternalDirectoryPath() + "/Download/Ab1.mp4";
private void CutVideo(){
try {
ffmpeg.execute("-i "+VideoIn+" -ss 00:01:00 -to 00:02:00 -c copy "+VideoOut ,
new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
//for logcat
Log.w(null,"Cut started");
}
@Override
public void onProgress(String message) {
//for logcat
Log.w(null,message.toString());
}
@Override
public void onFailure(String message) {
Log.w(null,message.toString());
}
@Override
public void onSuccess(String message) {
Log.w(null,message.toString());
}
@Override
public void onFinish() {
Log.w(null,"Cutting video finished");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
e.printStackTrace();
Log.w(null,e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)