Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.1k stars 1.51k forks source link

TextClip Custom Font Not Recognized #2007

Closed makseem77 closed 11 months ago

makseem77 commented 1 year ago

for some reason, I can't use custom fonts when creating a MoviePy TextClip. It says in their documentation that it should be to use all the fonts installed on my system, but when I run this little code snippet in Visual Studio with Python (to get all the possible TextClip fonts):

from moviepy.editor import TextClip

print(TextClip.list("font"))

It prints a list of all the basic fonts that you get when you install Windows, but none of the custom fonts that I installed myself. (And that I can see in the Windows/Fonts directory)

I did some research and it seems that it might be related with ImageMagick, but apparently, on Windows, the fonts should be handled without the user having to do anything. I tried reinstalling ImageMagick, but it didn't solve the issue. I also found a post talking about editing the type-windows.xml file in the ImageMagick config, but when I open it, I see a list of fonts looking like this:

...

 <type name="Arial-Special-G2-Italic" fullname="Arial Special G2 Italic" family="Arial Special G2" weight="400" style="italic" stretch="normal" glyphs="/usr/share/fonts/msttcore/msgeoai2.ttf"/>
  <type name="Bookman-Old-Style" fullname="Bookman Old Style" family="Bookman Old Style" weight="400" style="normal" stretch="normal" glyphs="/usr/share/fonts/msttcore/bkmnos.ttf"/>
  <type name="Bookman-Old-Style-Bold" fullname="Bookman Old Style Bold" family="Bookman Old Style" weight="700" style="normal" stretch="normal" glyphs="/usr/share/fonts/msttcore/bookosb.ttf"/> 

...

But the fonts do not correspond with the one I see when I print the list from TextClip.list + I didn't find anything on how to manually add a font there so I gave up on this lead.

If anyone has some ideas on what I'm doing wrong, it would be greatly appreciated !

ImageMagick version ImageMagick-7.1.1-Q16-HDRI

Operating system Windows 10

Operating system, version and so on Windows 10.0.19044 Build 19044

MoviePy version 1.0.3

keikoro commented 12 months ago

Please always include your specs like we ask for in our issue templates – MoviePy version, platform used etc. – to help pinpoint what causes your problem, thanks.

makseem77 commented 12 months ago

Please always include your specs like we ask for in our issue templates – MoviePy version, platform used etc. – to help pinpoint what causes your problem, thanks.

Sorry for that, just edited my issue.

keikoro commented 12 months ago

Sorry for that, just edited my issue.

Better to put the specs at the bottom of the issue (see other open issues for how it's done when following the template). Subject lines are meant to summarise what issues are about, and shouldn't be hard to parse.

makseem77 commented 12 months ago

Sorry I'm pretty bad at this, can you link me a conventional issue so I can replicate the template ?

keikoro commented 12 months ago

Sorry I'm pretty bad at this, can you link me a conventional issue so I can replicate the template ?

Any recent issue would have done, but no worries, I fixed it for you.

TheHimanshuRastogi commented 12 months ago

To see a list of fonts in your Windows OS, open cmd and type convert -list font, now you'll see a list of fonts installed like this:

Font: Myanmar-Text
family: Myanmar Text
style: Normal
stretch: Normal
weight: 400
glyphs: c:\windows\fonts\mmrtext.ttf

Now find your font, grab its name and use it in the TextClip object like this:

TextClip(
    txt="Hello World",
    size=(850, 1800),
    method='caption',
    fontsize=60,
    color='white',
    font="Myanmar-Text",
    stroke_width=3,
    stroke_color='black'
)

If you want to install font in Linux OS, first navigate to the font path then:

sudo mv path/to/font.otf /usr/share/fonts/
sudo fc-cache -f -v

Repeat same process to get the font name, bla bla...

makseem77 commented 12 months ago

To see a list of fonts in your Windows OS, open cmd and type convert -list font, now you'll see a list of fonts installed like this:

Font: Myanmar-Text
family: Myanmar Text
style: Normal
stretch: Normal
weight: 400
glyphs: c:\windows\fonts\mmrtext.ttf

Now find your font, grab its name and use it in the TextClip object like this:

TextClip(
    txt="Hello World",
    size=(850, 1800),
    method='caption',
    fontsize=60,
    color='white',
    font="Myanmar-Text",
    stroke_width=3,
    stroke_color='black'
)

If you want to install font in Linux OS, first navigate to the font path then:

sudo mv path/to/font.otf /usr/share/fonts/
sudo fc-cache -f -v

Repeat same process to get the font name, bla bla...

Thanks for your answer, but my issue is that whenever I install a font, it doesn't show up in the convert -list font list. I only have in this list the font that are already installed on Windows, but no way to add (or even delete) fonts.

TheHimanshuRastogi commented 12 months ago

Try manual adding fonts to c:\windows\fonts\, maybe it work?

makseem77 commented 12 months ago

Try manual adding fonts to c:\windows\fonts\, maybe it work?

By drag and dropping a .ttf into it right ? I tried it and it didn't solve the issue. I can see all my custom fonts in c:\windows\fonts\ but it doesn't translate in convert -list font.

I also just noticed that when I type convert -list font in cmd in administrator mode, I actually don't get the list, but in normal mode it works. (maybe this could hint something wrong on my ImageMagick installation ?)

TheHimanshuRastogi commented 12 months ago

Btw I also use custom fonts in Windows OS and it works perfect, I don’t know why it’s not working for you? You can give a try to Linux OS.

makseem77 commented 11 months ago

Didn't find the cause of the issue, but what works for me is to simply Right Click + "Install for all users" on my .otf/.ttf files so they end up in the C:\Windows\Fonts location and not in the C:\Users\33628\AppData\Local\Microsoft\Windows\Fonts location.