@@ -14,49 +14,61 @@ def render_command(in_video_path, out_video_path, in_subtitle_font_size, in_subt
14
14
in_subtitle_margin_v: str, the bottom margin of subtitles
15
15
"""
16
16
in_ass_path = in_video_path [:- 4 ] + '.ass'
17
+ if not os .path .isfile (in_ass_path ):
18
+ scan_log .warning ("Cannot find danmaku file, return directly" )
19
+ subprocess .run (['mv' , in_video_path , out_video_path ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
20
+ return
21
+
17
22
in_srt_path = in_video_path [:- 4 ] + '.srt'
18
-
19
- if GPU_EXIST and os .path .isfile (in_srt_path ):
20
- if os .path .isfile (in_ass_path ):
21
- scan_log .info ("Current Mode: GPU with danmaku" )
22
- command = [
23
+ if os .path .isfile (in_srt_path ):
24
+ if GPU_EXIST :
25
+ scan_log .info ("Current Mode: GPU with subtitles" )
26
+ gpu_srt_ass_command = [
23
27
'ffmpeg' , '-y' , '-hwaccel' , 'cuda' , '-c:v' , 'h264_cuvid' , '-i' , in_video_path ,
24
28
'-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
25
29
]
26
30
try :
27
- result = subprocess .run (command , check = True , capture_output = True , text = True )
31
+ result = subprocess .run (gpu_srt_ass_command , check = True , capture_output = True , text = True )
28
32
scan_log .debug (f"FFmpeg output: { result .stdout } " )
29
33
if result .stderr :
30
34
scan_log .debug (f"FFmpeg debug: { result .stderr } " )
31
35
except subprocess .CalledProcessError as e :
32
36
scan_log .error (f"Error: { e .stderr } " )
33
-
34
37
else :
35
- scan_log .info ("Current Mode: GPU without danmaku" )
36
- command_no_danmaku = [
37
- 'ffmpeg' , '-y' , '-hwaccel' , 'cuda' , '-c:v' , 'h264_cuvid' , '-i' , in_video_path ,
38
- '-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
38
+ scan_log .info ("Current Mode: CPU with subtitles" )
39
+ cpu_srt_ass_command = [
40
+ '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
39
41
]
40
42
try :
41
- result = subprocess .run (command_no_danmaku , check = True , capture_output = True , text = True )
43
+ result = subprocess .run (cpu_srt_ass_command , check = True , capture_output = True , text = True )
42
44
scan_log .debug (f"FFmpeg output: { result .stdout } " )
43
45
if result .stderr :
44
46
scan_log .debug (f"FFmpeg debug: { result .stderr } " )
45
47
except subprocess .CalledProcessError as e :
46
48
scan_log .error (f"Error: { e .stderr } " )
47
49
else :
48
- if os .path .isfile (in_ass_path ):
49
- scan_log .info ("Current Mode: CPU with danmaku" )
50
- command_without_gpu = [
51
- 'ffmpeg' , '-y' , '-i' , in_video_path , '-vf' , f'ass={ in_ass_path } ' , '-preset' , 'ultrafast' , out_video_path
50
+ if GPU_EXIST :
51
+ scan_log .info ("Current Mode: GPU without subtitles" )
52
+ gpu_ass_command = [
53
+ 'ffmpeg' , '-y' , '-hwaccel' , 'cuda' , '-c:v' , 'h264_cuvid' , '-i' , in_video_path ,
54
+ '-c:v' , 'h264_nvenc' , '-vf' , f"ass={ in_ass_path } " , out_video_path
52
55
]
53
56
try :
54
- result = subprocess .run (command_without_gpu , check = True , capture_output = True , text = True )
57
+ result = subprocess .run (gpu_ass_command , check = True , capture_output = True , text = True )
55
58
scan_log .debug (f"FFmpeg output: { result .stdout } " )
56
59
if result .stderr :
57
60
scan_log .debug (f"FFmpeg debug: { result .stderr } " )
58
61
except subprocess .CalledProcessError as e :
59
62
scan_log .error (f"Error: { e .stderr } " )
60
63
else :
61
- scan_log .info ("Current Mode: CPU without danmaku" )
62
- subprocess .run (['mv' , in_video_path , out_video_path ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
64
+ scan_log .info ("Current Mode: CPU without subtitles" )
65
+ cpu_ass_command = [
66
+ 'ffmpeg' , '-y' , '-i' , in_video_path , '-vf' , f"ass={ in_ass_path } " , '-preset' , 'ultrafast' , out_video_path
67
+ ]
68
+ try :
69
+ result = subprocess .run (cpu_ass_command , check = True , capture_output = True , text = True )
70
+ scan_log .debug (f"FFmpeg output: { result .stdout } " )
71
+ if result .stderr :
72
+ scan_log .debug (f"FFmpeg debug: { result .stderr } " )
73
+ except subprocess .CalledProcessError as e :
74
+ scan_log .error (f"Error: { e .stderr } " )
0 commit comments