I am using ffmpeg-kit to burn a subtitle into a mp4 file , based on their tips here, I need to register a font or specify a fontconfig
configuration under Android
, but I dont know how to do that.
in the tips , they suggest to use FFmpegKitConfig.setFontDirectory
to register a new FontConfig, so I tried to write the below code :
String cmd = "-i " + videoPath + " -vf subtitles=\"" + subtitlePAth + ":force_style='Alignment=10,Fontsize=18\" " +
outputVideoPath;
Map<String, String> mapping= new HashMap<String, String>();
mapping.put("fontName.ttf", "fontName");
FFmpegKitConfig.setFontDirectory(getApplicationContext(),fontDirectoyPath,mapping);
FFmpegKit.executeAsync(cmd, new FFmpegSessionCompleteCallback() {
@Override
public void apply(FFmpegSession session) {
}
}, new LogCallback() {
@Override
public void apply(com.arthenica.ffmpegkit.Log log) {
}
}, new StatisticsCallback() {
@Override
public void apply(Statistics statistics) {
}
});`
but still I am getting this log when run this code
[Parsed_subtitles_0 @ 0xe4bc04c0] Using font provider fontconfig[Parsed_subtitles_0 @ 0xe4bc04c0]
[Parsed_subtitles_0 @ 0xe4bc04c0] fontselect: failed to find any fallback with glyph 0x0 for font: (Arial, 400, 0)[Parsed_subtitles_0 @ 0xe4bc04c0]
any idea please ?
You are not specifying a font in the
force_style
directive. Try adding aFontName=fontName
option there.Also, I don't see the real values you use but your font name mapping may not be correct as well. Font name mappings have a
customName
->realName
format. Your example setsfontName.ttf
as custom which is okay but also odd a bit. It has an extension at the end. If that's the value given thenforce_style
directive must haveFontName=fontName.ttf
.ffmpeg-kit
has a separate repository for test applications at https://github.com/tanersener/ffmpeg-kit-test. Test applications provided there have a Subtitle tab to test burning subtitles. You can see howFFmpegKitConfig.setFontDirectory
is invoked and used there.