我使用'com.writingminds:FFmpegAndroid:0.3.2'库在我的应用程序中使用ffmpeg。我想在视频中添加文本。我已经添加了库并使用了那里指定的方法。然后我通过了ffmpeg命令作为execute方法的参数。但它显示错误,因为未指定输出文件,但我在命令中添加了一个输出文件。不知道出了什么问题。
我的代码如下:
`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**`
答案 0 :(得分:0)
您的命令格式错误。 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
,但我留下它来展示如何将两个线性过滤器链接在一起。