Skip to content

Commit e2f04e7

Browse files
committed
add video_add_ass_subtitle function.
1 parent 6d86264 commit e2f04e7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

ffmpeg/tools/vtools.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''
22
Date: 2021.03.01 19:46:08
33
LastEditors: Rustle Karl
4-
LastEditTime: 2021.04.25 13:07:29
4+
LastEditTime: 2021.05.24 07:34:01
55
'''
66
import os
77
from pathlib import Path
@@ -140,6 +140,24 @@ def video_add_text_watermark(v_src, dst, *, text: str, x: int = 0, y: int = 0,
140140
stream.output(dst).run()
141141

142142

143+
def video_add_ass_subtitle(v_src, s_src=None, dst=None, keep_audio=True):
144+
if not s_src:
145+
s_src = Path(v_src).with_suffix('.ass')
146+
assert s_src.exists()
147+
148+
if not dst:
149+
path = Path(v_src)
150+
dst = path.with_name(path.stem + '_video_ass.mp4')
151+
152+
v_input = input(v_src)
153+
stream = v_input.ass(filename=str(s_src))
154+
155+
if keep_audio:
156+
stream.output(v_input.audio, dst, acodec="copy").run()
157+
else:
158+
stream.output(dst).run()
159+
160+
143161
def assemble_video_from_images(glob_pattern, dst, *, pattern_type="glob", frame_rate=25):
144162
# https://stackoverflow.com/questions/31201164/ffmpeg-error-pattern-type-glob-was-selected-but-globbing-is-not-support-ed-by
145163
if pattern_type:

0 commit comments

Comments
 (0)