固定模板支持音乐

This commit is contained in:
Jerry Yan 2025-03-28 18:08:19 +08:00
parent 09e0f5f3be
commit 6e4dbfd843

View File

@ -19,12 +19,13 @@ def re_encode_and_annexb(file):
span.set_status(Status(StatusCode.ERROR))
return file
logger.info("ReEncodeAndAnnexb: %s", file)
ffmpeg_process = subprocess.run(["ffmpeg", "-y", "-hide_banner", "-i", file,
*MUTE_AUDIO_INPUT,
"-map", "0:v", "-map", "1:a",
has_audio = not not probe_video_audio(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",
*AUDIO_ARGS, "-bsf:a", "setts=pts=DTS",
*ENCODER_ARGS, "-shortest",
*ENCODER_ARGS, "-shortest", "-fflags", "+genpts",
"-f", "mpegts", file + ".ts"])
logger.info(" ".join(ffmpeg_process.args))
span.set_attribute("ffmpeg.args", json.dumps(ffmpeg_process.args))
@ -33,7 +34,7 @@ def re_encode_and_annexb(file):
if ffmpeg_process.returncode == 0:
span.set_status(Status(StatusCode.OK))
span.set_attribute("file.size", os.path.getsize(file+".ts"))
os.remove(file)
# os.remove(file)
return file+".ts"
else:
span.set_status(Status(StatusCode.ERROR))