|
@@ -104,7 +104,6 @@ class AgcVidoe():
|
|
|
}
|
|
|
response = requests.post(url, data=data, headers=headers)
|
|
|
data = response.json()
|
|
|
- code = data["code"]
|
|
|
return True
|
|
|
|
|
|
# 获取视频链接
|
|
@@ -240,8 +239,7 @@ class AgcVidoe():
|
|
|
t_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/txt/"
|
|
|
# oss 目录
|
|
|
v_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/oss/"
|
|
|
- # 无字幕 视频
|
|
|
- not_path_url = config['PATHS']['VIDEO_PATH'] + mark + "/not_oss/"
|
|
|
+
|
|
|
|
|
|
if not os.path.exists(video_path_url):
|
|
|
os.makedirs(video_path_url)
|
|
@@ -251,18 +249,12 @@ class AgcVidoe():
|
|
|
os.makedirs(t_path_url)
|
|
|
if not os.path.exists(v_path_url):
|
|
|
os.makedirs(v_path_url)
|
|
|
- if not os.path.exists(not_path_url):
|
|
|
- os.makedirs(not_path_url)
|
|
|
# srt 文件地址
|
|
|
s_path = s_path_url + mark + ".srt"
|
|
|
# txt 文件地址
|
|
|
t_path = t_path_url + mark + ".txt"
|
|
|
# 最终生成视频地址
|
|
|
v_path = v_path_url + mark + ".mp4"
|
|
|
- # 无字幕 视频地址
|
|
|
- not_path = not_path_url + mark + ".mp4"
|
|
|
- if os.path.isfile(not_path):
|
|
|
- os.remove(not_path)
|
|
|
if os.path.isfile(v_path):
|
|
|
os.remove(v_path)
|
|
|
if os.path.isfile(t_path):
|
|
@@ -271,13 +263,13 @@ class AgcVidoe():
|
|
|
os.remove(s_path)
|
|
|
# 清空所有mp4数据
|
|
|
cls.clear_mp4_files(video_path_url)
|
|
|
- return s_path, t_path, v_path, video_path_url, not_path
|
|
|
+ return s_path, t_path, v_path, video_path_url
|
|
|
|
|
|
|
|
|
|
|
|
# 视频拼接
|
|
|
@classmethod
|
|
|
- def concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path, not_path):
|
|
|
+ def concatenate_videos(cls, videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path):
|
|
|
video_files = cls.concat_videos_with_subtitles(videos, audio_duration, platform, mark)
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道待生成视频为:{video_files}")
|
|
|
if video_files == "":
|
|
@@ -304,50 +296,35 @@ class AgcVidoe():
|
|
|
resolution_cmd = "-s", "320x480"
|
|
|
# 多线程数
|
|
|
num_threads = 4
|
|
|
- # 构建 FFmpeg 命令,生成无字幕视频
|
|
|
- ffmpeg_cmd_not = [
|
|
|
+ # 构建 FFmpeg 命令,生成视频
|
|
|
+ ffmpeg_cmd = [
|
|
|
"ffmpeg",
|
|
|
"-f", "concat",
|
|
|
"-safe", "0",
|
|
|
"-i", f"{t_path}", # 视频文件列表
|
|
|
"-i", audio_video, # 音频文件
|
|
|
- "-c:v", "copy",
|
|
|
+ "-c:v", "libx264",
|
|
|
"-c:a", "aac",
|
|
|
- "-threads", str(num_threads),
|
|
|
+ "-vf", f"scale=320x480,{background_cmd},{subtitle_cmd}", # 添加背景色和字幕
|
|
|
*resolution_cmd, # 添加分辨率参数
|
|
|
- "-b:v", "6M", # 设置可变比特率
|
|
|
+ "-b:v", "5M", # 设置可变比特率
|
|
|
"-maxrate", "10M", # 设置最大比特率
|
|
|
"-bufsize", "5M", # 设置缓冲大小
|
|
|
"-crf", "23", # 设置CRF(恒定质量)
|
|
|
"-r", "30", # 设置帧率为30帧每秒
|
|
|
"-vsync", "cfr", # 设置视频同步策略为可变帧率
|
|
|
- "-shortest", # 保持与音频时长一致
|
|
|
+ "-t", str(int(audio_duration)), # 保持与音频时长一致
|
|
|
"-map", "0:v:0", # 映射第一个输入的视频流
|
|
|
"-map", "1:a:0", # 映射第二个输入的音频流
|
|
|
"-y", # 覆盖输出文件
|
|
|
- not_path
|
|
|
- ]
|
|
|
- # 构建 FFmpeg 命令,添加字幕
|
|
|
- ffmpeg_cmd = [
|
|
|
- "ffmpeg",
|
|
|
- "-i", not_path, # 拼接后的视频文件
|
|
|
- "-vf", f"scale=320x480,{background_cmd},{subtitle_cmd}", # 添加背景色和字幕
|
|
|
- # 添加背景色和字幕
|
|
|
- "-c:v", "libx264", # 使用拷贝模式
|
|
|
- "-preset", "slow", # 添加 medium
|
|
|
- "-profile:v", "high", # main指定视频编码的配置文件
|
|
|
- # "-c:a", "copy", # 拷贝音频流
|
|
|
- "-y", # 覆盖输出文件
|
|
|
+ "-x264opts",
|
|
|
+ "keyint=30:min-keyint=5:scenecut=0:ref=5:bframes=3:b-adapt=2:direct=auto:me=umh:subme=7:analyse=all:trellis=2",# 设置关键帧参数
|
|
|
v_path
|
|
|
]
|
|
|
+ # 构建 FFmpeg 命令,添加字幕
|
|
|
# 执行 FFmpeg 命令
|
|
|
try:
|
|
|
- subprocess.run(ffmpeg_cmd_not, check=True)
|
|
|
- if os.path.isfile(not_path):
|
|
|
- subprocess.run(ffmpeg_cmd, check=True)
|
|
|
- else:
|
|
|
- return ''
|
|
|
-
|
|
|
+ subprocess.run(ffmpeg_cmd, check=True)
|
|
|
print("视频处理完成!")
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
print(f"视频处理失败:{e}")
|
|
@@ -379,7 +356,7 @@ class AgcVidoe():
|
|
|
|
|
|
|
|
|
# 如果没有该文件目录则创建,有文件目录的话 则删除文件
|
|
|
- s_path, t_path, v_path, video_path_url, not_path = cls.create_folders(mark)
|
|
|
+ s_path, t_path, v_path, video_path_url= cls.create_folders(mark)
|
|
|
|
|
|
kb_count = int(result[1][1])
|
|
|
channel = ['douyin', 'kuaishou', 'koubo']
|
|
@@ -428,7 +405,7 @@ class AgcVidoe():
|
|
|
# 获取音频秒数
|
|
|
audio_duration = cls.get_audio_duration(audio_video)
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道获取需要拼接的音频秒数为:{audio_duration}")
|
|
|
- video_files = cls.concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path, not_path)
|
|
|
+ video_files = cls.concatenate_videos(videos, audio_duration, audio_video, platform, s_path, v_path, mark, t_path)
|
|
|
if video_files == "":
|
|
|
Common.logger("video").info(f"{mark}的{platform}渠道使用拼接视频为空")
|
|
|
return ""
|