+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/burn/generate_danmakus.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,34 @@ def process_danmakus(in_xml_path, resolution):
boxfont = '28'
danmakufont = '38'
subtitle_font_size = '15'
subtitle_margin_v = '60'
elif resolution == '1920x1080':
boxsize = '500x1080'
boxfont = '50'
danmakufont = '55'
subtitle_font_size = '16'
subtitle_margin_v = '60'
elif resolution == '1080x1920':
boxsize = '500x1920'
boxfont = '55'
danmakufont = '60'
subtitle_font_size = '8'
subtitle_margin_v = '60'
elif resolution == '720x1280':
boxsize = '500x1280'
boxfont = '28'
danmakufont = '38'
subtitle_font_size = '8'
subtitle_margin_v = '60'
else:
boxsize = '500x1080'
boxfont = '38'
danmakufont = '38'
subtitle_font_size = '16'

subtitle_margin_v = '60'
# Convert danmakus to ass file
subprocess.run([src.allconfig.DanmakuFactory_PATH, "-o", in_ass_path, "-i", in_xml_path, "--resolution", resolution, "--msgboxsize", boxsize, "--msgboxfontsize", boxfont, "-S", danmakufont, "--ignore-warnings"])
# Remove emojis from ass danmakus (the ffmpeg do not support emojis)
remove_emojis(in_ass_path)
print(f"The {in_ass_path} has been processed.", flush=True)
return subtitle_font_size
return subtitle_font_size, subtitle_margin_v
4 changes: 2 additions & 2 deletions src/burn/only_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def render_video_only(video_path):
video_resolution = get_resolution(original_video_path)

# Process the danmakus to ass and remove emojis
subtitle_font_size = process_danmakus(xml_path, video_resolution)
subtitle_font_size, subtitle_margin_v = process_danmakus(xml_path, video_resolution)

# Generate the srt file via whisper model
if GPU_EXIST:
generate_subtitles(original_video_path)

# Burn danmaku or subtitles into the videos
render_video(original_video_path, format_video_path, subtitle_font_size)
render_video(original_video_path, format_video_path, subtitle_font_size, subtitle_margin_v)
print("complete danamku burning and wait for uploading!", flush=True)

# # Delete relative files
Expand Down
4 changes: 2 additions & 2 deletions src/burn/render_and_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def render_and_merge(video_path_list):
# Recoginze the resolution of video
video_resolution = get_resolution(original_video_path)
# Process the danmakus to ass and remove emojis
subtitle_font_size = process_danmakus(xml_path, video_resolution)
subtitle_font_size, subtitle_margin_v = process_danmakus(xml_path, video_resolution)
# Generate the srt file via whisper model
if GPU_EXIST:
generate_subtitles(original_video_path)
# Burn danmaku or subtitles into the videos
render_video(original_video_path, video_to_be_merged, subtitle_font_size)
render_video(original_video_path, video_to_be_merged, subtitle_font_size, subtitle_margin_v)
if not os.path.exists(merge_list):
open(merge_list, 'w').close()
with open(merge_list, 'a') as f:
Expand Down
7 changes: 4 additions & 3 deletions src/burn/render_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import src.allconfig
import os

def render_video(in_video_path, out_video_path, in_subtitle_font_size):
def render_video(in_video_path, out_video_path, in_subtitle_font_size, in_subtitle_margin_v):
"""Burn the danmakus and subtitles into the videos
Args:
in_video_path: str, the path of video
out_video_path: str, the path of rendered video
in_subtitle_font_size: str, the font size of subtitles
in_subtitle_margin_v: str, the bottom margin of subtitles
"""
in_ass_path = in_video_path[:-4] + '.ass'
if src.allconfig.GPU_EXIST:
Expand All @@ -18,15 +19,15 @@ def render_video(in_video_path, out_video_path, in_subtitle_font_size):
print("wisper danmaku")
command = [
'ffmpeg', '-y', '-hwaccel', 'cuda', '-c:v', 'h264_cuvid', '-i', in_video_path,
'-c:v', 'h264_nvenc', '-vf', f"subtitles={in_srt_path}:force_style='Fontsize={in_subtitle_font_size}',subtitles={in_ass_path}", out_video_path
'-c:v', 'h264_nvenc', '-vf', f"subtitles={in_srt_path}:force_style='Fontsize={in_subtitle_font_size},MarginV={in_subtitle_margin_v}',subtitles={in_ass_path}", out_video_path
]
with open(src.allconfig.BURN_LOG_PATH, 'a') as blog:
subprocess.run(command, stdout=blog, stderr=subprocess.STDOUT)
else:
print("wisper no danmaku")
command_no_danmaku = [
'ffmpeg', '-y', '-hwaccel', 'cuda', '-c:v', 'h264_cuvid', '-i', in_video_path,
'-c:v', 'h264_nvenc', '-vf', f"subtitles={in_srt_path}:force_style='Fontsize={in_subtitle_font_size}'", out_video_path
'-c:v', 'h264_nvenc', '-vf', f"subtitles={in_srt_path}:force_style='Fontsize={in_subtitle_font_size},MarginV={in_subtitle_margin_v}'", out_video_path
]
with open(src.allconfig.BURN_LOG_PATH, 'a') as blog:
subprocess.run(command_no_danmaku, stdout=blog, stderr=subprocess.STDOUT)
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载