FFmpeg Android 连接。 “–safe 0”是无效参数

FFmpeg Android concat. "–safe 0" is an invalid argument

我正在尝试在 Android 上附加两个 .mp4 视频。使用命令出现不安全文件名错误后:

String[] complexCommand = {"ffmpeg", "-f", "concat", "-i", list, "-c", "copy", outputFilePath};

我按照 FFmpeg 文档中的建议添加了字符串“–safe 0”:

String[] complexCommand = {"ffmpeg", "-f", "concat","–safe 0", "-i", list, "-c", "copy", outputFilePath};

但是,FFmpeg 无法识别该命令,并给出此错误消息:

Failure with output
 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 ‘–safe 0'.
Error splitting the argument list: Option not found

我已经尝试过使用短划线 (–) 和 (-) 类型的各种排列,但仍然出现错误。有时,使用某个破折号或根本不使用破折号 returns 会出现稍微不同的错误消息:

Failure with output
I/System.out: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
I/System.out:   built with gcc 4.8 (GCC)
I/System.out:   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=
I/System.out:   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
 Input #0, tty, from '/data/user/0/com.example.cameraapp2/cache/ffmpeg-list1251307830.txt':

Duration: 00:00:00.04, bitrate: 28 kb/s
     Stream #0:0: Video: ansi, pal8, 640x400, 25 fps, 25 tbr, 25 tbn, 25 tbc
 [NULL @ 0xed834600] Unable to find a suitable output format for 'ffmpeg'
 ffmpeg: Invalid argument

然而,我在那里所做的修改(例如删除 "ffmpeg")并没有解决问题。

字符串 list 是文本文件的绝对路径,由我复制的用户 Marc Plano-Lesay 编写的代码生成:

private static String generateList(String[] inputs) {
    File list;
    Writer writer = null;
    try {
        list = File.createTempFile("ffmpeg-list", ".txt");
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)));
        for (String input: inputs) {
            writer.write("file '" + input + "'\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
        return "/";
    } finally {
        try {
            if (writer != null)
                writer.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

这里是引用它的相关代码片段:

inputFilePath1 = "/storage/emulated/0/Pictures/MyCameraApp/VID_20200416_162058.mp4";
inputFilePath2 = "/storage/emulated/0/Pictures/MyCameraApp/VID_20200418_104909.mp4";

String list = generateList(new String[] {inputFilePath1, inputFilePath2});

Android 通常可以很好地找到输入文件,所以我不确定还可以尝试什么。上面的错误消息证实了我的假设,即我是 运行 FFmpeg 0.3.1,应该是最新的。

感谢您的帮助。

将选项和值分开,即 "–safe", "0"

使用连字符,而不是破折号。

正确:-safe
不正确:–safe