Support multiline captions
This commit is contained in:
parent
aafd856ecc
commit
cfc7e4d32c
2 changed files with 20 additions and 14 deletions
|
|
@ -111,6 +111,7 @@ Optional per-file captions are supported:
|
||||||
```text
|
```text
|
||||||
IMG_001.jpg: Eiffel Tower
|
IMG_001.jpg: Eiffel Tower
|
||||||
IMG_002.jpg: Louvre
|
IMG_002.jpg: Louvre
|
||||||
|
IMG_003.jpg: First line | Second line
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
|
||||||
33
movmaker.py
33
movmaker.py
|
|
@ -451,7 +451,7 @@ def build_video(
|
||||||
filters.append(f"[{current}]copy[{title_label}]")
|
filters.append(f"[{current}]copy[{title_label}]")
|
||||||
|
|
||||||
caption_label = title_label
|
caption_label = title_label
|
||||||
caption_size = subtitle_font_size if title_lines else max(40, height // 18)
|
caption_size = max(16, int((subtitle_font_size if title_lines else max(40, height // 18)) * 0.5))
|
||||||
for idx, caption in enumerate(captions):
|
for idx, caption in enumerate(captions):
|
||||||
if not caption:
|
if not caption:
|
||||||
continue
|
continue
|
||||||
|
|
@ -474,19 +474,24 @@ def build_video(
|
||||||
f"if(lt(t\\,{start + caption_fade:.3f})\\,(t-{start:.3f})/{caption_fade:.3f}\\,"
|
f"if(lt(t\\,{start + caption_fade:.3f})\\,(t-{start:.3f})/{caption_fade:.3f}\\,"
|
||||||
f"if(lt(t\\,{end - caption_fade:.3f})\\,1\\,({end:.3f}-t)/{caption_fade:.3f}))"
|
f"if(lt(t\\,{end - caption_fade:.3f})\\,1\\,({end:.3f}-t)/{caption_fade:.3f}))"
|
||||||
) if caption_fade > 0 else "1"
|
) if caption_fade > 0 else "1"
|
||||||
next_label = f"caption{idx}"
|
caption_lines = [line.strip() for line in caption.split("|") if line.strip()]
|
||||||
filters.append(
|
line_gap = int(caption_size * 1.2)
|
||||||
f"[{caption_label}]drawtext=fontfile='{stamp_bold_font}':text='{drawtext_escape(caption)}':x=(w-text_w)/2:y=h-text_h-62:"
|
block_height = line_gap * (len(caption_lines) - 1)
|
||||||
f"fontsize={caption_size}:fontcolor=white:borderw=1:bordercolor=black:"
|
for line_idx, caption_line in enumerate(caption_lines):
|
||||||
f"alpha='{caption_alpha}':enable='between(t,{start:.3f},{end:.3f})'[{next_label}]"
|
y_expr = f"h-text_h-62-{block_height - line_idx * line_gap}"
|
||||||
)
|
next_label = f"caption{idx}_{line_idx}"
|
||||||
bold_label = f"caption{idx}b"
|
filters.append(
|
||||||
filters.append(
|
f"[{caption_label}]drawtext=fontfile='{stamp_bold_font}':text='{drawtext_escape(caption_line)}':x=(w-text_w)/2:y={y_expr}:"
|
||||||
f"[{next_label}]drawtext=fontfile='{stamp_bold_font}':text='{drawtext_escape(caption)}':x=(w-text_w)/2+1:y=h-text_h-62:"
|
f"fontsize={caption_size}:fontcolor=white:borderw=0:shadowcolor=black@0.75:shadowx=2:shadowy=2:"
|
||||||
f"fontsize={caption_size}:fontcolor=white:borderw=1:bordercolor=black:"
|
f"alpha='{caption_alpha}':enable='between(t,{start:.3f},{end:.3f})'[{next_label}]"
|
||||||
f"alpha='{caption_alpha}':enable='between(t,{start:.3f},{end:.3f})'[{bold_label}]"
|
)
|
||||||
)
|
bold_label = f"caption{idx}_{line_idx}b"
|
||||||
caption_label = bold_label
|
filters.append(
|
||||||
|
f"[{next_label}]drawtext=fontfile='{stamp_bold_font}':text='{drawtext_escape(caption_line)}':x=(w-text_w)/2+1:y={y_expr}:"
|
||||||
|
f"fontsize={caption_size}:fontcolor=white:borderw=0:shadowcolor=black@0.75:shadowx=2:shadowy=2:"
|
||||||
|
f"alpha='{caption_alpha}':enable='between(t,{start:.3f},{end:.3f})'[{bold_label}]"
|
||||||
|
)
|
||||||
|
caption_label = bold_label
|
||||||
|
|
||||||
stamp_size = max(14, height // 65)
|
stamp_size = max(14, height // 65)
|
||||||
stamp_lines = [x for x in [data.title, data.date, data.place] if x]
|
stamp_lines = [x for x in [data.title, data.date, data.place] if x]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue