|
@@ -155,7 +155,7 @@ class FFmpeg():
|
|
|
time_offset = total_duration - 1 # 提取倒数第一秒的帧
|
|
|
# 获取视频最后一秒,生成.jpg
|
|
|
subprocess.run(
|
|
|
- ['ffmpeg', '-ss', str(time_offset), '-i', new_video_path, '-t', str(total_duration), '-vf', 'fps=1', "-y", jpg_url])
|
|
|
+ ['ffmpeg', '-ss', str(time_offset), '-i', new_video_path, '-t', str(total_duration), '-vf', 'fps=1,scale=360:640', "-y", jpg_url])
|
|
|
return jpg_url
|
|
|
|
|
|
"""
|
|
@@ -181,7 +181,7 @@ class FFmpeg():
|
|
|
def update_video_h_w(cls, new_video_path, video_path_url, pw_random_id):
|
|
|
video_h_w_path = video_path_url + str(pw_random_id) +'video_h_w_video.mp4'
|
|
|
|
|
|
- ffmpeg_cmd = f"ffmpeg -i {new_video_path} -vf 'scale=1080:ih*1080/iw,pad=iw:iw*16/9:(ow-iw)/2:(oh-ih)/2' {video_h_w_path}"
|
|
|
+ ffmpeg_cmd = f"ffmpeg -i {new_video_path} -vf 'scale=640:ih*640/iw,pad=iw:iw*16/9:(ow-iw)/2:(oh-ih)/2' {video_h_w_path}"
|
|
|
subprocess.run(ffmpeg_cmd, shell=True)
|
|
|
return video_h_w_path
|
|
|
|
|
@@ -208,6 +208,7 @@ class FFmpeg():
|
|
|
"-i", single_video_txt,
|
|
|
"-c:v", "libx264",
|
|
|
"-c:a", "aac",
|
|
|
+ # '-vf', f"scale=640x360",
|
|
|
"-vf", draw,
|
|
|
"-y",
|
|
|
single_video
|
|
@@ -244,8 +245,8 @@ class FFmpeg():
|
|
|
height = 1080
|
|
|
margin_v = int(height) // 8 # 可根据需要调整字幕和背景之间的距离
|
|
|
subtitle_cmd = f"subtitles={pw_srt_path}:force_style='Fontsize=13,Fontname=wqy-zenhei,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000,Bold=1,MarginV={margin_v}'"
|
|
|
- bg_position_offset = (int(height) - margin_v) / 1.75
|
|
|
- background_cmd = f"drawbox=y=(ih-{int(height)}/2-{bg_position_offset}):color=yellow@1.0:width=iw:height={int(height)}/4:t=fill"
|
|
|
+ bg_position_offset = (int(360) - 360//8) / 1.75
|
|
|
+ background_cmd = f"drawbox=y=(ih-{int(360)}/2-{bg_position_offset}):color=yellow@1.0:width=iw:height={int(360)}/4:t=fill"
|
|
|
|
|
|
ffmpeg_cmd = [
|
|
|
'ffmpeg',
|
|
@@ -258,7 +259,7 @@ class FFmpeg():
|
|
|
'-c:a', 'aac', # 音频编码格式
|
|
|
'-strict', 'experimental', # 使用实验性编码器
|
|
|
'-shortest', # 确保输出视频的长度与音频一致
|
|
|
- '-vf', f"scale=1080x1920,{background_cmd},{subtitle_cmd}", # 视频过滤器,设置分辨率和其他过滤器
|
|
|
+ '-vf', f"{background_cmd},{subtitle_cmd}", # 视频过滤器,设置分辨率和其他过滤器
|
|
|
pw_url_path # 输出的视频文件路径
|
|
|
]
|
|
|
subprocess.run(ffmpeg_cmd)
|
|
@@ -270,8 +271,6 @@ class FFmpeg():
|
|
|
@classmethod
|
|
|
def concatenate_videos(cls, video_list, video_path_url):
|
|
|
concatenate_videos_url = video_path_url + 'concatenate_videos.mp4'
|
|
|
- # 获取视频的原始宽高信息
|
|
|
- width, height = cls.get_w_h_size(video_list[0])
|
|
|
# 拼接视频
|
|
|
VIDEO_COUNTER = 0
|
|
|
FF_INPUT = ""
|
|
@@ -282,7 +281,7 @@ class FFmpeg():
|
|
|
# 添加输入文件
|
|
|
FF_INPUT += f" -i {videos}"
|
|
|
# 为每个视频文件统一长宽,并设置SAR(采样宽高比)
|
|
|
- FF_SCALE += f"[{VIDEO_COUNTER}:v]scale={int(height)}x{int(width)},setsar=1[v{VIDEO_COUNTER}];"
|
|
|
+ FF_SCALE += f"[{VIDEO_COUNTER}:v]scale=360x640,setsar=1[v{VIDEO_COUNTER}];"
|
|
|
# 为每个视频文件创建一个输入流,并添加到-filter_complex参数中
|
|
|
FF_FILTER += f"[v{VIDEO_COUNTER}][{VIDEO_COUNTER}:a]"
|
|
|
# 增加视频计数器
|
|
@@ -299,7 +298,7 @@ class FFmpeg():
|
|
|
单个视频拼接
|
|
|
"""
|
|
|
@classmethod
|
|
|
- def single_video(cls, new_video_path, video_share, video_path_url, zm):
|
|
|
+ def single_video(cls, new_video_path, video_path_url, zm):
|
|
|
single_video_url = video_path_url + 'single_video.mp4'
|
|
|
single_video_srt = video_path_url + 'single_video.srt'
|
|
|
# 获取时长
|
|
@@ -311,18 +310,19 @@ class FFmpeg():
|
|
|
f.write(f"file '{new_video_path}'\n")
|
|
|
with open(single_video_srt, 'w') as f:
|
|
|
f.write(f"1\n{start_time} --> {end_time}\n\u2764\uFE0F{zm}\n\n")
|
|
|
- width, height = cls.get_w_h_size(new_video_path)
|
|
|
+ # width, height = cls.get_w_h_size(new_video_path)
|
|
|
+ height = 1080
|
|
|
box_height = int(int(height) / 4) # 框的高度为视频高度的四分之一
|
|
|
|
|
|
background_cmd = f"drawbox=y=ih-{70 + box_height}-{int(box_height / 20)}:color=yellow@1.0:width=iw:height={box_height}:t=fill"
|
|
|
|
|
|
- if video_share == '有':
|
|
|
- # 添加字幕 wqy-zenhei Hiragino Sans GB
|
|
|
- subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
- draw = f"{background_cmd},{subtitle_cmd}"
|
|
|
- else:
|
|
|
- subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=2,PrimaryColour=&H00FFFF,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
- draw = f"{subtitle_cmd}"
|
|
|
+ # if video_share == '有':
|
|
|
+ # # 添加字幕 wqy-zenhei Hiragino Sans GB
|
|
|
+ # subtitle_cmd = f"subtitles={single_video_srt}:force_style='Fontsize=14,Fontname=wqy-zenhei,Outline=0,PrimaryColour=&H000000,SecondaryColour=&H000000,Bold=1,MarginV=20'"
|
|
|
+ # draw = f"{background_cmd},{subtitle_cmd}"
|
|
|
+ # else:
|
|
|
+ subtitle_cmd = f"subtitles={single_video_srt}: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 命令,生成视频
|