備忘錄_20160105(定位)
修改
回首頁
程式 2026-01-05 11:49:21 1767584961 100
blender 4.3.0 產生字幕 python 程式
blender 4.3.0 產生字幕 python 程式
Blender 4.3.0 → Video Editing
+ → General → Layout
把 3D Viewport 改成 Text Editor
按下 "+ New",貼上程式碼,執行(Run Script)。
切回 "Video Editing" 頁籤,看 Sequencer 的區塊,應該可以看到許多字幕才對。
# frame rate 與 seconds 之間的轉換,再請自行修改。
import bpy
oScene=bpy.context.scene
oFont=bpy.data.fonts.load("c:/windows/fonts/kaiu.ttf")
# 確保 VSE 存在
if not oScene.sequence_editor:
oScene.sequence_editor_create()
oSE=oScene.sequence_editor
for iFrame in range(1, 246, 4):
oTextStrip=oSE.sequences.new_effect(
name="textStrip", # blender 會自動變換名字為流水號,不用怕衝突。
type='TEXT',
channel=2,
frame_start=iFrame,
frame_end=iFrame+3 # not included
)
oTextStrip.text=f"買變壓器~~~{iFrame}"
oTextStrip.font=oFont
oTextStrip.font_size=60
oTextStrip.color=(1, 1, 1, 1) # RGBA,白色
oTextStrip.align_x='CENTER'
oTextStrip.align_y='CENTER'
oTextStrip.location[0]=0.5
oTextStrip.location[1]=0.1