我正在尝试在视频中添加文字,但是我得到了-
Fontconfig错误:无法加载默认配置文件 [Parsed_drawtext_0 @ 0xea1aeaa0]无法初始化fontconfig
在cmd下面使用FFmpeg lib-
添加文本字符串[] cmd =新字符串[] { “ -i”,SavedVideoFilePath,“-vf”,“ drawtext = text =” +“'” + timeStamp +“'” +“: fontfile = / android_asset / fonts / Poppins-Medium.ttf:fontcolor = white: fontsize = 24:x =(w-tw)/ 2:y =(h / PHI)+第一个box = 0:“,”-codec:a“,” copy“, output_path};
日志详细信息-
打开过滤器时出错! 2019-06-10 18:04:58.027 18678-18678 / com.rs.vir.debug E / FFMPEG错误:输出失败: ffmpeg版本n3.0.1版权所有(c)2000-2016 FFmpeg开发人员 内置gcc 4.8(GCC) 配置:--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,现在-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 从'/data/user/0/com.rs.vir.debug/files/VIR_Customer/EVINV12207201906100303240000/Videos/sample.mp4'输入#0,mov,mp4,m4a,3gp,3g2,mj2: 元数据: major_brand:mp42 minor_version:0 compatible_brands:isommp42 creation_time:2019-06-10 12:34:55 com.android.version:8.1.0 持续时间:00:00:06.66,开始:0.000000,比特率:3724 kb / s 流#0:0(eng):视频:h264(高)(avc1 / 0x31637661),yuv420p(电视,smpte170m / smpte170m / bt709),720x480,3464 kb / s,SAR 1:1 DAR 3:2、30.04 fps,30 tbr,90k tbn,180k tbc(默认) 元数据: 旋转90 creation_time:2019-06-10 12:34:55 handler_name:VideoHandle 辅助数据: displaymatrix:-90.00度旋转 流#0:1(eng):音频:aac(LC)(mp4a / 0x6134706D),48000 Hz,立体声,fltp,255 kb / s(默认) 元数据: creation_time:2019-06-10 12:34:55 handler_name:SoundHandle Fontconfig错误:无法加载默认配置文件 [Parsed_drawtext_0 @ 0xea1aeaa0]无法初始化fontconfig [AVFilterGraph @ 0xea1cb040]使用args初始化过滤器'drawtext'时出错 'text = java.util.GregorianCalendar [time = 1560170097814,areFieldsSet = true,areAllFieldsSet = true,lenient = true,zone = libcore.util.ZoneInfo [id =“ Asia / Kolkata”,mRawOffset = 19800000,mEarliestRawOffset = 19800000,mUseDst = false,mDstSavings = 0,transitions = 5],firstDayOfWeek = 2,minimumDaysInFirstWeek = 4,ERA = 1,YEAR = 2019,MONTH = 5,WEEK_OF_YEAR = 24,WEEK_OF_MONTH = 2,DAY_OF_MONTH = 10,DAY_OF_YEAR = 161,DAY_OF_WEEK = 2,DAY_OF_WEEK_IN_MONTH = 2,AM_PM = 1,HOUR = 6,HOUR_OF_DAY = 18,MINUTE = 4,SECOND = 57,MILLISECOND = 814,ZONE_OFFSET = 19800000,DST_OFFSET = 0]: fontfile = / android_asset / fonts / Poppins-Medium.ttf:fontcolor = white: fontsize = 24:x = {w-tw)/ 2:y = {h / PHI)+ th box = 0:' 打开过滤器时出错!
请给我解决方法。
答案 0 :(得分:1)
使用以下方法将文件从资产目录复制到内部存储。
private void copyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("tag", "Failed to get asset file list.", e);
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
String outDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/X/Y/Z/" ;
File outFile = new File(outDir, filename);
out = new FileOutputStream(outFile);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(IOException e) {
Log.e("tag", "Failed to copy asset file: " + filename, e);
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
然后将您的ttf文件路径传递给ffmpeg命令
String[] cmd = new String[] { "-i", savedVideoFilePath, "-vf", "drawtext=text="+"'"+timeStamp+"'"+": fontfile=<YOUR_DIRECTORY_PATH>/Poppins-Medium.ttf: fontcolor=white: fontsize=24: x=(w-tw)/2: y=(h/PHI)+th box=0:","-codec:a" ,"copy" , output_path };
我们只能将"file:///android_assets"
用于Android。但我们不能将其用于本机项目
答案 1 :(得分:1)
我使用的字体问题,将代码更改如下-
mFileFont = new File("/system/fonts/Roboto-Regular.ttf");
if (!mFileFont.exists())
mFileFont = new File("/system/fonts/DroidSerif-Regular.ttf");
String[] cmd = new String[]{
"-i", savedVideoFilePath, "-vf", "drawtext=text=" + "'" + todaysdate
+ "'" + ": fontfile=" + mFileFont.getAbsolutePath() + ":
fontcolor=white: fontsize=24: x=20: y=50: box=0:", "-codec:a", "copy",
"-preset", "ultrafast", "-b:a", "128k", output_path};