我正在尝试在Androoid Studio中使用FFmpeg lib在视频上添加文本和图像

时间:2019-06-19 10:10:02

标签: android ffmpeg

我正在使用FFmpeg lib通过视频添加文本和通过视频添加图像,但是无法成功。我正在一个真实的设备中测试这个。

我已经尝试了2个命令来添加文本和通过视频添加图像,但是无法获得正确的输出

String command[]={"ffmpeg","-i",inputpath,"-vf", "drawtext="+"\""+"fontfile=/sdcard/retro.ttf: text='Test Text'"+"\"",outputpath};


String addimg[]={"ffmpeg","-i", inputpath,"-i", imagepath ,"-filter_complex", "[0:v][1:v] overlay=25:25:enable='between(t,0,10)'" ,"-pix_fmt", "yuv420p", "-c:a copy",outputpath};

public void LoadFFmpegLibrary()
{
    if(ffmpeg==null)
    {
        ffmpeg = FFmpeg.getInstance(MainActivity.this);
        try {
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

                @Override
                public void onStart() {
                    Log.e("ffmpeg","Start to load");
                }

                @Override
                public void onFailure() {
                    Log.e("ffmpeg","failed to load");
                }

                @Override
                public void onSuccess() {
                    Log.e("ffmpeg","load Successfully");
                    ExcuteFfmpefLibrabry(command);
                    //    Toast.makeText(MainActivity.this,"Success",Toast.LENGTH_LONG).show();
                }

                @Override
                public void onFinish() {
                    Log.e("ffmpeg","failed to load");
                }
            });
        } catch (FFmpegNotSupportedException e) {
            // Handle if FFmpeg is not supported by device
            Log.e("ffmpeg",e.toString());
        }

    }


}

public void ExcuteFfmpefLibrabry(String command[])
{

    ffmpeg = FFmpeg.getInstance(MainActivity.this);
    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {
                Log.e("ffmpeg","Exaction Start");
            }

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {
                Log.e("ffmpeg","failed to Excute Command");
                Log.e("ok",message);
            }

            @Override
            public void onSuccess(String message) {
                Log.e("ffmpeg","Video Edited Successfully");
                Log.e("ok",message);
                // ExcuteFfmpefLibrabry(tetxcommand);
                Toast.makeText(MainActivity.this,"Success",Toast.LENGTH_LONG).show();

            }

            @Override
            public void onFinish() {

            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        Log.e("ffmpeg",e.toString());
    }
}

找不到适用于'ffmpeg'的输出格式     ffmpeg:参数无效

我遇到错误---> Unable to find a suitable output format for 'ffmpeg' ffmpeg: Invalid argument

1 个答案:

答案 0 :(得分:0)

我已经看过您的代码,并知道您正在使用Android的FFMPEG编写思想吗?

而且您的错误也表示ffmpeg无效argumnet意味着在FFMPEG中找不到ffmpeg

当您传递命令来编写构想时

例如:

您传递的命令如:String command[]={"ffmpeg","-i",inputpath,outputpath};

然后ffmpeg执行以下代码::-ffmpeg ffmpeg -i inputpath outputpath

因此ffm​​pef在其构建中找不到名为ffmpeg的参数

因此请更改您的命令

来自

String command[]={"ffmpeg","-i",inputpath,"-vf", "drawtext="+"\""+"fontfile=/sdcard/retro.ttf: text='Test Text'"+"\"",outputpath};


String addimg[]={"ffmpeg","-i", inputpath,"-i", imagepath ,"-filter_complex", "[0:v][1:v] overlay=25:25:enable='between(t,0,10)'" ,"-pix_fmt", "yuv420p", "-c:a copy",outputpath};

String command[]={"-i",inputpath,"-vf", "drawtext=fontfile=/sdcard/retro.ttf: text='Test Text'",outputpath};


String addimg[]={"-i", inputpath,"-i", imagepath ,"-filter_complex", "[0:v][1:v] overlay=25:25:enable='between(t,0,10)'" ,"-pix_fmt", "yuv420p", "-c:a copy",outputpath};