Custom fonts for subtitles issue

  • Hi,

    I have SSA subtitles (*.ass) with custom fonts that I have as well. I moved them to /storage/.kodi/media/Fonts . So kodi sees these new fonts and I can change default font under "Language --> Subtitle --> Font to use for text subtitles". What I'm trying to achieve is actually to see all these fonts while watching a movie like it's defined in *.ass file when different lines can have different fonts.

    Does anybody know how to make it work? :/

  • Okay, after spending a day playing with this I was able to find interesting Kodi's behavior. For *.ass fonts Kodi actually looks into /usr/share/fonts/ . I'm guessing some library checks this path. Seems like this thing which renders subtitles completely ignores "/storage/.kodi/media/Fonts" and I can't upload custom fonts to "/usr/share/fonts/" because it's read only by default. Trying to find a way to make it open "/storage/.kodi/media/Fonts", will appreciate any help.

    Edited once, last by rooty (December 7, 2017 at 8:50 AM).

  • For a test to confirm your theory mount bind user folder over system one with this command

    Code
    mount --bind /storage/.kodi/media/Fonts /usr/share/fonts

    Note: this is not a solution.

  • vpeter, ah, completely forgot about mount --bind, but YEAP! It works! The theory is confirmed now. Thanks!

    This is how it looks like before any change: Shared album - Stas Rudenko (rooty0) - Google Photos .

    And the result after the binding custom fonts to /usr/share/fonts: Shared album - Stas Rudenko (rooty0) - Google Photos

    P.s. I also have following files at /storage/.kodi/media/Fonts which where created for the fonts: fonts.dir , fonts.scale

    So this is interesting, actually it is related to Xorg . Would be cool to have custom xorg config at /storage/.config , so in this case additional font path can be added

  • For those who can't wait until it will be fixed (like me) I made a nasty hack:

    At the path "/storage" create a new directory with any name (example: fonthack) . Inside the directory create a file (for example runme.sh) and copy content from above to the file and run following command

    Code
    chmod +x runme.sh 

    I've attached dependencies to this post:

    Code
    libfontenc.so.1      mkfontscale
    libfontenc.so.1.0.0

    You need to put these 3 files to your new folder (in example above it's fonthack) .

    You need to run the file (example: runme.sh) every time when new fonts uploaded to /storage/.kodi/media/Fonts or Kodi's hardware was rebooted.

    If everything went ok, you should see following:

    Code
    LibreELEC:~/fonthack # ./runme.sh
    [x] Making a copy of system fonts
    [x] Making an index of font files
    [x] Attaching Kodi's fonts to system
    [x] Done

    That's it. You don't need to restart Kodi or anything else. Should work right away. If you was watching movie while doing this, stop the movie and play again. Cheers

  • Would be cool to have custom xorg config at /storage/.config , so in this case additional font path can be added

    You can have /storage/.config/xorg.conf.

    And instead of mount bind you could use overlay which doesn't need copying file.

  • I think this is easier solution to your problem:

    Code
    ln -s /storage/.kodi/media/Fonts ~/.fonts

    libass can read from system folder or from user home one. But obviously not from .kodi.

    Before

    Code
    11:02:53.015 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: Using default font family: (Favorit, 400, 0) -> /usr/share/fonts/liberation/LiberationSans-Regular.ttf, 0, LiberationSans
    11:02:53.015 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: (Favorit, 400, 0) -> /usr/share/fonts/liberation/LiberationSans-Regular.ttf, 0, LiberationSans
    11:02:53.019 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: Using default font family: (Artist-Modern, 400, 0) -> /usr/share/fonts/liberation/LiberationSans-Regular.ttf, 0, LiberationSans
    11:02:53.019 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: (Artist-Modern, 400, 0) -> /usr/share/fonts/liberation/LiberationSans-Regular.ttf, 0, LiberationSans
    11:02:53.024 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: Using default font family: (Purisa, 400, 0) -> /usr/share/fonts/liberation/LiberationSans-Regular.ttf, 0, LiberationSans
    11:02:53.024 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: (Purisa, 400, 0) -> /usr/share/fonts/liberation/LiberationSans-Regular.ttf, 0, LiberationSans

    after

    Code
    11:17:28.151 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: (Favorit, 400, 0) -> /storage/.local/share/fonts/Favorit.ttf, 0, Favorit
    11:17:28.162 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: (Artist-Modern, 400, 0) -> /storage/.local/share/fonts/Artist-Modern.ttf, 0, Artist-Modern
    11:17:28.164 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: Using default font family: (Purisa, 400, 0) -> /storage/.local/share/fonts/arial.ttf, 0, ArialMT
    11:17:28.164 T:140242383945024   DEBUG: CDVDSubtitlesLibass: [ass] fontselect: (Purisa, 400, 0) -> /storage/.local/share/fonts/arial.ttf, 0, ArialMT

    Final fix: fontconfig: add kodi font folder to a list by vpeter4 · Pull Request #2301 · LibreELEC/LibreELEC.tv · GitHub

  • From the documentation you can use a srt subtitle file and change the size of the font by putting ASS style format KEY=VALUE pairs separated by ,. So,

    Code
    ffmpeg -i input.mp4 -vf subtitles=sub.srt:force_style='FontName=DejaVu Serif,FontSize=24' -vcodec libx264 -acodec copy -q:v 0 -q:a 0 output.mp4

    will put the subtitles with DejaVu font and size 24 while keeps the quality of the video. I've tried myself and it worked.