support windows style paths

This commit is contained in:
Somdev Sangwan 2023-05-29 18:53:10 +05:30 committed by GitHub
parent 499bd2e3f6
commit d72d9d7328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
run.py
View File

@ -28,6 +28,10 @@ parser.add_argument('--keep-frames', help='keep frames directory', dest='keep_fr
for name, value in vars(parser.parse_args()).items(): for name, value in vars(parser.parse_args()).items():
args[name] = value args[name] = value
sep = "/" # used for filepaths e.g. /root/path/output.mp4
if os.name == 'nt':
sep = "\\" # for windows
def start_processing(): def start_processing():
if args['gpu']: if args['gpu']:
process_video(args['source_img'], args["frame_paths"]) process_video(args['source_img'], args["frame_paths"])
@ -77,12 +81,12 @@ def start():
if is_img(target_path): if is_img(target_path):
process_img(args['source_img'], target_path) process_img(args['source_img'], target_path)
return return
video_name = target_path.split("/")[-1].split(".")[0] video_name = target_path.split(sep)[-1].split(".")[0]
output_dir = target_path.replace(target_path.split("/")[-1], "") + "/" + video_name output_dir = target_path.replace(target_path.split(sep)[-1], "") + sep + video_name
Path(output_dir).mkdir(exist_ok=True) Path(output_dir).mkdir(exist_ok=True)
fps = detect_fps(target_path) fps = detect_fps(target_path)
if not args['keep_fps'] and fps > 30: if not args['keep_fps'] and fps > 30:
this_path = output_dir + "/" + video_name + ".mp4" this_path = output_dir + sep + video_name + ".mp4"
set_fps(target_path, this_path, 30) set_fps(target_path, this_path, 30)
target_path, fps = this_path, 30 target_path, fps = this_path, 30
else: else:
@ -90,12 +94,12 @@ def start():
extract_frames(target_path, output_dir) extract_frames(target_path, output_dir)
args['frame_paths'] = tuple(sorted( args['frame_paths'] = tuple(sorted(
glob.glob(output_dir + "/*.png"), glob.glob(output_dir + "/*.png"),
key=lambda x: int(x.split("/")[-1].replace(".png", "")) key=lambda x: int(x.split(sep)[-1].replace(".png", ""))
)) ))
start_processing() start_processing()
create_video(video_name, fps, output_dir) create_video(video_name, fps, output_dir)
add_audio(output_dir, target_path, args['keep_frames'], args['output_file']) add_audio(output_dir, target_path, args['keep_frames'], args['output_file'])
save_path = args['output_file'] if args['output_file'] else output_dir + "/" + video_name + ".mp4" save_path = args['output_file'] if args['output_file'] else output_dir + sep + video_name + ".mp4"
print("\n\nVideo saved as:", save_path, "\n\n") print("\n\nVideo saved as:", save_path, "\n\n")