You've already forked FrameTour-RenderWorker
Init
This commit is contained in:
63
util/api.py
Normal file
63
util/api.py
Normal file
@ -0,0 +1,63 @@
|
||||
import requests
|
||||
|
||||
session = requests.Session()
|
||||
|
||||
|
||||
def get_render_task():
|
||||
"""
|
||||
通过接口获取任务
|
||||
:return: 任务列表
|
||||
"""
|
||||
tasks = []
|
||||
tasks.append({
|
||||
'user_videos': {
|
||||
'CAM_ID': 'paper-planes.mp4'
|
||||
}
|
||||
})
|
||||
return tasks
|
||||
|
||||
|
||||
def get_template_info(template_id):
|
||||
"""
|
||||
通过接口获取模板信息
|
||||
:rtype: Template
|
||||
:param template_id: 模板id
|
||||
:type template_id: str
|
||||
:return: 模板信息
|
||||
"""
|
||||
template = {
|
||||
'id': template_id,
|
||||
'name': '模板名称',
|
||||
'description': '模板描述',
|
||||
'video_size': '1920x1080',
|
||||
'frame_rate': 30,
|
||||
'overall_duration': 30,
|
||||
'video_parts': [
|
||||
{
|
||||
'source': './template/test_template/1.mp4',
|
||||
'mute': True,
|
||||
},
|
||||
{
|
||||
'source': 'PLACEHOLDER_CAM_ID',
|
||||
'mute': True,
|
||||
'overlays': [
|
||||
'./template/test_template/2.mov'
|
||||
],
|
||||
'luts': [
|
||||
'./template/test_template/cube.cube'
|
||||
]
|
||||
},
|
||||
{
|
||||
'source': './template/test_template/3.mp4',
|
||||
'mute': True,
|
||||
}
|
||||
],
|
||||
'overall_template': {
|
||||
'source': None,
|
||||
'mute': False,
|
||||
'audios': [
|
||||
'./template/test_template/bgm.acc'
|
||||
]
|
||||
},
|
||||
}
|
||||
return template
|
27
util/ffmpeg.py
Normal file
27
util/ffmpeg.py
Normal file
@ -0,0 +1,27 @@
|
||||
from typing import Optional, IO
|
||||
|
||||
from entity.ffmpeg import FfmpegTask
|
||||
|
||||
|
||||
def start_render(ffmpeg_task: FfmpegTask):
|
||||
print(ffmpeg_task)
|
||||
|
||||
def handle_ffmpeg_output(stdout: Optional[IO[bytes]]) -> str:
|
||||
out_time = "0:0:0.0"
|
||||
if stdout is None:
|
||||
print("[!]STDOUT is null")
|
||||
return out_time
|
||||
speed = "0"
|
||||
while True:
|
||||
line = stdout.readline()
|
||||
if line == b"":
|
||||
break
|
||||
if line.strip() == b"progress=end":
|
||||
# 处理完毕
|
||||
break
|
||||
if line.startswith(b"out_time="):
|
||||
out_time = line.replace(b"out_time=", b"").decode().strip()
|
||||
if line.startswith(b"speed="):
|
||||
speed = line.replace(b"speed=", b"").decode().strip()
|
||||
print("[ ]Speed:", out_time, "@", speed)
|
||||
return out_time
|
17
util/oss.py
Normal file
17
util/oss.py
Normal file
@ -0,0 +1,17 @@
|
||||
import requests
|
||||
|
||||
|
||||
def upload_to_oss_use_signed_url(url, file_path):
|
||||
"""
|
||||
使用签名URL上传文件到OSS
|
||||
:param str url: 签名URL
|
||||
:param str file_path: 文件路径
|
||||
:return bool: 是否成功
|
||||
"""
|
||||
with open(file_path, 'rb') as f:
|
||||
try:
|
||||
response = requests.put(url, data=f)
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
21
util/system.py
Normal file
21
util/system.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
import platform
|
||||
import psutil
|
||||
from constant import SUPPORT_FEATURE, SOFTWARE_VERSION
|
||||
|
||||
|
||||
def get_sys_info():
|
||||
"""
|
||||
Returns a dictionary with system information.
|
||||
"""
|
||||
info = {
|
||||
'version': SOFTWARE_VERSION,
|
||||
'platform': platform.system(),
|
||||
'runtime_version': 'Python ' + platform.python_version(),
|
||||
'cpu_count': os.cpu_count(),
|
||||
'cpu_usage': psutil.cpu_percent(),
|
||||
'memory_total': psutil.virtual_memory().total,
|
||||
'memory_available': psutil.virtual_memory().available,
|
||||
'support_feature': SUPPORT_FEATURE
|
||||
}
|
||||
return info
|
Reference in New Issue
Block a user