From 7bcb561a6539b2e0973254b2e3ed0fdd26b45a50 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 24 Dec 2024 14:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/ffmpeg.py | 5 ++++- biz/task.py | 9 ++------- config/__init__.py | 2 +- entity/ffmpeg.py | 6 ++++++ index.py | 3 ++- template/__init__.py | 2 ++ util/api.py | 5 +++++ util/ffmpeg.py | 3 +++ util/oss.py | 5 +++-- 9 files changed, 28 insertions(+), 12 deletions(-) diff --git a/biz/ffmpeg.py b/biz/ffmpeg.py index e8c38ef..941b0c9 100644 --- a/biz/ffmpeg.py +++ b/biz/ffmpeg.py @@ -33,6 +33,9 @@ def parse_ffmpeg_task(task_info, template_info): task = FfmpegTask(tasks, output_file=output_file) overall = template_info.get("overall_template") task.frame_rate = template_info.get("frame_rate", 25) + if overall.get('source', ''): + source = parse_video(overall.get('source'), task_params, template_info) + task.add_inputs(source) for lut in overall.get('filters', []): task.add_lut(os.path.join(template_info.get("local_path"), lut)) for audio in overall.get('audios', []): @@ -56,7 +59,7 @@ def parse_video(source, task_params, template_info): new_sources = new_sources[0].get("url") if new_sources.startswith("http"): _, source_name = os.path.split(new_sources) - oss.download_from_oss(new_sources, source) + oss.download_from_oss(new_sources, source_name) return source_name return new_sources return os.path.join(template_info.get("local_path"), source) diff --git a/biz/task.py b/biz/task.py index 2eaf62f..c9e08e6 100644 --- a/biz/task.py +++ b/biz/task.py @@ -2,16 +2,11 @@ from template import get_template_def from util import api -def normalize_task(task_info): - ... - return task_info - - def start_task(task_info): from biz.ffmpeg import parse_ffmpeg_task, start_ffmpeg_task, clear_task_tmp_file - task_info = normalize_task(task_info) - api.report_task_start(task_info) + task_info = api.normalize_task(task_info) template_info = get_template_def(task_info.get("templateId")) + api.report_task_start(task_info) ffmpeg_task = parse_ffmpeg_task(task_info, template_info) result = start_ffmpeg_task(ffmpeg_task) if not result: diff --git a/config/__init__.py b/config/__init__.py index 6ee1b9d..f749288 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -4,7 +4,7 @@ from logging.handlers import TimedRotatingFileHandler from dotenv import load_dotenv load_dotenv() -logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(level=logging.INFO) root_logger = logging.getLogger() rf_handler = TimedRotatingFileHandler('all_log.log', when='midnight') rf_handler.setFormatter(logging.Formatter("[%(asctime)s][%(name)s]%(levelname)s - %(message)s")) diff --git a/entity/ffmpeg.py b/entity/ffmpeg.py index cf7cf8c..a728a2e 100644 --- a/entity/ffmpeg.py +++ b/entity/ffmpeg.py @@ -213,6 +213,12 @@ class FfmpegTask(object): output_args.append(f"-map") output_args.append(audio_output_str) return args + input_args + ["-filter_complex", ";".join(filter_args)] + output_args + [self.get_output_file()] + elif self.task_type == 'copy': + if len(self.input_file) == 1: + if type(self.input_file[0]) is str: + if self.input_file[0] == self.get_output_file(): + return None + return args + ["-i", self.input_file[0]] + ["-c", "copy", self.get_output_file()] def set_output_file(self, file=None): if file is None: diff --git a/index.py b/index.py index 30f3593..09197b7 100644 --- a/index.py +++ b/index.py @@ -12,7 +12,8 @@ while True: # print(get_sys_info()) print("waiting for task...") task_list = api.sync_center() + if len(task_list) == 0: + sleep(5) for task in task_list: print("start task:", task) biz.task.start_task(task) - sleep(10000) \ No newline at end of file diff --git a/template/__init__.py b/template/__init__.py index ea37dbe..ed1f572 100644 --- a/template/__init__.py +++ b/template/__init__.py @@ -76,6 +76,8 @@ def get_template_def(template_id): def download_template(template_id): template_info = api.get_template_info(template_id) + if not os.path.isdir(template_info['local_path']): + os.makedirs(template_info['local_path']) # download template assets overall_template = template_info['overall_template'] video_parts = template_info['video_parts'] diff --git a/util/api.py b/util/api.py index 9e04b75..c2773c3 100644 --- a/util/api.py +++ b/util/api.py @@ -9,6 +9,11 @@ session = requests.Session() logger = logging.getLogger(__name__) +def normalize_task(task_info): + ... + return task_info + + def sync_center(): """ 通过接口获取任务 diff --git a/util/ffmpeg.py b/util/ffmpeg.py index 4a024d5..28a4ac8 100644 --- a/util/ffmpeg.py +++ b/util/ffmpeg.py @@ -8,6 +8,9 @@ from entity.ffmpeg import FfmpegTask def start_render(ffmpeg_task: FfmpegTask): print(ffmpeg_task) print(ffmpeg_task.get_ffmpeg_args()) + if not ffmpeg_task.need_run(): + ffmpeg_task.set_output_file(ffmpeg_task.input_file[0]) + return True code = os.system("ffmpeg.exe "+" ".join(ffmpeg_task.get_ffmpeg_args())) return code == 0 diff --git a/util/oss.py b/util/oss.py index 9cf4733..c003c8e 100644 --- a/util/oss.py +++ b/util/oss.py @@ -26,8 +26,9 @@ def download_from_oss(url, file_path): :return bool: 是否成功 """ file_dir, file_name = os.path.split(file_path) - if not os.path.exists(file_dir): - os.makedirs(file_dir) + if file_dir: + if not os.path.exists(file_dir): + os.makedirs(file_dir) try: response = requests.get(url) with open(file_path, 'wb') as f: