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"
|
||||
|
||||
+1
-1
@@ -277,7 +277,7 @@ tools:
|
||||
description: '文字转音频(14 种音色)、音频转文字(中英日粤自动检测)、声音克隆等 AI 语音工具'
|
||||
video-tools:
|
||||
title: '视频工具'
|
||||
description: '视频格式转换、压缩、裁剪、变速、提取音频、GIF 互转等 11 个常用视频处理工具,服务端高速处理'
|
||||
description: '视频格式转换、压缩、裁剪、变速、水印、去水印、提取音频、GIF 互转等 13 个常用视频处理工具,服务端高速处理'
|
||||
label-designer:
|
||||
title: 面单设计
|
||||
description: 内置快递面单、物流标签、价格标签等常用模板,导入即可修改;支持上传PDF面单作底图二次编辑(遮盖改字),完成后一键导出PDF打印。
|
||||
|
||||
@@ -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<HTMLVideoElement>();
|
||||
const selCanvas = ref<HTMLCanvasElement>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -316,6 +442,27 @@ const isImageResult = computed(() => /\.(png|jpg|jpeg)$/i.test(resultName.value)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="needSelBox && file" class="vt-selwrap">
|
||||
<video
|
||||
ref="previewVideo"
|
||||
:src="fileUrl"
|
||||
preload="metadata"
|
||||
controls
|
||||
class="vt-sel-video"
|
||||
/>
|
||||
<canvas
|
||||
ref="selCanvas"
|
||||
class="vt-sel-canvas"
|
||||
@mousedown="onSelDown"
|
||||
@mousemove="onSelMove"
|
||||
@mouseup="onSelUp"
|
||||
@mouseleave="onSelUp"
|
||||
/>
|
||||
<div class="vt-sel-hint">
|
||||
{{ selBox ? `✓ 已选区域 x=${selBox.x} y=${selBox.y} ${selBox.w}×${selBox.h}` : '👉 在画面上按住拖拽,框选水印区域' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="current.params?.length" class="vt-params">
|
||||
<div v-for="p in current.params" :key="p.key" class="vt-param">
|
||||
<label class="vt-param-label">{{ p.label }}</label>
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user