You've already forked FrameTour-RenderWorker
音轨叠加
This commit is contained in:
@ -5,7 +5,7 @@ import subprocess
|
||||
from datetime import datetime
|
||||
from typing import Optional, IO
|
||||
|
||||
from entity.ffmpeg import FfmpegTask, ENCODER_ARGS, PROFILE_LEVEL_ARGS
|
||||
from entity.ffmpeg import FfmpegTask, ENCODER_ARGS, VIDEO_ARGS, AUDIO_ARGS
|
||||
from telemetry import get_tracer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -34,7 +34,7 @@ def re_encode_and_annexb(file):
|
||||
if not os.path.exists(file):
|
||||
return file
|
||||
logger.info("ReEncodeAndAnnexb: %s", file)
|
||||
ffmpeg_process = subprocess.run(["ffmpeg", "-y", "-hide_banner", "-i", file, *PROFILE_LEVEL_ARGS, *ENCODER_ARGS, "-bsf:v", "h264_mp4toannexb",
|
||||
ffmpeg_process = subprocess.run(["ffmpeg", "-y", "-hide_banner", "-i", file, *VIDEO_ARGS, *AUDIO_ARGS, *ENCODER_ARGS, "-bsf:v", "h264_mp4toannexb",
|
||||
"-f", "mpegts", file +".ts"])
|
||||
span.set_attribute("ffmpeg.args", json.dumps(ffmpeg_process.args))
|
||||
logger.info("ReEncodeAndAnnexb: %s, returned: %s", file, ffmpeg_process.returncode)
|
||||
@ -55,12 +55,12 @@ def start_render(ffmpeg_task: FfmpegTask):
|
||||
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
|
||||
ffmpeg_process = subprocess.run(["ffmpeg", "-progress", "-", "-loglevel", "error", *ffmpeg_args], **subprocess_args(True))
|
||||
span.set_attribute("ffmpeg.args", json.dumps(ffmpeg_process.args))
|
||||
logger.info(ffmpeg_process.args)
|
||||
ffmpeg_final_out = handle_ffmpeg_output(ffmpeg_process.stdout)
|
||||
span.set_attribute("ffmpeg.out", ffmpeg_final_out)
|
||||
logger.info("FINISH TASK, OUTPUT IS %s", ffmpeg_final_out)
|
||||
|
41
util/oss.py
41
util/oss.py
@ -22,8 +22,9 @@ def upload_to_oss(url, file_path):
|
||||
max_retries = 5
|
||||
retries = 0
|
||||
while retries < max_retries:
|
||||
try:
|
||||
with tracer.start_as_current_span("upload_to_oss.request") as req_span:
|
||||
with tracer.start_as_current_span("upload_to_oss.request") as req_span:
|
||||
req_span.set_attribute("http.retry_count", retries)
|
||||
try:
|
||||
req_span.set_attribute("http.method", "PUT")
|
||||
req_span.set_attribute("http.url", url)
|
||||
with open(file_path, 'rb') as f:
|
||||
@ -31,13 +32,14 @@ def upload_to_oss(url, file_path):
|
||||
req_span.set_attribute("http.status_code", response.status_code)
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
except requests.exceptions.Timeout:
|
||||
retries += 1
|
||||
logger.warning(f"Upload timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
retries += 1
|
||||
span.set_attribute("oss.error", str(e))
|
||||
logger.warning(f"Upload failed. Retrying {retries}/{max_retries}...")
|
||||
except requests.exceptions.Timeout:
|
||||
req_span.set_attribute("http.error", "Timeout")
|
||||
retries += 1
|
||||
logger.warning(f"Upload timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
req_span.set_attribute("http.error", str(e))
|
||||
retries += 1
|
||||
logger.warning(f"Upload failed. Retrying {retries}/{max_retries}...")
|
||||
return False
|
||||
|
||||
|
||||
@ -60,20 +62,23 @@ def download_from_oss(url, file_path):
|
||||
max_retries = 5
|
||||
retries = 0
|
||||
while retries < max_retries:
|
||||
try:
|
||||
with tracer.start_as_current_span("download_from_oss.request") as req_span:
|
||||
with tracer.start_as_current_span("download_from_oss.request") as req_span:
|
||||
req_span.set_attribute("http.retry_count", retries)
|
||||
try:
|
||||
req_span.set_attribute("http.method", "GET")
|
||||
req_span.set_attribute("http.url", url)
|
||||
response = requests.get(url, timeout=15) # 设置超时时间
|
||||
req_span.set_attribute("http.status_code", response.status_code)
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
span.set_attribute("file.size", os.path.getsize(file_path))
|
||||
return True
|
||||
except requests.exceptions.Timeout:
|
||||
retries += 1
|
||||
logger.warning(f"Download timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
retries += 1
|
||||
span.set_attribute("oss.error", str(e))
|
||||
logger.warning(f"Download failed. Retrying {retries}/{max_retries}...")
|
||||
except requests.exceptions.Timeout:
|
||||
span.set_attribute("http.error", "Timeout")
|
||||
retries += 1
|
||||
logger.warning(f"Download timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
span.set_attribute("http.error", str(e))
|
||||
retries += 1
|
||||
logger.warning(f"Download failed. Retrying {retries}/{max_retries}...")
|
||||
return False
|
||||
|
Reference in New Issue
Block a user