mirror of
https://github.com/woodchen-ink/video2gif.git
synced 2025-07-19 14:12:02 +08:00
Compare commits
No commits in common. "main" and "v1.0.0-0f8751a" have entirely different histories.
main
...
v1.0.0-0f8
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
__pycache__/gui.cpython-311.pyc
|
||||
ffmpeg/ffmpeg.exe
|
||||
ffmpeg
|
||||
|
45
gui.py
45
gui.py
@ -140,6 +140,22 @@ class VideoToGifConverter:
|
||||
self.duration_entry.pack(side="left", padx=5)
|
||||
ttk.Label(duration_frame, text="(留空表示全部)").pack(side="left", padx=5)
|
||||
|
||||
# 质量设置
|
||||
quality_frame = ttk.Frame(self.settings_frame)
|
||||
quality_frame.pack(fill="x", padx=5, pady=5)
|
||||
|
||||
ttk.Label(quality_frame, text="质量设置:").pack(side="left", padx=5)
|
||||
self.quality_var = tk.StringVar(value="medium")
|
||||
ttk.Radiobutton(
|
||||
quality_frame, text="高质量", variable=self.quality_var, value="high"
|
||||
).pack(side="left", padx=5)
|
||||
ttk.Radiobutton(
|
||||
quality_frame, text="中等", variable=self.quality_var, value="medium"
|
||||
).pack(side="left", padx=5)
|
||||
ttk.Radiobutton(
|
||||
quality_frame, text="低质量", variable=self.quality_var, value="low"
|
||||
).pack(side="left", padx=5)
|
||||
|
||||
# 输出设置
|
||||
output_frame = ttk.Frame(self.settings_frame)
|
||||
output_frame.pack(fill="x", padx=5, pady=5)
|
||||
@ -204,6 +220,16 @@ class VideoToGifConverter:
|
||||
for file in files:
|
||||
self.files_list.insert(tk.END, file)
|
||||
|
||||
def get_quality_settings(self):
|
||||
"""根据质量设置返回 FFmpeg 调色板生成参数"""
|
||||
quality = self.quality_var.get()
|
||||
if quality == "high":
|
||||
return "max_colors=256"
|
||||
elif quality == "medium":
|
||||
return "max_colors=128"
|
||||
else:
|
||||
return "max_colors=64"
|
||||
|
||||
def validate_inputs(self):
|
||||
"""验证输入参数"""
|
||||
try:
|
||||
@ -303,8 +329,13 @@ class VideoToGifConverter:
|
||||
if duration:
|
||||
palette_cmd.extend(["-t", str(float(duration))])
|
||||
|
||||
# 添加滤镜和输出
|
||||
palette_cmd.extend(["-vf", f"{filter_complex},palettegen", palette_path])
|
||||
# 获取质量设置
|
||||
quality_setting = self.get_quality_settings()
|
||||
|
||||
# 修改调色板生成命令中的滤镜
|
||||
palette_cmd.extend(
|
||||
["-vf", f"{filter_complex},palettegen={quality_setting}", palette_path]
|
||||
)
|
||||
|
||||
# 打印命令用于调试
|
||||
print("调色板生成命令:", " ".join(palette_cmd))
|
||||
@ -327,10 +358,13 @@ class VideoToGifConverter:
|
||||
else 0
|
||||
),
|
||||
)
|
||||
_, stderr = process.communicate()
|
||||
stdout, stderr = process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
raise RuntimeError(f"调色板生成失败: {stderr.decode()}")
|
||||
error_msg = stderr.decode()
|
||||
print(f"调色板生成命令: {' '.join(palette_cmd)}")
|
||||
print(f"错误输出: {error_msg}")
|
||||
raise RuntimeError(f"调色板生成失败: {error_msg}")
|
||||
|
||||
# 更新状态显示
|
||||
self.status_label.config(
|
||||
@ -350,12 +384,13 @@ class VideoToGifConverter:
|
||||
if duration:
|
||||
gif_cmd.extend(["-t", str(float(duration))])
|
||||
|
||||
# 修改 GIF 生成命令中的滤镜
|
||||
gif_cmd.extend(
|
||||
[
|
||||
"-i",
|
||||
palette_path,
|
||||
"-lavfi",
|
||||
f"{filter_complex} [x]; [x][1:v] paletteuse",
|
||||
f"{filter_complex} [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=2",
|
||||
output_path,
|
||||
]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user