改改bug

This commit is contained in:
Jerry Yan 2025-01-13 10:33:36 +08:00
parent ce469dacf2
commit 92160b05ea
5 changed files with 22 additions and 18 deletions

View File

@ -69,6 +69,7 @@ def parse_video(source, task_params, template_info):
def start_ffmpeg_task(ffmpeg_task):
for task in ffmpeg_task.analyze_input_render_tasks():
start_ffmpeg_task(task)
ffmpeg_task.correct_task_type()
return ffmpeg.start_render(ffmpeg_task)

View File

@ -124,11 +124,11 @@ class FfmpegTask(object):
def get_ffmpeg_args(self):
args = ['-y', '-hide_banner']
video_output_str = "[0:v]"
if self.task_type == 'encode':
# args += ('-hwaccel', 'qsv', '-hwaccel_output_format', 'qsv')
input_args = []
filter_args = []
output_args = ["-shortest", "-c:v", "h264_qsv"]
output_args = ["-shortest", "-c:v", "h264_qsv", "-global_quality", "28", "-look_ahead", "1"]
if self.annexb:
output_args.append("-bsf:v")
output_args.append("h264_mp4toannexb")
@ -192,12 +192,7 @@ class FfmpegTask(object):
f.write("file '"+input_file+"'\n")
elif isinstance(input_file, FfmpegTask):
f.write("file '" + input_file.get_output_file() + "'\n")
input_args.append("-f")
input_args.append("concat")
input_args.append("-safe")
input_args.append("0")
input_args.append("-i")
input_args.append(_tmp_file)
input_args += ("-f", "concat", "-safe", "0", "-i", _tmp_file)
output_args.append("-c:v")
output_args.append("copy")
if len(self.audios) > 0:
@ -207,11 +202,9 @@ class FfmpegTask(object):
output_args.append("copy")
output_args.append("-f")
output_args.append("mp4")
output_args += ("-c:v", "h264_qsv", "-r", "25", "-global_quality", "28", "-look_ahead", "1")
return args + input_args + output_args + [self.get_output_file()]
output_args.append("-c:v")
output_args.append("h264_qsv")
output_args.append("-r")
output_args.append("25")
output_args += ("-c:v", "h264_qsv", "-r", "25", "-global_quality", "28", "-look_ahead", "1")
filter_args = []
video_output_str = "[0:v]"
audio_output_str = "[0:a]"
@ -266,7 +259,12 @@ class FfmpegTask(object):
else:
self.output_file = "rand_" + str(uuid.uuid4()) + ".mp4"
else:
self.output_file = file
if isinstance(file, FfmpegTask):
if file == self:
return
self.output_file = file.get_output_file()
if type(file) is str:
self.output_file = file
def check_annexb(self):
for input_file in self.input_file:

View File

@ -85,11 +85,12 @@ def download_template(template_id):
if 'source' in _template:
if str(_template['source']).startswith("http"):
_, _fn = os.path.split(_template['source'])
oss.download_from_oss(_template['source'], os.path.join(template_info['local_path'], _fn))
new_fp = os.path.join(template_info['local_path'], _fn)
oss.download_from_oss(_template['source'], new_fp)
if _fn.endswith(".mp4"):
from util.ffmpeg import to_annexb
_fn = to_annexb(os.path.join(template_info['local_path'], _fn))
_template['source'] = os.path.relpath(_fn, template_info['local_path'])
new_fp = to_annexb(new_fp)
_template['source'] = os.path.relpath(new_fp, template_info['local_path'])
if 'overlays' in _template:
for i in range(len(_template['overlays'])):
overlay = _template['overlays'][i]

View File

@ -139,6 +139,7 @@ def report_task_failed(task_info):
def upload_task_file(task_info, ffmpeg_task):
logger.info("开始上传文件: %s", task_info.get("id"))
try:
response = session.post('{0}/{1}/uploadUrl'.format(os.getenv('API_ENDPOINT'), task_info.get("id")), json={
'accessKey': os.getenv('ACCESS_KEY'),
@ -149,10 +150,13 @@ def upload_task_file(task_info, ffmpeg_task):
return False
data = response.json()
url = data.get('data', "")
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)
except requests.RequestException as e:
logger.error("上传失败!", e)
return False
return True
finally:
logger.info("上传文件结束: %s", task_info.get("id"))
return True

View File

@ -23,11 +23,11 @@ def to_annexb(file):
def start_render(ffmpeg_task: FfmpegTask):
logger.info(ffmpeg_task)
logger.info(ffmpeg_task.get_ffmpeg_args())
if not ffmpeg_task.need_run():
ffmpeg_task.set_output_file(ffmpeg_task.input_file[0])
return True
ffmpeg_args = ffmpeg_task.get_ffmpeg_args()
logger.info(ffmpeg_args)
if len(ffmpeg_args) == 0:
ffmpeg_task.set_output_file(ffmpeg_task.input_file[0])
return True