You've already forked FrameTour-RenderWorker
hevc+重下模板
This commit is contained in:
@@ -7,5 +7,7 @@ TEMP_DIR=tmp/
|
||||
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"
|
||||
# HEVC
|
||||
#VIDEO_ARGS="-profile:v main
|
||||
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,8 +1,8 @@
|
||||
SUPPORT_FEATURE = (
|
||||
'simple_render_algo',
|
||||
'gpu_accelerate',
|
||||
'gpu_accelerate',
|
||||
'hevc_encode',
|
||||
'rapid_download',
|
||||
'rclone_upload',
|
||||
)
|
||||
SOFTWARE_VERSION = '0.0.2'
|
||||
SOFTWARE_VERSION = '0.0.3'
|
||||
|
@@ -6,11 +6,22 @@ from typing import Any
|
||||
|
||||
DEFAULT_ARGS = ("-shortest",)
|
||||
ENCODER_ARGS = ("-c:v", "h264", ) if not os.getenv("ENCODER_ARGS", False) else os.getenv("ENCODER_ARGS", "").split(" ")
|
||||
VIDEO_ARGS = ("-profile:v", "high", "-level:v", "4", )
|
||||
VIDEO_ARGS = ("-profile:v", "high", "-level:v", "4", ) if not os.getenv("VIDEO_ARGS", False) else os.getenv("VIDEO_ARGS", "").split(" ")
|
||||
AUDIO_ARGS = ("-c:a", "aac", "-b:a", "128k", "-ar", "48000", "-ac", "2", )
|
||||
MUTE_AUDIO_INPUT = ("-f", "lavfi", "-i", "anullsrc=cl=stereo:r=48000", )
|
||||
|
||||
|
||||
def get_mp4toannexb_filter():
|
||||
"""
|
||||
Determine which mp4toannexb filter to use based on ENCODER_ARGS.
|
||||
Returns 'hevc_mp4toannexb' if ENCODER_ARGS contains 'hevc', otherwise 'h264_mp4toannexb'.
|
||||
"""
|
||||
encoder_args_str = os.getenv("ENCODER_ARGS", "").lower()
|
||||
if "hevc" in encoder_args_str:
|
||||
return "hevc_mp4toannexb"
|
||||
return "h264_mp4toannexb"
|
||||
|
||||
|
||||
class FfmpegTask(object):
|
||||
|
||||
effects: list[str]
|
||||
@@ -164,7 +175,7 @@ class FfmpegTask(object):
|
||||
output_args = [*VIDEO_ARGS, *AUDIO_ARGS, *ENCODER_ARGS, *DEFAULT_ARGS]
|
||||
if self.annexb:
|
||||
output_args.append("-bsf:v")
|
||||
output_args.append("h264_mp4toannexb")
|
||||
output_args.append(get_mp4toannexb_filter())
|
||||
output_args.append("-reset_timestamps")
|
||||
output_args.append("1")
|
||||
video_output_str = "[0:v]"
|
||||
@@ -359,7 +370,7 @@ class FfmpegTask(object):
|
||||
output_args += AUDIO_ARGS
|
||||
if self.annexb:
|
||||
output_args.append("-bsf:v")
|
||||
output_args.append("h264_mp4toannexb")
|
||||
output_args.append(get_mp4toannexb_filter())
|
||||
output_args.append("-bsf:a")
|
||||
output_args.append("setts=pts=DTS")
|
||||
output_args.append("-f")
|
||||
|
12
index.py
12
index.py
@@ -1,15 +1,25 @@
|
||||
from time import sleep
|
||||
import sys
|
||||
|
||||
import config
|
||||
import biz.task
|
||||
from telemetry import init_opentelemetry
|
||||
from template import load_local_template
|
||||
from template import load_local_template, download_template, TEMPLATES
|
||||
from util import api
|
||||
|
||||
import os
|
||||
import glob
|
||||
|
||||
load_local_template()
|
||||
|
||||
# Check for redownload parameter
|
||||
if 'redownload' in sys.argv:
|
||||
print("Redownloading all templates...")
|
||||
for template_name in TEMPLATES.keys():
|
||||
print(f"Redownloading template: {template_name}")
|
||||
download_template(template_name)
|
||||
print("All templates redownloaded successfully!")
|
||||
sys.exit(0)
|
||||
import logging
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
@@ -79,6 +79,8 @@ def download_template(template_id):
|
||||
tracer = get_tracer(__name__)
|
||||
with tracer.start_as_current_span("download_template"):
|
||||
template_info = api.get_template_info(template_id)
|
||||
if template_info is None:
|
||||
return
|
||||
if not os.path.isdir(template_info['local_path']):
|
||||
os.makedirs(template_info['local_path'])
|
||||
# download template assets
|
||||
|
@@ -87,6 +87,9 @@ def get_template_info(template_id):
|
||||
data = response.json()
|
||||
logger.debug("获取模板信息结果:【%s】", data)
|
||||
remote_template_info = data.get('data', {})
|
||||
if not remote_template_info:
|
||||
logger.warning("获取模板信息结果为空", data)
|
||||
return None
|
||||
template = {
|
||||
'id': template_id,
|
||||
'updateTime': remote_template_info.get('updateTime', template_id),
|
||||
|
@@ -7,7 +7,7 @@ from typing import Optional, IO
|
||||
|
||||
from opentelemetry.trace import Status, StatusCode
|
||||
|
||||
from entity.ffmpeg import FfmpegTask, ENCODER_ARGS, VIDEO_ARGS, AUDIO_ARGS, MUTE_AUDIO_INPUT
|
||||
from entity.ffmpeg import FfmpegTask, ENCODER_ARGS, VIDEO_ARGS, AUDIO_ARGS, MUTE_AUDIO_INPUT, get_mp4toannexb_filter
|
||||
from telemetry import get_tracer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -23,7 +23,7 @@ def re_encode_and_annexb(file):
|
||||
ffmpeg_process = subprocess.run(["ffmpeg", "-y", "-hide_banner", "-vsync", "cfr", "-i", file,
|
||||
*(set() if has_audio else MUTE_AUDIO_INPUT),
|
||||
"-map", "0:v", "-map", "0:a" if has_audio else "1:a",
|
||||
*VIDEO_ARGS, "-bsf:v", "h264_mp4toannexb",
|
||||
*VIDEO_ARGS, "-bsf:v", get_mp4toannexb_filter(),
|
||||
*AUDIO_ARGS, "-bsf:a", "setts=pts=DTS",
|
||||
*ENCODER_ARGS, "-shortest", "-fflags", "+genpts",
|
||||
"-f", "mpegts", file + ".ts"])
|
||||
|
Reference in New Issue
Block a user