|
@@ -38,7 +38,7 @@ def generate_video(image_files, output_path):
|
|
|
start_xvfb()
|
|
|
try:
|
|
|
video_files = []
|
|
|
- music_path = "/web/test/ASJServer/static/temp/music.mp3"
|
|
|
+ music_path = "static/ffmpeg/music.mp3"
|
|
|
# 定义特效列表
|
|
|
transitions = [
|
|
|
"BowTieHorizontal.glsl",
|
|
@@ -58,36 +58,41 @@ def generate_video(image_files, output_path):
|
|
|
video_files.append(output_video)
|
|
|
|
|
|
cmd = [
|
|
|
- 'ffmpeg', '-loop', '1', '-i', image_files[i],
|
|
|
+ 'static/ffmpeg/ffmpeg4', '-loop', '1', '-i', image_files[i],
|
|
|
'-loop', '1', '-i', image_files[i + 1],
|
|
|
'-filter_complex',
|
|
|
- f'gltransition=duration=1:offset=0.7:source=/web/test/ASJServer/static/gl-transitions/{transitions[i]}',
|
|
|
+ f'gltransition=duration=1:offset=0.7:source=static/gl-transitions/{transitions[i]}',
|
|
|
'-t', '2', output_video
|
|
|
]
|
|
|
|
|
|
subprocess.run(cmd, check=True)
|
|
|
|
|
|
# 生成拼接列表文件
|
|
|
- with open(os.path.join(output_path, 'filelist.txt'), 'w') as f:
|
|
|
+ filelist_path = os.path.join(output_path, 'filelist.txt')
|
|
|
+ with open(filelist_path, 'w') as f:
|
|
|
for video in video_files:
|
|
|
- f.write(f"file '{video}'\n")
|
|
|
+ f.write(f"file '{os.path.relpath(video, output_path)}'\n") # 使用相对路径
|
|
|
|
|
|
- # 拼接视频
|
|
|
- final_output = os.path.join(output_path, 'final_output.mp4')
|
|
|
+ # 拼接并生成背景音乐
|
|
|
+ final_output_with_music = os.path.join(output_path, 'final_output_with_music.mp4')
|
|
|
subprocess.run(
|
|
|
- ['ffmpeg', '-f', 'concat', '-safe', '0', '-i', '/web/test/ASJServer/static/temp/filelist.txt', '-c', 'copy',
|
|
|
- final_output],
|
|
|
- check=True)
|
|
|
+ ['static/ffmpeg/ffmpeg6', '-f', 'concat', '-safe', '0', '-i', filelist_path, '-i', music_path,
|
|
|
+ '-c:v', 'copy', '-c:a', 'aac', '-b:a', '192k', '-movflags', '+faststart', '-shortest',
|
|
|
+ final_output_with_music],
|
|
|
+ check=True
|
|
|
+ )
|
|
|
+ video420acc = os.path.join(output_path, 'video420acc.mp4')
|
|
|
|
|
|
- # 添加背景音乐
|
|
|
- final_output_with_music = os.path.join(output_path, 'final_output_with_music.mp4')
|
|
|
- subprocess.run(['ffmpeg', '-i', final_output, '-i', music_path, '-c:v', 'copy', '-c:a', 'aac', '-b:a', '192k',
|
|
|
- '-shortest', final_output_with_music], check=True)
|
|
|
+ subprocess.run(
|
|
|
+ ['static/ffmpeg/ffmpeg6', '-i', final_output_with_music, '-pix_fmt', 'yuv420p', video420acc],
|
|
|
+ check=True
|
|
|
+ )
|
|
|
|
|
|
# 清理临时文件
|
|
|
for video in video_files:
|
|
|
os.remove(video)
|
|
|
- os.remove('/web/test/ASJServer/static/temp/filelist.txt')
|
|
|
+ os.remove(filelist_path)
|
|
|
+ os.remove(final_output_with_music)
|
|
|
except Exception as e:
|
|
|
LOGGER.info(f'视频合成失败: {e}')
|
|
|
|