88from extract_subs import extract_subs
99from multi import multi
1010from mux import mux
11+ from patch import patch
1112from shader import shader
1213from splitter import split_by_seconds , get_video_length
1314from utils import __current_version__ , is_tool , credz , str2dict
1415
1516# Constant variables
16- MODES_SUPPORTING_MULTI_INPUTS = ["shader" , "multi" , "encode" ]
17+ MODES_SUPPORTING_MULTI_INPUTS = ["shader" , "multi" , "encode" , "patch" ]
18+ MODES_TO_IGNORE_OUTPUT_EXISTENCE = ["patch" ]
1719
1820# Print credits
1921credz ()
3739parser .add_argument ("-v" , "--version" , required = False ,
3840 action = 'store_true' ,
3941 help = "Print the current version of Anime4K-Encoder" )
42+ parser .add_argument ("--debug" , "--verbose" , required = False ,
43+ action = 'store_true' ,
44+ help = 'Enable debug mode; print more information and no screen clearing' )
4045parser .add_argument ("-m" , "--mode" , required = False ,
4146 default = "shader" ,
4247 help = '''Modes:
4651 mux - Mux/compile a media file with audio files and subtitle files
4752 multi - Apply shader with -ss and -sa, audio, subs and mux mode in order
4853 encode - Encode media files using X265 with predefined settings
49- split - Split a media file into parts''' )
54+ split - Split a media file into parts
55+ patch - Extract audio and subs from input files then mux with already upscaled
56+ output files located in the output directory with matching file names.
57+ This is essentially a mux mode supporting multiple files.''' )
5058parser .add_argument ("-ew" , "--width" , required = False , type = int , default = 3840 ,
5159 help = "Desired width when applying shader" )
5260parser .add_argument ("-eh" , "--height" , required = False , type = int , default = 2160 ,
7179 action = 'store_true' ,
7280 default = False ,
7381 help = "Set this flag if you want to manually mux audio when using mode shader" )
82+ parser .add_argument ("-fps" , "--fps" , required = False , type = float ,
83+ help = "Desired framerate when applying shader" )
7484parser .add_argument ("-sm" , "--skip_menus" , required = False , type = str2dict ,
7585 help = '''Skip choice menus
7686Examples for mode shader:
90100 default = False ,
91101 help = "Set this flag to delete output files that have failed to compile when using mode multi" )
92102parser .add_argument ("-si" , "--skip_input" , required = False , action = 'append' ,
93- help = "Input file to skip when using a directory as an input for modes shader and multi " )
103+ help = "Input file to skip when using a directory as an input for modes shader, multi and patch " )
94104
95105args = vars (parser .parse_args ())
96106if args ['version' ]:
97107 print ("Anime4K-Encoder v" + __current_version__ )
98108 sys .exit (1 )
99109
110+ debug = args ['debug' ]
111+ if debug is None :
112+ debug = False
113+
100114
101115def exit_if_missing (file_path : str , allow_dir : bool = True ):
102116 if not os .path .isdir (file_path ):
@@ -151,7 +165,9 @@ def exit_if_missing(file_path: str, allow_dir: bool = True):
151165 output = output + "/"
152166elif mode in MODES_SUPPORTING_MULTI_INPUTS :
153167 output = args ['output' ] or "out.mkv"
154- if os .path .isdir (output ) and not os .path .exists (output ):
168+ if mode not in MODES_TO_IGNORE_OUTPUT_EXISTENCE \
169+ and os .path .isdir (output ) \
170+ and not os .path .exists (output ):
155171 try :
156172 os .mkdir (output )
157173 except Exception as e :
@@ -179,14 +195,14 @@ def exit_if_missing(file_path: str, allow_dir: bool = True):
179195 os .path .join (file , "*.mp4" )
180196 ):
181197 file_name = os .path .basename (file_in_dir )
182- if file_name in skip_inputs :
198+ if file_in_dir in skip_inputs or file_name in skip_inputs :
183199 continue
184200 in_files .append (os .path .join (file_in_dir ))
185201 else :
186202 # Only here for consistency
187203 # Why would you specify a file input then add that file
188204 # to a list of files to ignore?
189- if file in skip_inputs :
205+ if file in skip_inputs or os . path . basename ( file ) in skip_inputs :
190206 continue
191207 in_files .append (os .path .join (file ))
192208 file_count = len (in_files )
@@ -206,24 +222,28 @@ def exit_if_missing(file_path: str, allow_dir: bool = True):
206222
207223# Perform action based on mode
208224if mode == "audio" :
209- extract_audio (fn , output , skip_menus )
225+ extract_audio (debug , fn , output , skip_menus )
210226elif mode == "subs" :
211- extract_subs (fn , output )
227+ extract_subs (debug , fn , output )
212228elif mode == "mux" :
213- mux (fn , output )
229+ mux (debug , fn , output )
214230elif mode == "shader" :
215- shader (in_files , args ['width' ], args ['height' ],
231+ shader (debug , in_files , args ['width' ], args ['height' ],
216232 args ['shader_dir' ], args ['bit' ], args ['audio_language' ],
217- args ['softsubs' ], args ['softaudio' ], skip_menus , True , output )
233+ args ['softsubs' ], args ['softaudio' ], args ['fps' ], skip_menus , True ,
234+ output )
218235elif mode == "multi" :
219- multi (in_files , args ['width' ], args ['height' ],
220- args ['shader_dir' ], args ['bit' ], skip_menus ,
236+ multi (debug , in_files , args ['width' ], args ['height' ],
237+ args ['shader_dir' ], args ['bit' ], args [ 'fps' ], skip_menus ,
221238 args ['delete_failures' ], output )
222239elif mode == "encode" :
223- encode_to_hevc (in_files , output , skip_menus )
240+ encode_to_hevc (debug , in_files , output , skip_menus )
224241elif mode == "split" :
225242 length = get_video_length (fn )
226- split_by_seconds (filename = fn , split_length = args ['split_length' ],
243+ split_by_seconds (debug = debug , filename = fn ,
244+ split_length = args ['split_length' ],
227245 video_length = length , split_dir = output )
246+ elif mode == "patch" :
247+ patch (debug , in_files , skip_menus , output )
228248else :
229249 print ("Unknown mode: {0}" .format (mode ))
0 commit comments