From 94a5e687df5db1282c174975c915acdcb9ff7bba Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 8 Feb 2025 15:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E7=94=9F=E6=88=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B8=8A=E6=8A=A5=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + biz/ffmpeg.py | 4 +++- util/api.py | 2 +- util/ffmpeg.py | 13 ++++++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 75e0eb4..6054df3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ build/ dist/ *.mp4 *.ts +rand*.ts tmp_concat_*.txt *.egg-info/ *.egg diff --git a/biz/ffmpeg.py b/biz/ffmpeg.py index d0868ea..047db41 100644 --- a/biz/ffmpeg.py +++ b/biz/ffmpeg.py @@ -84,7 +84,9 @@ def check_placeholder_exist(placeholder_id, task_params): def start_ffmpeg_task(ffmpeg_task): for task in ffmpeg_task.analyze_input_render_tasks(): - start_ffmpeg_task(task) + result = start_ffmpeg_task(task) + if not result: + return False ffmpeg_task.correct_task_type() return ffmpeg.start_render(ffmpeg_task) diff --git a/util/api.py b/util/api.py index 80ad92d..8a55a93 100644 --- a/util/api.py +++ b/util/api.py @@ -168,7 +168,7 @@ def upload_task_file(task_info, ffmpeg_task): logger.info("开始上传文件: %s 至 %s", task_info.get("id"), url) try: with open(ffmpeg_task.get_output_file(), 'rb') as f: - requests.put(url, data=f) + requests.put(url, data=f, headers={"Content-Type": "video/mp4"}) except requests.RequestException as e: logger.error("上传失败!", e) return False diff --git a/util/ffmpeg.py b/util/ffmpeg.py index 0f878d0..ff68a8b 100644 --- a/util/ffmpeg.py +++ b/util/ffmpeg.py @@ -47,7 +47,18 @@ def start_render(ffmpeg_task: FfmpegTask): ffmpeg_process = subprocess.run(["ffmpeg", "-progress", "-", "-loglevel", "error", *ffmpeg_args], **subprocess_args(True)) logger.info("FINISH TASK, OUTPUT IS %s", handle_ffmpeg_output(ffmpeg_process.stdout)) code = ffmpeg_process.returncode - return code == 0 + if code != 0: + logger.error("FFMPEG ERROR: %s", ffmpeg_process.stderr) + return False + try: + out_file_stat = os.stat(ffmpeg_task.output_file) + if out_file_stat.st_size < 4096: + logger.error("FFMPEG ERROR: OUTPUT FILE IS TOO SMALL") + return False + except OSError: + logger.error("FFMPEG ERROR: OUTPUT FILE NOT FOUND") + return False + return True def handle_ffmpeg_output(stdout: Optional[bytes]) -> str: out_time = "0:0:0.0"