+
Skip to content
Merged
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
50 changes: 31 additions & 19 deletions src/burn/render_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,61 @@ def render_command(in_video_path, out_video_path, in_subtitle_font_size, in_subt
in_subtitle_margin_v: str, the bottom margin of subtitles
"""
in_ass_path = in_video_path[:-4] + '.ass'
if not os.path.isfile(in_ass_path):
scan_log.warning("Cannot find danmaku file, return directly")
subprocess.run(['mv', in_video_path, out_video_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return

in_srt_path = in_video_path[:-4] + '.srt'

if GPU_EXIST and os.path.isfile(in_srt_path):
if os.path.isfile(in_ass_path):
scan_log.info("Current Mode: GPU with danmaku")
command = [
if os.path.isfile(in_srt_path):
if GPU_EXIST:
scan_log.info("Current Mode: GPU with subtitles")
gpu_srt_ass_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},MarginV={in_subtitle_margin_v}',subtitles={in_ass_path}", out_video_path
]
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
result = subprocess.run(gpu_srt_ass_command, check=True, capture_output=True, text=True)
scan_log.debug(f"FFmpeg output: {result.stdout}")
if result.stderr:
scan_log.debug(f"FFmpeg debug: {result.stderr}")
except subprocess.CalledProcessError as e:
scan_log.error(f"Error: {e.stderr}")

else:
scan_log.info("Current Mode: GPU without 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},MarginV={in_subtitle_margin_v}'", out_video_path
scan_log.info("Current Mode: CPU with subtitles")
cpu_srt_ass_command = [
'ffmpeg', '-y', '-i', in_video_path, '-vf', f"subtitles={in_srt_path}:force_style='Fontsize={in_subtitle_font_size},MarginV={in_subtitle_margin_v}',subtitles={in_ass_path}", '-preset', 'ultrafast', out_video_path
]
try:
result = subprocess.run(command_no_danmaku, check=True, capture_output=True, text=True)
result = subprocess.run(cpu_srt_ass_command, check=True, capture_output=True, text=True)
scan_log.debug(f"FFmpeg output: {result.stdout}")
if result.stderr:
scan_log.debug(f"FFmpeg debug: {result.stderr}")
except subprocess.CalledProcessError as e:
scan_log.error(f"Error: {e.stderr}")
else:
if os.path.isfile(in_ass_path):
scan_log.info("Current Mode: CPU with danmaku")
command_without_gpu = [
'ffmpeg', '-y', '-i', in_video_path, '-vf', f'ass={in_ass_path}', '-preset', 'ultrafast', out_video_path
if GPU_EXIST:
scan_log.info("Current Mode: GPU without subtitles")
gpu_ass_command = [
'ffmpeg', '-y', '-hwaccel', 'cuda', '-c:v', 'h264_cuvid', '-i', in_video_path,
'-c:v', 'h264_nvenc', '-vf', f"ass={in_ass_path}", out_video_path
]
try:
result = subprocess.run(command_without_gpu, check=True, capture_output=True, text=True)
result = subprocess.run(gpu_ass_command, check=True, capture_output=True, text=True)
scan_log.debug(f"FFmpeg output: {result.stdout}")
if result.stderr:
scan_log.debug(f"FFmpeg debug: {result.stderr}")
except subprocess.CalledProcessError as e:
scan_log.error(f"Error: {e.stderr}")
else:
scan_log.info("Current Mode: CPU without danmaku")
subprocess.run(['mv', in_video_path, out_video_path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
scan_log.info("Current Mode: CPU without subtitles")
cpu_ass_command = [
'ffmpeg', '-y', '-i', in_video_path, '-vf', f"ass={in_ass_path}", '-preset', 'ultrafast', out_video_path
]
try:
result = subprocess.run(cpu_ass_command, check=True, capture_output=True, text=True)
scan_log.debug(f"FFmpeg output: {result.stdout}")
if result.stderr:
scan_log.debug(f"FFmpeg debug: {result.stderr}")
except subprocess.CalledProcessError as e:
scan_log.error(f"Error: {e.stderr}")
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载