mirror of
https://github.com/woodchen-ink/video2webp.git
synced 2025-07-19 14:31:59 +08:00
Compare commits
1 Commits
v1.0.0-ed4
...
main
Author | SHA1 | Date | |
---|---|---|---|
fdf0d7a770 |
57
gui.py
57
gui.py
@ -326,22 +326,14 @@ class VideoToWebpConverter:
|
|||||||
# 构建命令
|
# 构建命令
|
||||||
cmd = [ffmpeg_exe, "-y", "-threads", str(threads)] # 覆盖输出文件
|
cmd = [ffmpeg_exe, "-y", "-threads", str(threads)] # 覆盖输出文件
|
||||||
|
|
||||||
# 添加时间控制 (仅对视频有效)
|
# 添加输入文件
|
||||||
if not is_gif and start_time > 0:
|
|
||||||
cmd.extend(["-ss", str(start_time)])
|
|
||||||
|
|
||||||
cmd.extend(["-i", input_path])
|
cmd.extend(["-i", input_path])
|
||||||
|
|
||||||
if not is_gif and duration:
|
|
||||||
cmd.extend(["-t", str(float(duration))])
|
|
||||||
|
|
||||||
# 构建滤镜链
|
# 构建滤镜链
|
||||||
filters = []
|
filters = []
|
||||||
|
|
||||||
# FPS控制
|
# FPS控制
|
||||||
if (
|
if not is_gif or self.fps_var.get() != "10":
|
||||||
not is_gif or self.fps_var.get() != "10"
|
|
||||||
): # GIF默认保持原FPS,除非用户修改
|
|
||||||
filters.append(f"fps={fps}")
|
filters.append(f"fps={fps}")
|
||||||
|
|
||||||
# 尺寸控制
|
# 尺寸控制
|
||||||
@ -355,33 +347,33 @@ class VideoToWebpConverter:
|
|||||||
if filters:
|
if filters:
|
||||||
cmd.extend(["-vf", ",".join(filters)])
|
cmd.extend(["-vf", ",".join(filters)])
|
||||||
|
|
||||||
# 添加质量设置
|
# 添加编码器选项
|
||||||
quality = self.quality_var.get()
|
|
||||||
if quality == "high":
|
|
||||||
cmd.extend(["-quality", "90"]) # WebP质量0-100
|
|
||||||
elif quality == "medium":
|
|
||||||
cmd.extend(["-quality", "75"])
|
|
||||||
else:
|
|
||||||
cmd.extend(["-quality", "60"])
|
|
||||||
|
|
||||||
# 设置循环次数 (0表示无限循环)
|
|
||||||
cmd.extend(["-loop", "0"])
|
|
||||||
|
|
||||||
# 添加WebP编码器的特定参数
|
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
[
|
[
|
||||||
"-preset",
|
"-c:v",
|
||||||
"picture", # 使用图片预设
|
"libwebp", # 使用 WebP 编码器
|
||||||
"-compression_level",
|
|
||||||
"4", # 压缩级别 (0-6)
|
|
||||||
"-lossless",
|
"-lossless",
|
||||||
"0", # 使用有损压缩
|
"0", # 使用有损压缩
|
||||||
"-metadata",
|
"-compression_level",
|
||||||
"none", # 不包含元数据
|
"4", # 压缩级别
|
||||||
|
"-preset",
|
||||||
|
"default", # 使用默认预设
|
||||||
|
"-loop",
|
||||||
|
"0", # 无限循环
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# 添加输出文件
|
# 添加质量设置
|
||||||
|
quality = self.quality_var.get()
|
||||||
|
if quality == "high":
|
||||||
|
cmd.extend(["-qscale", "90"]) # WebP质量0-100
|
||||||
|
elif quality == "medium":
|
||||||
|
cmd.extend(["-qscale", "75"])
|
||||||
|
else:
|
||||||
|
cmd.extend(["-qscale", "60"])
|
||||||
|
|
||||||
|
# 规范化输出路径
|
||||||
|
output_path = os.path.normpath(output_path)
|
||||||
cmd.append(output_path)
|
cmd.append(output_path)
|
||||||
|
|
||||||
# 获取subprocess配置
|
# 获取subprocess配置
|
||||||
@ -398,10 +390,11 @@ class VideoToWebpConverter:
|
|||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **subprocess_config
|
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **subprocess_config
|
||||||
)
|
)
|
||||||
_, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
|
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
raise RuntimeError(f"转换失败: {stderr.decode()}")
|
error_message = stderr.decode() if stderr else "未知错误"
|
||||||
|
raise RuntimeError(f"转换失败:\n{error_message}")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user