FFmpeg Android执行 [英] FFmpeg android execute

查看:142
本文介绍了FFmpeg Android执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上,我可以使用ffmpeg.exe用以下代码剪切视频

On windows I could cut a video with below code with ffmpeg.exe

在android中无法使用ffmpeg. 我用gradle在我的应用中抓取ffmpeg.

Can't use ffmpeg in android. I used gradle to grab ffmpeg in my app.

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]工作目录:null环境:null

Shows this error: Error running exec(). Command: [/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] Working Directory: null Environment: null

此方法有什么问题?谢谢您的帮助

What's wrong with this method? Thanks for your help

推荐答案

好,我找到了答案: 这种使用ffmpeg的方法在cmd中不需要"ffmpeg"

Ok I found the answer: There is no need for "ffmpeg" in cmd with this method of using 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());
        }
}

这篇关于FFmpeg Android执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆