允许跳过下载,并发下载,env和版本更新

This commit is contained in:
2025-07-18 12:32:15 +08:00
parent 13a10b9812
commit 4b080771f6
6 changed files with 39 additions and 18 deletions

9
.env
View File

@@ -1,9 +0,0 @@
TEMPLATE_DIR=template/
API_ENDPOINT=https://zhentuai.com/task/v1
ACCESS_KEY=TEST_ACCESS_KEY
TEMP_DIR=tmp/
#REDIRECT_TO_URL=https://worker-renderworker-re-kekuflqjxx.cn-shanghai.fcapp.run/
# QSV
ENCODER_ARGS="-c:v h264_qsv -global_quality 28 -look_ahead 1"
# NVENC
#ENCODER_ARGS="-c:v h264_nvenc -cq:v 24 -preset:v p7 -tune:v hq -profile:v high"

11
.env.example Normal file
View File

@@ -0,0 +1,11 @@
TEMPLATE_DIR=template/
API_ENDPOINT=https://zhentuai.com/task/v1
ACCESS_KEY=TEST_ACCESS_KEY
TEMP_DIR=tmp/
#REDIRECT_TO_URL=https://renderworker-deuvulkhes.cn-shanghai.fcapp.run/
# QSV
ENCODER_ARGS="-c:v h264_qsv -global_quality 28 -look_ahead 1"
# NVENC
#ENCODER_ARGS="-c:v h264_nvenc -cq:v 24 -preset:v p7 -tune:v hq -profile:v high"
UPLOAD_METHOD="rclone"
RCLONE_REPLACE_MAP="https://oss.zhentuai.com|alioss://frametour-assets,https://frametour-assets.oss-cn-shanghai.aliyuncs.com|alioss://frametour-assets"

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ target/
.venv .venv
venv/ venv/
cython_debug/ cython_debug/
.env

View File

@@ -1,6 +1,7 @@
import json import json
import os.path import os.path
import time import time
from concurrent.futures import ThreadPoolExecutor
from opentelemetry.trace import Status, StatusCode from opentelemetry.trace import Status, StatusCode
@@ -21,8 +22,18 @@ def parse_ffmpeg_task(task_info, template_info):
# 中间片段 # 中间片段
task_params_str = task_info.get("taskParams", "{}") task_params_str = task_info.get("taskParams", "{}")
span.set_attribute("task_params", task_params_str) span.set_attribute("task_params", task_params_str)
task_params = json.loads(task_params_str) task_params: dict = json.loads(task_params_str)
task_params_orig = json.loads(task_params_str) task_params_orig = json.loads(task_params_str)
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]
for param_list in task_params.values():
for param in param_list:
url = param.get("url")
if url.startswith("http"):
_, fn = os.path.split(url)
executor.submit(oss.download_from_oss, url, fn, True)
executor.shutdown(wait=True)
for part in template_info.get("video_parts"): for part in template_info.get("video_parts"):
source, ext_data = parse_video(part.get('source'), task_params, template_info) source, ext_data = parse_video(part.get('source'), task_params, template_info)
if not source: if not source:
@@ -54,10 +65,10 @@ def parse_ffmpeg_task(task_info, template_info):
overall = template_info.get("overall_template") overall = template_info.get("overall_template")
task.center_cut = template_info.get("crop_mode", None) task.center_cut = template_info.get("crop_mode", None)
task.frame_rate = template_info.get("frame_rate", 25) task.frame_rate = template_info.get("frame_rate", 25)
if overall.get('source', ''): # if overall.get('source', ''):
source, ext_data = parse_video(overall.get('source'), task_params, template_info) # source, ext_data = parse_video(overall.get('source'), task_params, template_info)
task.add_inputs(source) # task.add_inputs(source)
task.ext_data = ext_data or {} # task.ext_data = ext_data or {}
for effect in overall.get('effects', []): for effect in overall.get('effects', []):
task.add_effect(effect) task.add_effect(effect)
for lut in overall.get('filters', []): for lut in overall.get('filters', []):
@@ -83,7 +94,7 @@ def parse_video(source, task_params, template_info):
new_sources = _pick_source.get("url") new_sources = _pick_source.get("url")
if new_sources.startswith("http"): if new_sources.startswith("http"):
_, source_name = os.path.split(new_sources) _, source_name = os.path.split(new_sources)
oss.download_from_oss(new_sources, source_name) oss.download_from_oss(new_sources, source_name, True)
return source_name, _pick_source return source_name, _pick_source
return new_sources, _pick_source return new_sources, _pick_source
return os.path.join(template_info.get("local_path"), source), None return os.path.join(template_info.get("local_path"), source), None

View File

@@ -1,6 +1,8 @@
SUPPORT_FEATURE = ( SUPPORT_FEATURE = (
'simple_render_algo', 'simple_render_algo',
'gpu_accelerate', 'gpu_accelerate',
'intel_gpu_accelerate', 'gpu_accelerate',
'rapid_download',
'rclone_upload',
) )
SOFTWARE_VERSION = '0.0.1' SOFTWARE_VERSION = '0.0.2'

View File

@@ -70,9 +70,10 @@ def upload_to_oss(url, file_path):
return False return False
def download_from_oss(url, file_path): def download_from_oss(url, file_path, skip_if_exist=False):
""" """
使用签名URL下载文件到OSS 使用签名URL下载文件到OSS
:param skip_if_exist: 如果存在就不下载了
:param str url: 签名URL :param str url: 签名URL
:param Union[LiteralString, str, bytes] file_path: 文件路径 :param Union[LiteralString, str, bytes] file_path: 文件路径
:return bool: 是否成功 :return bool: 是否成功
@@ -81,6 +82,10 @@ def download_from_oss(url, file_path):
with tracer.start_as_current_span("download_from_oss") as span: with tracer.start_as_current_span("download_from_oss") as span:
span.set_attribute("file.url", url) span.set_attribute("file.url", url)
span.set_attribute("file.path", file_path) span.set_attribute("file.path", file_path)
if skip_if_exist and os.path.exists(file_path):
span.set_attribute("file.exist", True)
span.set_attribute("file.size", os.path.getsize(file_path))
return True
logging.info("download_from_oss: %s", url) logging.info("download_from_oss: %s", url)
file_dir, file_name = os.path.split(file_path) file_dir, file_name = os.path.split(file_path)
if file_dir: if file_dir: