首页 > 解决方案 > 尝试使用 FFmPeg lib 在视频上添加标题

问题描述

我正在使用 Ff-mpeg lib 在视频上添加文本。lib成功加载但在执行时它给了我错误。

这是我的字符串显示错误命令::

String tetxcommand[]=new String[]{"ffmpeg -i /Phone storage/video.mp4 -vf drawtext=text='HELLLLLLO':x=10:y=H-th-10: fontfile=/path/to/font.ttf:fontsize=12:fontcolor=white:shadowcolor=black:shadowx=5:shadowy=5 /Phone storage/video.mp4"};

有我的代码以及我如何使用 FFmpeg lib(我创建了 2 个方法 1 用于加载 ffmpeg 和 1 用于执行,我在成功方法的 loadffmpedlLibrarymethod() 下调用执行方法)

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

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

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

                @Override
                public void onSuccess() {
                    Log.e("ffmpef","load Successfully");
                    ExcuteFfmpefLibrabry(mutevideocommand);
                }

                @Override
                public void onFinish() {}
            });
        } catch (FFmpegNotSupportedException e) {
            // Handle if FFmpeg is not supported by device
            Log.e("ffmpef",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("ffmpef","Exaction Start");
            }

            @Override
            public void onProgress(String message) {}

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

            @Override
            public void onSuccess(String message) {
                Log.e("ffmpef","Video Edited Successfully");
                Log.e("ok",message);
            }

            @Override
            public void onFinish() {

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

输出:

ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8 (GCC)
  configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Unrecognized option 'i /Phone storage/video.mp4 -b:v 2097k -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -strict experimental /Phone storage/video.mp4'.
Error splitting the argument list: Option not found

标签: androidandroid-ffmpeg

解决方案


您必须将参数拆分为单独的字符串对象,因为现在二进制文件将它们视为单个参数。

String tetxcommand[]=new String[]{"-i", "/Phone storage/video.mp4", "-vf", "drawtext=text='HELLLLLLO':x=10:y=H-th-10:fontfile=/path/to/font.ttf:fontsize=12:fontcolor=white:shadowcolor=black:shadowx=5:shadowy=5", "/Phone storage/video.mp4"};

从您发布的代码看来,ffmpeg数组中实际上不需要,只需要实际参数(从关于版本的评论判断)。


推荐阅读