feat: 视频工具新增添加水印(文字/位置/字号/颜色/透明度, 中文字体)与去水印(预览拖拽框选+智能模糊), 11→13个工具
This commit is contained in:
1 parent
de37b0435e
commit
0afbd42fdf
3 files changed
+224
-1
No files matched your search
@@ -118,6 +118,48 @@ def build_cmd(op: str, fin: str, fout: str, p: dict):
|
||||
ac = ["-c:a", "libvorbis", "-q:a", "5"]
|
||||
return [FFMPEG, "-y", "-i", fin, "-vn"] + ac + [fout], ext.lstrip(".")
|
||||
|
||||
if op == "watermark":
|
||||
# text watermark via drawtext
|
||||
text = str(p.get("text") or "").strip()
|
||||
if not text:
|
||||
raise ValueError("请输入水印文字")
|
||||
text = text.replace("'", "").replace(":", ":").replace("%", "")
|
||||
pos = p.get("position", "br")
|
||||
fs_size = _int(p.get("fontsize"), 12, 200, 36)
|
||||
color = p.get("color", "white")
|
||||
if color not in ("white", "black", "red", "yellow", "cyan", "gray"):
|
||||
color = "white"
|
||||
opacity = max(10, min(100, _int(p.get("opacity"), 10, 100, 70))) / 100.0
|
||||
margin = _int(p.get("margin"), 0, 300, 24)
|
||||
if pos == "tl":
|
||||
xy = f"x={margin}:y={margin}"
|
||||
elif pos == "tr":
|
||||
xy = f"x=w-tw-{margin}:y={margin}"
|
||||
elif pos == "bl":
|
||||
xy = f"x={margin}:y=h-th-{margin}"
|
||||
elif pos == "br":
|
||||
xy = f"x=w-tw-{margin}:y=h-th-{margin}"
|
||||
else: # center
|
||||
xy = "x=(w-tw)/2:y=(h-th)/2"
|
||||
font = "/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc"
|
||||
vf = (f"drawtext=fontfile={font}:text={text}:fontsize={fs_size}"
|
||||
f":fontcolor={color}@{opacity:.2f}:{xy}")
|
||||
return [FFMPEG, "-y", "-i", fin, "-vf", vf, "-c:v", "libx264", "-preset", "fast",
|
||||
"-crf", "20", "-c:a", "copy", "-movflags", "+faststart", fout], "mp4"
|
||||
|
||||
if op == "unwatermark":
|
||||
# remove watermark region: blur overlay (any background) or delogo fill
|
||||
x = _int(p.get("x"), 0, 7680, 0)
|
||||
y = _int(p.get("y"), 0, 4320, 0)
|
||||
w = _int(p.get("w"), 8, 7680, 100)
|
||||
h = _int(p.get("h"), 8, 4320, 100)
|
||||
sigma = _int(p.get("sigma"), 5, 100, 30)
|
||||
fc = (f"[0:v]crop={w}:{h}:{x}:{y},gblur=sigma={sigma}[ck];"
|
||||
f"[0:v][ck]overlay={x}:{y}")
|
||||
return [FFMPEG, "-y", "-i", fin, "-filter_complex", fc, "-c:v", "libx264",
|
||||
"-preset", "fast", "-crf", "20", "-c:a", "copy",
|
||||
"-movflags", "+faststart", fout], "mp4"
|
||||
|
||||
if op == "screenshot":
|
||||
t = max(0.0, _num(p.get("time"), 0, 86400, 0))
|
||||
return [FFMPEG, "-y", "-ss", f"{t:.3f}", "-i", fin, "-frames:v", "1", fout], "png"
|
||||
|
||||
Reference in new issue
Block a user