Commit d3583746 by xiaoqi

脚本

parent 3406eb5e
Showing with 22 additions and 16 deletions
......@@ -33,7 +33,7 @@ chroma_msize_y:色度矩阵的垂直大小(Y方向)。
chroma_amount:色度锐化强度。
"""
p_enable_denoising = "" # 4:3:6:4 亮度空间去噪强度 亮度时间去噪强度 色度空间去噪强度 色度时间去噪强度
p_enable_color_enhancement = ""#色彩增强
p_enable_color_enhancement = "" # 色彩增强
p_fps = 0
p_vf = ""
......@@ -313,7 +313,7 @@ def convert_to_grayscale(input_folder, output_folder):
convert_png_alpha_2_gray(file_path, output_path)
def check_file_or_dir(userinput, output_name: str = None):
def check_file_or_dir(userinput,output_file_path: str = None, output_name: str = None):
# 检查路径是否存在
if not os.path.exists(userinput):
print(f"路径不存在:{userinput}")
......@@ -326,11 +326,11 @@ def check_file_or_dir(userinput, output_name: str = None):
for dirpath, _, filenames in os.walk(userinput):
for filename in filenames:
full_path = os.path.join(dirpath, filename)
files_to_process.append((full_path, output_name))
files_to_process.append((full_path,output_file_path, output_name))
# 如果是文件,直接添加到待处理列表中
elif os.path.isfile(userinput):
files_to_process.append((userinput, output_name))
files_to_process.append((userinput,output_file_path, output_name))
else:
print(f"路径既不是文件也不是目录:{userinput}")
......@@ -339,12 +339,12 @@ def check_file_or_dir(userinput, output_name: str = None):
# 使用ThreadPoolExecutor来并行处理任务
with ThreadPoolExecutor(max_workers=8) as executor:
# 提交所有任务
futures = {executor.submit(process_webp_file, file_path, out_name): (file_path, out_name) for
file_path, out_name in files_to_process}
futures = {executor.submit(process_webp_file, file_path, output_file_path,out_name): (file_path,output_file_path, out_name) for
file_path,output_file_path, out_name in files_to_process}
# 获取已完成的任务结果
for future in as_completed(futures):
file_path, out_name = futures[future]
file_path, output_file_path,out_name = futures[future]
try:
future.result() # 这里可以获取process_webp_file的返回值(如果有)
except Exception as exc:
......@@ -372,10 +372,10 @@ def check_file_or_dir(userinput, output_name: str = None):
# print(f"路径既不是文件也不是目录:{userinput}")
def process_webp_file(file_path, output_name: str = None):
def process_webp_file(file_path, output_file_path: str = None,output_name: str = None):
if is_webp_animator(file_path):
print(f"正在处理 WebP 文件:{file_path}")
webp2mp4core(file_path, output_name=output_name)
webp2mp4core(file_path, output_file_path=output_file_path,output_name=output_name)
else:
print(f"跳过非 WebP 文件:{file_path}")
......@@ -415,16 +415,19 @@ def get_total_size(input_webp_path_str):
print(f"计入大小:mp4:{output_merge_video_path}")
def webp2mp4core(input_webp_path_str, output_name: str = None):
def webp2mp4core(input_webp_path_str, output_file_path: str = None, output_name: str = None):
print(f"开始将{input_webp_path_str}转成成mp4")
# 原始webp文件的路径对象
webp_path = Path(input_webp_path_str)
mp4_output_path = webp_path.parent
if output_file_path is not None:
mp4_output_path = output_file_path
# 最终合并视频的输出路径保持不变,仍然位于原始webp文件所在目录
if output_name is None:
output_merge_video_path = webp_path.parent / f"{webp_path.stem}.mp4"
output_merge_video_path = mp4_output_path / f"{webp_path.stem}.mp4"
else:
output_merge_video_path = webp_path.parent / f"{webp_path.stem}-{output_name}.mp4"
output_merge_video_path = mp4_output_path / f"{webp_path.stem}-{output_name}.mp4"
if Path(output_merge_video_path).exists():
print(f"文件{output_merge_video_path}已存在跳过生成")
return
......
......@@ -68,7 +68,7 @@ p_bitrate = sys.argv[5] # 第一个参数
p_enable_sharpening = sys.argv[6] # 第一个参数
p_enable_denoising = sys.argv[7] # 第一个参数
p_enable_color_enhancement = sys.argv[8] # 第一个参数
webp_path_or_dir = ""
webp_path_or_dir = sys.argv[9] # 第一个参数
# if not is_null_or_empty(gift_id):
# webp_path_or_dir = find_first_file("webp_dir", gift_id)
# else:
......@@ -90,7 +90,10 @@ print(f"入参:p_bitrate={p_bitrate}")
print(f"入参:p_enable_sharpening={p_enable_sharpening}")
print(f"入参:p_enable_denoising={p_enable_denoising}")
print(f"入参:p_enable_color_enhancement={p_enable_color_enhancement}")
for gift_path in find_files_by_prefixes("webp_dir",gift_id):
print(f"礼物路径{gift_path}")
for gift_path in find_files_by_prefixes("motoring",motoring_id):
for gift_path in find_files_by_prefixes("webp_dir", gift_id):
convert_webp_2_mp4.check_file_or_dir(gift_path, "mp4ConvertResult")
for gift_path in find_files_by_prefixes("motoring", motoring_id):
convert_webp_2_mp4.check_file_or_dir(gift_path, "mp4ConvertResult")
print(f"座驾路径{gift_path}")
if not is_null_or_empty(webp_path_or_dir):
convert_webp_2_mp4.check_file_or_dir(webp_path_or_dir)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment