Introduction to MoviePy TextClip Supports Chinese Character – Python Tutorial

By | June 1, 2023

In this tutorial, we will introduce how to make python moviepy textclip support chinese character. You can learn how to do by our steps.

MoviePy TextClip

It is defined as:

class moviepy.video.VideoClip.TextClip(text=None, filename=None, size=None, color='black', bg_color='transparent', font_size=None, font='Courier', stroke_color=None, stroke_width=1, method='label', kerning=None, align='center', interline=None, tempfilename=None, temptxt=None, transparent=True, remove_temp=True, print_cmd=False)

In order to make TextClip support chinese text, we should:

text: It is a text string that contains chinese character.

font: We should set a correct font that support chinese character

We can use TextClip.list(“font”) to show all fonts in our pc.

For example:

from moviepy.editor import *
print(TextClip.list("font"))

Run this code, we may see:

['04b_21', 'Aharoni-Bold', 'Andalus', 'Angsana-New', 'Angsana-New-Bold', 'Angsana-New-Bold-Italic', 'Angsana-New-Italic', 'AngsanaUPC', 'AngsanaUPC-Bold', 'AngsanaUPC-Bold-Italic', 'AngsanaUPC-Italic', 'Aparajita', 'Aparajita-Bold', 'Aparajita-Italic', 'Arabic-Typesetting', 'Arial', 'Arial-Black', 'Arial-Bold', 'Arial-Bold-Italic', 'Arial-Italic', 'Arial-Narrow', 'Arial-Narrow-Bold', 'Arial-Narrow-Bold-Italic', 'Arial-Narrow-Italic', 'Batang-&-BatangChe-&-Gungsuh-&-GungsuhChe', 'Book-Antiqua-Bold', 'Book-Antiqua-Bold-Italic', 'Book-Antiqua-Italic', 'Bookman-Old-Style', 'Bookman-Old-Style-Bold', 'Bookman-Old-Style-Bold-Italic', 'Bookman-Old-Style-Italic', 'Browallia-New-Bold', 'Browallia-New-Bold-Italic', 'Browallia-New-Italic', 'BrowalliaUPC-Bold', 'BrowalliaUPC-Bold-Italic', 'BrowalliaUPC-Italic', 'Calibri', 'Calibri-Bold', 'Calibri-Bold-Italic', 'Calibri-Italic', 'Cambria-&-Cambria-Math', 'Cambria-Bold', 'Cambria-Bold-Italic', 'Cambria-Italic', 'Candara', 'Candara-Bold', 'Candara-Bold-Italic', 'Candara-Italic', 'Comic-Sans-MS-Bold', 'Consolas', 'Consolas-Bold', 'Consolas-Bold-Italic', 'Consolas-Italic', 'Constantia', 'Constantia-Bold', 'Constantia-Bold-Italic', 'Constantia-Italic', 'Corbel', 'Corbel-Bold', 'Corbel-Bold-Italic', 'Corbel-Italic', 'Cordia-New-Bold', 'Cordia-New-Bold-Italic', 'Cordia-New-Italic', 'CordiaUPC-Bold', 'CordiaUPC-Bold-Italic', 'CordiaUPC-Italic', 'Courier-New', 'Courier-New-Bold', 'Courier-New-Bold-Italic', 'Courier-New-Italic', 'DaunPenh', 'David-Bold', 'DejaVu-Sans-Mono', 'DilleniaUPC-Bold', 'DilleniaUPC-Bold-Italic', 'DilleniaUPC-Italic', 'DokChampa', 'Ebrima', 'Ebrima-Bold', 'Estrangelo-Edessa', 'Euclid', 'Euclid-Bold', 'Euclid-Bold-Italic', 'Euclid-Extra', 'Euclid-Extra-Bold', 'Euclid-Fraktur', 'Euclid-Fraktur-Bold', 'Euclid-Italic', 'Euclid-Math-One', 'Euclid-Math-One-Bold', 'Euclid-Math-Two', 'Euclid-Math-Two-Bold', 'Euclid-Symbol', 'Euclid-Symbol-Bold', 'Euclid-Symbol-Bold-Italic', 'Euclid-Symbol-Italic', 'EucrosiaUPC-Bold', 'EucrosiaUPC-Bold-Italic', 'EucrosiaUPC-Italic', 'Euphemia', 'FangSong', 'Fences-Plain', 'Franklin-Gothic-Medium-Italic', 'FreesiaUPC-Bold', 'FreesiaUPC-Bold-Italic', 'FreesiaUPC-Italic', 'Gabriola', 'Garamond', 'Garamond-Bold', 'Garamond-Italic', 'Gautami', 'Gautami-Bold', 'Georgia-Bold', 'Georgia-Bold-Italic', 'Georgia-Italic', 'Gisha-Bold', 'Gulim-&-GulimChe-&-Dotum-&-DotumChe', 'Impact', 'IrisUPC-Bold', 'IrisUPC-Bold-Italic', 'IrisUPC-Italic', 'Iskoola-Pota', 'Iskoola-Pota-Bold', 'JasmineUPC-Bold', 'JasmineUPC-Bold-Italic', 'JasmineUPC-Italic', 'KaiTi', 'Kalinga', 'Kalinga-Bold', 'Kartika', 'Kartika-Bold', 'Khmer-UI', 'Khmer-UI-Bold', 'KodchiangUPC-Bold', 'KodchiangUPC-Bold-Italic', 'KodchiangUPC-Italic', 'Kokila', 'Kokila-Bold', 'Kokila-Italic', 'Lao-UI', 'Lao-UI-Bold', 'Latha', 'Latha-Bold', 'Leelawadee-Bold', 'Levenim-MT-Bold', 'LilyUPC-Bold', 'LilyUPC-Bold-Italic', 'LilyUPC-Italic', 'Lucida-Console', 'Malgun-Gothic', 'Malgun-Gothic-Bold', 'Mangal', 'Mangal-Bold', 'Meiryo-&-Meiryo-Italic-&-Meiryo-UI-&-Meiryo-UI-Italic', 'Meiryo-Bold-&-Meiryo-Bold-Italic-&-Meiryo-UI-Bold-&-Meiryo-UI-Bold-Italic', 'Microsoft-Himalaya', 'Microsoft-JhengHei', 'Microsoft-JhengHei-Bold', 'Microsoft-New-Tai-Lue', 'Microsoft-New-Tai-Lue-Bold', 'Microsoft-PhagsPa', 'Microsoft-PhagsPa-Bold', 'Microsoft-Sans-Serif', 'Microsoft-Tai-Le', 'Microsoft-Tai-Le-Bold', 'Microsoft-YaHei', 'Microsoft-YaHei-Bold', 'Microsoft-Yi-Baiti', 'MingLiU-&-PMingLiU-&-MingLiU_HKSCS', 'MingLiU-ExtB-&-PMingLiU-ExtB-&-MingLiU_HKSCS-ExtB', 'Mongolian-Baiti', 'MS-Gothic-&-MS-PGothic-&-MS-UI-Gothic', 'MS-Mincho-&-MS-PMincho', 'MT-Extra', 'MV-Boli', 'Nyala', 'Palatino-Linotype-Bold', 'Palatino-Linotype-Bold-Italic', 'Palatino-Linotype-Italic', 'Plantagenet-Cherokee', 'Raavi', 'Raavi-Bold', 'Sakkal-Majalla-Bold', 'Segoe-Print-Bold', 'Segoe-Script', 'Segoe-Script-Bold', 'Segoe-UI', 'Segoe-UI-Bold', 'Segoe-UI-Bold-Italic', 'Segoe-UI-Italic', 'Segoe-UI-Light', 'Segoe-UI-Semibold', 'Segoe-UI-Symbol', 'Shonar-Bangla', 'Shonar-Bangla-Bold', 'Shruti', 'Shruti-Bold', 'SimHei', 'Simplified-Arabic-Bold', 'SimSun-&-NSimSun', 'SimSun-ExtB', 'Sylfaen', 'Symbol', 'Tahoma', 'Tahoma-Bold', 'Times-New-Roman', 'Times-New-Roman-Bold', 'Times-New-Roman-Bold-Italic', 'Times-New-Roman-Italic', 'Traditional-Arabic-Bold', 'Trebuchet-MS-Bold', 'Trebuchet-MS-Bold-Italic', 'Trebuchet-MS-Italic', 'Tunga', 'Tunga-Bold', 'Utsaah', 'Utsaah-Bold', 'Utsaah-Italic', 'Vani', 'Vani-Bold', 'Verdana', 'Verdana-Bold', 'Verdana-Bold-Italic', 'Verdana-Italic', 'Vijaya', 'Vijaya-Bold', 'Vrinda', 'Vrinda-Bold', 'Webdings', 'Wingdings']

How to make MoviePy TextClip support chinese character?

If all fonts above can not support, we have to set a font that supports.

For example: font = r”C:\Windows\Fonts\msyh.ttf”

Here msyh.ttf  is a kind of font that support chinese.

Here is an example code:

from moviepy.editor import *
print(TextClip.list("font"))
video = VideoFileClip("3.mp4")
txt_clip = TextClip("TutorialExample\n版权所有",fontsize=12,color='red',font = r"C:\Windows\Fonts\msyh.ttf")
txt_mov = txt_clip.set_position("center").set_duration(video.duration).set_opacity(0.5)
result = CompositeVideoClip([video, txt_mov])
result.write_videofile("3_textclip.mp4")

Run this code, we will see:

Introduction to MoviePy TextClip Supports Chinese Character - Python Tutorial