在 Windows 上,我可以使用 ffmpeg.exe 使用以下代码剪切视频
安卓上无法使用ffmpeg。
我使用 gradle 在我的应用程序中获取 ffmpeg。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'
}
我的方法中有这些行
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();
}
显示此错误:运行 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] 工作目录:空 环境:空
这个方法有什么问题吗?感谢您的帮助
好吧,我找到了答案:
这种使用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());
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)