简体   繁体   English

Android - 如何使用 FFmpegKitConfig.setFontDirectory 注册新的 FontConfig

[英]Android - how to register a new FontConfig using FFmpegKitConfig.setFontDirectory

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.我正在使用ffmpeg-kit将字幕刻录成 mp4 文件,根据他们在这里的提示,我需要在Android下注册字体或指定fontconfig配置,但我不知道该怎么做。

in the tips , they suggest to use FFmpegKitConfig.setFontDirectory to register a new FontConfig, so I tried to write the below code :在提示中,他们建议使用FFmpegKitConfig.setFontDirectory注册一个新的 FontConfig,所以我尝试编写以下代码:

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.您没有在force_style指令中指定字体。 Try adding a FontName=fontName option there.尝试在那里添加一个FontName=fontName选项。

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.字体名称映射具有customName -> realName格式。 Your example sets fontName.ttf as custom which is okay but also odd a bit.您的示例将fontName.ttf设置为自定义,这很好,但也有点奇怪。 It has an extension at the end.它的末尾有一个扩展名。 If that's the value given then force_style directive must have FontName=fontName.ttf .如果这是给定的值,则force_style指令必须具有FontName=fontName.ttf

ffmpeg-kit has a separate repository for test applications at https://github.com/tanersener/ffmpeg-kit-test . ffmpeg-kithttps://github.com/tanersener/ffmpeg-kit-test有一个用于测试应用程序的单独存储库。 Test applications provided there have a Subtitle tab to test burning subtitles.那里提供的测试应用程序有一个字幕选项卡来测试刻录字幕。 You can see how FFmpegKitConfig.setFontDirectory is invoked and used there.你可以看到FFmpegKitConfig.setFontDirectory是如何被调用和使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM