|
@@ -153,6 +153,60 @@ class FFmpeg():
|
|
|
except Exception as e:
|
|
|
return pw_mp3_path
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def get_pw_video_mp3(cls, video_file, video_path_url):
|
|
|
+ bgm_pw_path_mp3 = video_file + 'bgm_pw.mp3'
|
|
|
+ try:
|
|
|
+ cls.asyncio_run_subprocess([
|
|
|
+ 'ffmpeg',
|
|
|
+ '-i', video_path_url, # 输入的视频文件路径
|
|
|
+ '-q:a', '0', # 设置音频质量为最佳
|
|
|
+ '-map', 'a',
|
|
|
+ '-y',
|
|
|
+ bgm_pw_path_mp3
|
|
|
+ ], timeout=120)
|
|
|
+ time.sleep(1)
|
|
|
+ return bgm_pw_path_mp3
|
|
|
+ except Exception as e:
|
|
|
+ return bgm_pw_path_mp3
|
|
|
+
|
|
|
+
|
|
|
+ """
|
|
|
+ 片尾增加bgm
|
|
|
+ """
|
|
|
+ @classmethod
|
|
|
+ def video_add_bgm(cls, video_file, bgm_path, video_path_url):
|
|
|
+ bgm_pw_path = video_path_url + 'bgm_pw.mp4'
|
|
|
+ pw_duration = cls.get_video_duration(video_file)
|
|
|
+
|
|
|
+ try:
|
|
|
+ pw_path_txt = video_path_url + 'bgm_pw_video.txt'
|
|
|
+ with open(pw_path_txt, 'w') as f:
|
|
|
+ f.write(f"file '{video_file}'\n")
|
|
|
+ cls.asyncio_run_subprocess([
|
|
|
+ "ffmpeg",
|
|
|
+ "-f", "concat",
|
|
|
+ "-safe", "0",
|
|
|
+ "-i", f"{pw_path_txt}", # 视频序列输入的文本文件
|
|
|
+ "-i", bgm_path, # 音频文件
|
|
|
+ "-c:v", "libx264", # 视频编码格式
|
|
|
+ "-t", str(pw_duration), # 输出视频的持续时间
|
|
|
+ '-c:a', 'aac', # 音频编码格式
|
|
|
+ '-b:v', '260k', # 视频比特率
|
|
|
+ '-b:a', '96k', # 音频比特率
|
|
|
+ '-threads', '2', # 线程数
|
|
|
+ # '-vf', f'{background_cmd},{subtitle_cmd}', # 视频过滤器(背景和字幕)
|
|
|
+ "-filter_complex", "[1:a]volume=0.6[a1];[0:a][a1]amerge=inputs=2[aout]", # 混合音频流
|
|
|
+ "-map", "0:v:0", # 映射视频流来自第一个输入文件(视频)
|
|
|
+ "-map", "[aout]", # 映射混合后的音频流
|
|
|
+ '-y', # 强制覆盖输出文件
|
|
|
+ bgm_pw_path # 输出文件路径
|
|
|
+ ], timeout=500)
|
|
|
+ time.sleep(1)
|
|
|
+ return bgm_pw_path
|
|
|
+ except Exception as e:
|
|
|
+ return bgm_pw_path
|
|
|
+
|
|
|
"""横屏视频改为竖屏"""
|
|
|
@classmethod
|
|
|
def update_video_h_w(cls, video_path, file_path):
|