|
@@ -202,33 +202,10 @@ class FFmpeg():
|
|
|
|
|
|
"""视频拼接到一起"""
|
|
|
@classmethod
|
|
|
- def h_b_video(cls, video_path, pw_path, file_path, zm):
|
|
|
+ def h_b_video(cls, video_path, pw_path, file_path):
|
|
|
video_url = file_path + 'hbvideo.mp4'
|
|
|
- single_video_srt = file_path + 'single_video.srt'
|
|
|
- # 获取时长
|
|
|
- duration = cls.get_video_duration(video_path)
|
|
|
- pw_duration = cls.get_video_duration(pw_path)
|
|
|
-
|
|
|
- if duration == 0 or pw_duration == 0:
|
|
|
- return video_url
|
|
|
- duration = pw_duration + duration
|
|
|
- start_time = cls.seconds_to_srt_time(2)
|
|
|
- end_time = cls.seconds_to_srt_time(duration)
|
|
|
- single_video_txt = file_path + 'single_video.txt'
|
|
|
- with open(single_video_txt, 'w') as f:
|
|
|
- f.write(f"file '{video_path}'\n")
|
|
|
- if zm:
|
|
|
- # 如果有 zm,则写入字幕文件
|
|
|
- with open(single_video_srt, 'w') as f:
|
|
|
- f.write(f"1\n{start_time} --> {end_time}\n<font color=\"red\">\u2764\uFE0F</font>{zm}\n\n")
|
|
|
- # 字幕命令,包含字幕文件路径
|
|
|
- subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
- else:
|
|
|
- # 如果没有 zm,则不使用字幕文件,直接使用样式
|
|
|
- subtitle_cmd = f"force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
|
|
|
- # 最终的ffmpeg命令,加入字幕命令
|
|
|
- ffmpeg_cmd = f"ffmpeg -i {video_path} -i {pw_path} -filter_complex '[0:v]scale=360:640[v1]; [1:v]scale=360:640[v2]; [v1][0:a][v2][1:a]concat=n=2:v=1:a=1[outv][outa]' -map '[outv]' -map '[outa]' {subtitle_cmd} {video_url}"
|
|
|
+ ffmpeg_cmd = f"ffmpeg -i {video_path} -i {pw_path} -filter_complex '[0:v]scale=360:640[v1]; [1:v]scale=360:640[v2]; [v1][0:a][v2][1:a]concat=n=2:v=1:a=1[outv][outa]' -map '[outv]' -map '[outa]' {video_url}"
|
|
|
subprocess.run(ffmpeg_cmd, shell=True)
|
|
|
return video_url
|
|
|
|
|
@@ -380,7 +357,6 @@ class FFmpeg():
|
|
|
subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
else:
|
|
|
subtitle_cmd = f"force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
- draw = f"{subtitle_cmd}"
|
|
|
# 多线程数
|
|
|
num_threads = 5
|
|
|
# 构建 FFmpeg 命令,生成视频
|
|
@@ -394,7 +370,7 @@ class FFmpeg():
|
|
|
'-b:v', '260k',
|
|
|
"-b:a", "96k",
|
|
|
"-threads", str(num_threads),
|
|
|
- "-vf", f"{draw}",
|
|
|
+ "-vf", subtitle_cmd,
|
|
|
"-y",
|
|
|
single_video_url
|
|
|
]
|