【问题标题】:ffmpeg error while adding text on video在视频上添加文本时出现ffmpeg错误
【发布时间】:2018-05-27 04:37:05
【问题描述】:

我已经使用 'com.writingminds:FFmpegAndroid:0.3.2' 库在我的应用程序中使用 ffmpeg。我想在视频中添加文本。我已经添加了库并使用了那里指定的方法。然后我通过了ffmpeg 命令作为执行方法的参数。但它显示错误,因为未指定输出文件,但我在命令中添加了输出文件。不知道出了什么问题。

我的代码如下:

 `FFmpeg fFmpeg = FFmpeg.getInstance (MainActivity.this);
            try {
                fFmpeg.loadBinary (new LoadBinaryResponseHandler () {

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

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

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

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

            String[] cmd = {"-y",
                    "-i",
                    "/storage/emulated/0/DCIM/Camera/VID_20171212_120337.mp4",
                    "-vf",
                    "format=yuv444p",
                    "-codec:v",
                    "drawtext=text='Title of this Video': fontcolor=white: fontsize=24: x=(w-tw)/2: y=(h/PHI)+th  box=1: boxcolor=black@0.5",
                    "-c:v copy",
                    "outVideo.mp4"
            };

            try {
                fFmpeg.execute (cmd, new ExecuteBinaryResponseHandler () {

                    @Override
                    public void onStart() {
                        Log.e ("onStart", "onStart execute");
                    }

                    @Override
                    public void onProgress(String message) {
                        Log.e ("onProgress execute", message);
                    }

                    @Override
                    public void onFailure(String message) {
                        Log.e ("onFailure execute", message);
                    }

                    @Override
                    public void onSuccess(String message) {
                        Log.e ("onSuccess execute", message);
                    }

                    @Override
                    public void onFinish() {
                        Log.e ("onFinish execute", "onFinish execute");
                    }
                });
            } catch (FFmpegCommandAlreadyRunningException e) {
                e.printStackTrace ();
                // Handle if FFmpeg is already running
            }`

它显示以下错误:

`onFailure execute: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 4.8 (GCC)

在命令行中找到了尾随选项。

                                                            Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/VID_20171212_120337.mp4':
                                                               Metadata:
                                                                 major_brand     : mp42
                                                                 minor_version   : 0
                                                                 compatible_brands: isommp42
                                                                 creation_time   : 2017-12-12 06:33:43
                                                               Duration: 00:00:04.84, start: 0.000000, bitrate: 8552 kb/s
                                                                 Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 7842 kb/s, SAR 1:1 DAR 16:9, 16.84 fps, 16.67 tbr, 90k tbn, 180k tbc (default)
                                                                 Metadata:
                                                                   rotate          : 90
                                                                   creation_time   : 2017-12-12 06:33:43
                                                                   handler_name    : VideoHandle
                                                                 Side data:
                                                                   displaymatrix: rotation of -90.00 degrees
                                                                 Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
                                                                 Metadata:
                                                                   creation_time   : 2017-12-12 06:33:43
                                                                   handler_name    : SoundHandle
                                                          **At least one output file must be specified**`

【问题讨论】:

  • 这是命令 String[] cmd = {"-y", "-i", "/storage/emulated/0/DCIM/Camera/VID_20171212_120337.mp4", "-vf", "format=yuv444p", "-codec:v", "drawtext=text='这个视频的标题': fontcolor=white: fontsize=24: x=(w-tw)/2: y=(h/PHI) +th box=1: boxcolor=black@0.5", "-c:v copy", "outVideo.mp4" };
  • -y -i input.mp4 -vf format=yuv444p -codec:v drawtext=text='这个视频的标题': fontcolor=white: fontsize=24: x=(w-tw) /2: y=(h/PHI)+th box=1: boxcolor=black@0.5 -c:v copy outVideo.mp4

标签: android video ffmpeg video-streaming android-ffmpeg


【解决方案1】:

您的命令格式错误。 drawtext 是过滤器,不是编解码器,因此需要将其移动到正确的位置:

ffmpeg -y -i input.mp4 -vf "format=yuv444p,drawtext=text='Title of this Video': fontcolor=white: fontsize=24: x=(w-tw)/2: y=(h/PHI)+th box=1: boxcolor=black@0.5" outVideo.mp4
  • 过滤时无法使用-c:v copy,因此我将其删除。

  • 我不知道你为什么想要format=yuv444p,但我留下它是为了展示如何将两个线性过滤器链接在一起。

【讨论】:

  • 现在它显示这个错误:无法为 'fontcolor=white:' fontcolor=white:: Invalid argument找到合适的输出格式
猜你喜欢
  • 2016-05-22
  • 2022-06-14
  • 1970-01-01
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-13
  • 2023-03-09
相关资源
最近更新 更多