From 0afbd42fdfefb5cb4bbd802747c6c91d04ac8892 Mon Sep 17 00:00:00 2001 From: personal82555 Date: Mon, 12 Oct 2026 13:41:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=86=E9=A2=91=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B7=BB=E5=8A=A0=E6=B0=B4=E5=8D=B0(?= =?UTF-8?q?=E6=96=87=E5=AD=97/=E4=BD=8D=E7=BD=AE/=E5=AD=97=E5=8F=B7/?= =?UTF-8?q?=E9=A2=9C=E8=89=B2/=E9=80=8F=E6=98=8E=E5=BA=A6,=20=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E5=AD=97=E4=BD=93)=E4=B8=8E=E5=8E=BB=E6=B0=B4?= =?UTF-8?q?=E5=8D=B0(=E9=A2=84=E8=A7=88=E6=8B=96=E6=8B=BD=E6=A1=86?= =?UTF-8?q?=E9=80=89+=E6=99=BA=E8=83=BD=E6=A8=A1=E7=B3=8A),=2011=E2=86=921?= =?UTF-8?q?3=E4=B8=AA=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/it-tools-relay/video_ops.py | 42 ++++++ locales/zh.yml | 2 +- src/tools/video-tools/video-tools.vue | 181 ++++++++++++++++++++++++++ 3 files changed, 224 insertions(+), 1 deletion(-) diff --git a/docker/it-tools-relay/video_ops.py b/docker/it-tools-relay/video_ops.py index affea20..f48b7f1 100644 --- a/docker/it-tools-relay/video_ops.py +++ b/docker/it-tools-relay/video_ops.py @@ -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" diff --git a/locales/zh.yml b/locales/zh.yml index 26f81f0..5b2034a 100644 --- a/locales/zh.yml +++ b/locales/zh.yml @@ -277,7 +277,7 @@ tools: description: '文字转音频(14 种音色)、音频转文字(中英日粤自动检测)、声音克隆等 AI 语音工具' video-tools: title: '视频工具' - description: '视频格式转换、压缩、裁剪、变速、提取音频、GIF 互转等 11 个常用视频处理工具,服务端高速处理' + description: '视频格式转换、压缩、裁剪、变速、水印、去水印、提取音频、GIF 互转等 13 个常用视频处理工具,服务端高速处理' label-designer: title: 面单设计 description: 内置快递面单、物流标签、价格标签等常用模板,导入即可修改;支持上传PDF面单作底图二次编辑(遮盖改字),完成后一键导出PDF打印。 diff --git a/src/tools/video-tools/video-tools.vue b/src/tools/video-tools/video-tools.vue index 3a2103e..bdd309f 100644 --- a/src/tools/video-tools/video-tools.vue +++ b/src/tools/video-tools/video-tools.vue @@ -114,6 +114,32 @@ const GROUPS: { title: string; subtitle: string; tools: VTool[] }[] = [ desc: '移除视频中的全部音轨', tags: ['无损画面', '秒级完成'], }, + { + op: 'watermark', name: '视频添加水印', icon: '💧', color: '#3b82f6', + desc: '给视频添加文字水印,位置颜色透明度可调', + tags: ['文字水印', '中文支持', '位置可调'], + params: [ + { key: 'text', label: '水印文字', type: 'text', def: 'IT-TOOLS-PRO' }, + { key: 'position', label: '位置', type: 'select', def: 'br', options: [ + { label: '右下角', value: 'br' }, { label: '左下角', value: 'bl' }, + { label: '右上角', value: 'tr' }, { label: '左上角', value: 'tl' }, { label: '居中', value: 'c' }, + ] }, + { key: 'fontsize', label: '字号', type: 'slider', min: 12, max: 120, step: 2, def: 40 }, + { key: 'color', label: '颜色', type: 'select', def: 'white', options: [ + { label: '白色', value: 'white' }, { label: '黑色', value: 'black' }, { label: '红色', value: 'red' }, + { label: '黄色', value: 'yellow' }, { label: '青色', value: 'cyan' }, { label: '灰色', value: 'gray' }, + ] }, + { key: 'opacity', label: '透明度', type: 'slider', min: 10, max: 100, step: 5, def: 70, unit: '%' }, + ], + }, + { + op: 'unwatermark', name: '视频去水印', icon: '🩹', color: '#f43f5e', + desc: '在预览画面上拖拽框选水印区域,智能模糊去除', + tags: ['拖拽框选', '智能模糊', '任意背景'], + params: [ + { key: 'sigma', label: '模糊强度', type: 'slider', min: 5, max: 100, step: 5, def: 30 }, + ], + }, ], }, { @@ -190,6 +216,7 @@ function setFile(f: File | null) { file.value = f; error.value = ''; resultBlob.value = null; + selBox.value = null; if (resultUrl.value) { URL.revokeObjectURL(resultUrl.value); resultUrl.value = ''; @@ -211,6 +238,15 @@ async function process() { for (const [k, v] of Object.entries(paramVals.value)) { fd.append(k, String(v)); } + if (currentOp.value === 'unwatermark') { + if (!selBox.value) { + throw new Error('请先在预览画面上拖拽框选水印区域'); + } + fd.append('x', String(selBox.value.x)); + fd.append('y', String(selBox.value.y)); + fd.append('w', String(selBox.value.w)); + fd.append('h', String(selBox.value.h)); + } const res = await fetch('/relay/video', { method: 'POST', body: fd, headers: licenseHeaders() }); if (!res.ok) { const b = await res.json().catch(() => ({})); @@ -252,6 +288,96 @@ function download() { } const isImageResult = computed(() => /\.(png|jpg|jpeg)$/i.test(resultName.value)); + +// ============ 去水印:预览框选 ============ +const selBox = ref<{ x: number; y: number; w: number; h: number } | null>(null); +const previewVideo = ref(); +const selCanvas = ref(); +let dragging = false; +let dragStart = { x: 0, y: 0 }; + +const needSelBox = computed(() => currentOp.value === 'unwatermark'); + +const fileUrl = computed(() => (file.value ? URL.createObjectURL(file.value) : '')); + +function videoBox() { + const v = previewVideo.value; + if (!v) { + return null; + } + const rect = v.getBoundingClientRect(); + const sx = v.videoWidth / rect.width; + const sy = v.videoHeight / rect.height; + return { rect, sx, sy }; +} + +function drawSel(x1: number, y1: number, x2: number, y2: number) { + const v = previewVideo.value; + const c = selCanvas.value; + if (!v || !c) { + return; + } + c.width = v.videoWidth || 640; + c.height = v.videoHeight || 360; + const ctx = c.getContext('2d')!; + ctx.clearRect(0, 0, c.width, c.height); + if (x2 > x1 && y2 > y1) { + ctx.fillStyle = 'rgba(24,160,88,0.25)'; + ctx.fillRect(x1, y1, x2 - x1, y2 - y1); + ctx.strokeStyle = '#18a058'; + ctx.lineWidth = Math.max(2, c.width / 400); + ctx.strokeRect(x1, y1, x2 - x1, y2 - y1); + } +} + +function onSelDown(e: MouseEvent) { + const vb = videoBox(); + if (!vb) { + return; + } + dragging = true; + dragStart = { x: e.clientX - vb.rect.left, y: e.clientY - vb.rect.top }; +} + +function onSelMove(e: MouseEvent) { + if (!dragging) { + return; + } + const vb = videoBox(); + if (!vb) { + return; + } + const x2 = Math.min(vb.rect.width, e.clientX - vb.rect.left); + const y2 = Math.min(vb.rect.height, e.clientY - vb.rect.top); + drawSel(dragStart.x, dragStart.y, Math.max(dragStart.x, x2), Math.max(dragStart.y, y2)); +} + +function onSelUp(e: MouseEvent) { + if (!dragging) { + return; + } + dragging = false; + const vb = videoBox(); + if (!vb) { + return; + } + const x2 = Math.min(vb.rect.width, e.clientX - vb.rect.left); + const y2 = Math.min(vb.rect.height, e.clientY - vb.rect.top); + const x1 = Math.min(dragStart.x, x2); + const y1 = Math.min(dragStart.y, y2); + drawSel(x1, y1, Math.max(x1, x2), Math.max(y1, y2)); + if (x2 - x1 > 8 && y2 - y1 > 8) { + selBox.value = { + x: Math.round(x1 * vb.sx), + y: Math.round(y1 * vb.sy), + w: Math.round((x2 - x1) * vb.sx), + h: Math.round((y2 - y1) * vb.sy), + }; + } + else { + selBox.value = null; + } +} @@ -316,6 +442,27 @@ const isImageResult = computed(() => /\.(png|jpg|jpeg)$/i.test(resultName.value) +
+
+
@@ -485,6 +632,40 @@ const isImageResult = computed(() => /\.(png|jpg|jpeg)$/i.test(resultName.value) } } +.vt-selwrap { + position: relative; + margin-bottom: 10px; + border-radius: 9px; + overflow: hidden; + background: #000; + + .vt-sel-video { + display: block; + width: 100%; + max-height: 240px; + } + + .vt-sel-canvas { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + cursor: crosshair; + } + + .vt-sel-hint { + position: absolute; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.55); + color: #fff; + font-size: 11px; + padding: 4px 10px; + pointer-events: none; + } +} + // ---- panel ---- .vt-panel { border: 1.5px solid rgba(24, 160, 88, 0.4);