qsv、对接
This commit is contained in:
parent
fb51d144c0
commit
8d6159d302
@ -1,9 +1,11 @@
|
||||
import json
|
||||
import os.path
|
||||
import time
|
||||
|
||||
from entity.ffmpeg import FfmpegTask
|
||||
import logging
|
||||
|
||||
from util import ffmpeg
|
||||
from util import ffmpeg, oss
|
||||
|
||||
logger = logging.getLogger('biz/ffmpeg')
|
||||
|
||||
@ -11,8 +13,10 @@ logger = logging.getLogger('biz/ffmpeg')
|
||||
def parse_ffmpeg_task(task_info, template_info):
|
||||
tasks = []
|
||||
# 中间片段
|
||||
task_params_str = task_info.get("taskParams", "{}")
|
||||
task_params = json.loads(task_params_str)
|
||||
for part in template_info.get("video_parts"):
|
||||
source = select_video_if_needed(part.get('source'), task_info, template_info)
|
||||
source = parse_video(part.get('source'), task_params, template_info)
|
||||
if not source:
|
||||
logger.warning("no video found for part: " + str(part))
|
||||
continue
|
||||
@ -37,17 +41,22 @@ def parse_ffmpeg_task(task_info, template_info):
|
||||
return task
|
||||
|
||||
|
||||
def select_video_if_needed(source, task_info, template_info):
|
||||
def parse_video(source, task_params, template_info):
|
||||
print(source)
|
||||
if source.startswith('PLACEHOLDER_'):
|
||||
placeholder_id = source.replace('PLACEHOLDER_', '')
|
||||
new_sources = task_info.get('user_videos', {}).get(placeholder_id, [])
|
||||
new_sources = task_params.get(placeholder_id, [])
|
||||
if type(new_sources) is list:
|
||||
if len(new_sources) == 0:
|
||||
logger.debug("no video found for placeholder: " + placeholder_id)
|
||||
return None
|
||||
else:
|
||||
# TODO: Random Pick / Policy Pick
|
||||
new_sources = new_sources[0]
|
||||
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)
|
||||
return source_name
|
||||
return new_sources
|
||||
return os.path.join(template_info.get("local_path"), source)
|
||||
|
||||
|
@ -9,7 +9,6 @@ def normalize_task(task_info):
|
||||
def start_task(task_info):
|
||||
from biz.ffmpeg import parse_ffmpeg_task, start_ffmpeg_task
|
||||
task_info = normalize_task(task_info)
|
||||
task_template = "test_template"
|
||||
template_info = get_template_def(task_template)
|
||||
template_info = get_template_def(task_info.get("templateId"))
|
||||
ffmpeg_task = parse_ffmpeg_task(task_info, template_info)
|
||||
result = start_ffmpeg_task(ffmpeg_task)
|
@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
|
||||
class FfmpegTask(object):
|
||||
|
||||
@ -123,7 +125,7 @@ class FfmpegTask(object):
|
||||
if self.task_type == 'encode':
|
||||
input_args = []
|
||||
filter_args = []
|
||||
output_args = []
|
||||
output_args = ["-shortest", "-c:v h264_qsv"]
|
||||
video_output_str = "[0:v]"
|
||||
audio_output_str = "[0:v]"
|
||||
video_input_count = 0
|
||||
@ -170,8 +172,8 @@ class FfmpegTask(object):
|
||||
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 == 'concat':
|
||||
input_args = ["-hwaccel qsv"]
|
||||
output_args = []
|
||||
input_args = []
|
||||
output_args = ["-shortest", "-c:v", "h264_qsv", "-r", "25"]
|
||||
filter_args = []
|
||||
video_output_str = "[0:v]"
|
||||
audio_output_str = "[0:v]"
|
||||
@ -215,7 +217,6 @@ class FfmpegTask(object):
|
||||
def set_output_file(self, file=None):
|
||||
if file is None:
|
||||
if self.output_file == '':
|
||||
# TODO: Random Filename
|
||||
self.output_file = "rand.mp4"
|
||||
self.output_file = "rand_" + str(uuid.uuid4()) + ".mp4"
|
||||
else:
|
||||
self.output_file = file
|
Loading…
x
Reference in New Issue
Block a user