From 1119a7b0302054df1ce957d46fa35b7933e1b32e Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 22 Jul 2025 10:44:37 +0800 Subject: [PATCH] =?UTF-8?q?onlyIf=E5=88=A4=E6=96=AD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/ffmpeg.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/biz/ffmpeg.py b/biz/ffmpeg.py index 2d57d5e..74fd90b 100644 --- a/biz/ffmpeg.py +++ b/biz/ffmpeg.py @@ -24,6 +24,13 @@ def parse_ffmpeg_task(task_info, template_info): span.set_attribute("task_params", task_params_str) task_params: dict = json.loads(task_params_str) task_params_orig = json.loads(task_params_str) + + # 统计only_if占位符的使用次数 + only_if_usage_count = {} + for part in template_info.get("video_parts", []): + only_if = part.get('only_if', '') + if only_if: + only_if_usage_count[only_if] = only_if_usage_count.get(only_if, 0) + 1 with tracer.start_as_current_span("parse_ffmpeg_task.download_all") as sub_span: with ThreadPoolExecutor(max_workers=8) as executor: param_list: list[dict] @@ -41,8 +48,9 @@ def parse_ffmpeg_task(task_info, template_info): continue only_if = part.get('only_if', '') if only_if: - if not check_placeholder_exist(only_if, task_params_orig): - logger.info("because only_if exist, placeholder: %s not exist, skip part: %s", only_if, part) + required_count = only_if_usage_count.get(only_if, 1) + if not check_placeholder_exist_with_count(only_if, task_params_orig, required_count): + logger.info("because only_if exist, placeholder: %s insufficient (need %d), skip part: %s", only_if, required_count, part) continue sub_ffmpeg_task = FfmpegTask(source) sub_ffmpeg_task.resolution = template_info.get("video_size", "") @@ -114,6 +122,16 @@ def check_placeholder_exist(placeholder_id, task_params): return False +def check_placeholder_exist_with_count(placeholder_id, task_params, required_count=1): + """检查占位符是否存在足够数量的片段""" + if placeholder_id in task_params: + new_sources = task_params.get(placeholder_id, []) + if type(new_sources) is list: + return len(new_sources) >= required_count + return required_count <= 1 + return False + + def start_ffmpeg_task(ffmpeg_task): tracer = get_tracer(__name__) with tracer.start_as_current_span("start_ffmpeg_task") as span: