You've already forked FrameTour-RenderWorker
音频淡出
This commit is contained in:
@ -154,6 +154,43 @@ def probe_video_audio(video_file, type=None):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# 音频淡出2秒
|
||||
def fade_out_audio(file, duration, fade_out_sec = 2):
|
||||
if type(duration) == str:
|
||||
try:
|
||||
duration = float(duration)
|
||||
except Exception as e:
|
||||
logger.error("duration is not float: %s", e)
|
||||
return file
|
||||
tracer = get_tracer(__name__)
|
||||
with tracer.start_as_current_span("fade_out_audio") as span:
|
||||
span.set_attribute("audio.file", file)
|
||||
if duration <= fade_out_sec:
|
||||
return file
|
||||
else:
|
||||
new_fn = file + "_.mp4"
|
||||
if os.path.exists(new_fn):
|
||||
os.remove(new_fn)
|
||||
logger.info("delete tmp file: " + new_fn)
|
||||
try:
|
||||
process = subprocess.run(["ffmpeg", "-i", file, "-c:v", "copy", "-c:a", "aac", "-af", "afade=t=out:st=" + str(duration - fade_out_sec) + ":d=" + str(fade_out_sec), "-y", new_fn], **subprocess_args(True))
|
||||
span.set_attribute("ffmpeg.args", json.dumps(process.args))
|
||||
logger.info(" ".join(process.args))
|
||||
if process.returncode != 0:
|
||||
span.set_status(Status(StatusCode.ERROR))
|
||||
logger.error("FFMPEG ERROR: %s", process.stderr)
|
||||
return file
|
||||
else:
|
||||
span.set_status(Status(StatusCode.OK))
|
||||
return new_fn
|
||||
except Exception as e:
|
||||
span.set_status(Status(StatusCode.ERROR))
|
||||
logger.error("FFMPEG ERROR: %s", e)
|
||||
return file
|
||||
|
||||
|
||||
|
||||
# Create a set of arguments which make a ``subprocess.Popen`` (and
|
||||
# variants) call work with or without Pyinstaller, ``--noconsole`` or
|
||||
# not, on Windows and Linux. Typical use::
|
||||
|
Reference in New Issue
Block a user