表参道高校合唱部 神田沙也加 城田優
mimori mimori
78 subscribers
10,170 views
103

 Published On Apr 17, 2023

#---------------------------------------------------------------------------------#
drawtext filter for "simple" text on video on ffmpeg
#---------------------------------------------------------------------------------#
https://stackoverflow.com/questions/1...
If you need more complex timing, formatting, or dynamic text see the subtitles filter.
https://ffmpeg.org/ffmpeg-filters.htm...

import os;

font = "/System/Library/Fonts/Supplemental/Copperplate.ttc"
font = "/Library/Fonts/Arial Unicode.ttf" # 日本語必要なら
font = "/Library/Fonts/migmix-1p-regular.ttf" # 日本語必要なら
font = "/Library/Fonts/migmix-1p-bold.ttf" # Bold
fontsize = 96

textline = "Beautiful Voices\n表参道高校合唱部"
basefilename = "source.mp4"
outfilename = "darkblue02.mp4"
color = "pink"
box = 1 # 1: shadow on, 0: shadow off
boxcolor = "darkblue"
boxcolor_depth = 0.3
boxborderw = 20
parms = (textline, basefilename, outfilename, font, fontsize, color, box, boxcolor, boxcolor_depth, boxborderw)

def text_on_video(parms, x="center"):
text, basefilename, outfilename, font, fontsize, color, box, boxcolor, boxcolor_depth, boxborderw = parms
if x == "center":
w = "(w-text_w)/2"
h = "(h-text_h)/6*5"
elif x == "left":
w = "10"
h = "h - 200"
else:
w = "0"
y = "0"

ffmpeg_command = f"""ffmpeg -i {basefilename} -vf drawtext="fontfile={font}: \
text={text}: fontcolor={color}: fontsize={fontsize}: box={box}: boxcolor={boxcolor}@{boxcolor_depth}: \
boxborderw={boxborderw}: x={w}: y={h}" -codec:a copy {outfilename}"""

os.system(ffmpeg_command)

text_on_video(parms)
text_on_video(parms, x="left")


''' original centering
def text(text, x="center"):
if x == "center":
w = "(w-text_w)/2"
h = "(h-text_h)/2"
elif x == "left":
w = "10"
h = "h - 30"
else:
w = "0"
y = "0"
'''

show more

Share/Embed