From a8e02b89d0095abc88f1cc356d21f2e2d0be4e42 Mon Sep 17 00:00:00 2001 From: EonZeNx Date: Wed, 18 Nov 2020 12:07:56 +1300 Subject: [PATCH] More robust video file path getter --- inference_mp4_2x.py | 5 +++-- inference_mp4_4x.py | 5 +++-- inference_mp4_4x_parallel.py | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/inference_mp4_2x.py b/inference_mp4_2x.py index 31be380..5dcd4f1 100644 --- a/inference_mp4_2x.py +++ b/inference_mp4_2x.py @@ -36,7 +36,8 @@ if args.png: if not os.path.exists('output'): os.mkdir('output') else: - output = cv2.VideoWriter('{}_2x.{}'.format(args.video[:-4], args.ext), fourcc, args.fps, (w, h)) + video_path_wo_ext, ext = os.path.splitext(args.video) + output = cv2.VideoWriter('{}_2x.{}'.format(video_path_wo_ext, args.ext), fourcc, args.fps, (w, h)) cnt = 0 def writeframe(frame): @@ -54,7 +55,7 @@ ph = ((h - 1) // 32 + 1) * 32 pw = ((w - 1) // 32 + 1) * 32 padding = (0, pw - w, 0, ph - h) tot_frame = videoCapture.get(cv2.CAP_PROP_FRAME_COUNT) -print('{}.{}, {} frames in total, {}FPS to {}FPS'.format(args.video[:-4], args.ext, tot_frame, fps, args.fps)) +print('{}.{}, {} frames in total, {}FPS to {}FPS'.format(video_path_wo_ext, args.ext, tot_frame, fps, args.fps)) pbar = tqdm(total=tot_frame) skip_frame = 1 if args.montage: diff --git a/inference_mp4_4x.py b/inference_mp4_4x.py index 5ba2a52..4135592 100644 --- a/inference_mp4_4x.py +++ b/inference_mp4_4x.py @@ -36,7 +36,8 @@ if args.png: if not os.path.exists('output'): os.mkdir('output') else: - output = cv2.VideoWriter('{}_4x.{}'.format(args.video[:-4], args.ext), fourcc, args.fps, (w, h)) + video_path_wo_ext, ext = os.path.splitext(args.video) + output = cv2.VideoWriter('{}_4x.{}'.format(video_path_wo_ext, args.ext), fourcc, args.fps, (w, h)) cnt = 0 def writeframe(frame): @@ -53,7 +54,7 @@ ph = ((h - 1) // 32 + 1) * 32 pw = ((w - 1) // 32 + 1) * 32 padding = (0, pw - w, 0, ph - h) tot_frame = videoCapture.get(cv2.CAP_PROP_FRAME_COUNT) -print('{}.{}, {} frames in total, {}FPS to {}FPS'.format(args.video[:-4], args.ext, tot_frame, fps, args.fps)) +print('{}.{}, {} frames in total, {}FPS to {}FPS'.format(video_path_wo_ext, args.ext, tot_frame, fps, args.fps)) pbar = tqdm(total=tot_frame) skip_frame = 1 if args.montage: diff --git a/inference_mp4_4x_parallel.py b/inference_mp4_4x_parallel.py index f1de0ab..715e9f0 100644 --- a/inference_mp4_4x_parallel.py +++ b/inference_mp4_4x_parallel.py @@ -35,7 +35,8 @@ if args.png: if not os.path.exists('output'): os.mkdir('output') else: - output = cv2.VideoWriter('{}_4x.{}'.format(args.video[:-4], args.ext), fourcc, args.fps, (w, h)) + video_path_wo_ext, ext = os.path.splitext(args.video) + output = cv2.VideoWriter('{}_4x.{}'.format(video_path_wo_ext, args.ext), fourcc, args.fps, (w, h)) cnt = 0 skip_frame = 1 @@ -71,7 +72,7 @@ ph = ((h - 1) // 32 + 1) * 32 pw = ((w - 1) // 32 + 1) * 32 padding = (0, pw - w, 0, ph - h) tot_frame = videoCapture.get(cv2.CAP_PROP_FRAME_COUNT) -print('{}.{}, {} frames in total, {}FPS to {}FPS'.format(args.video[:-4], args.ext, tot_frame, fps, args.fps)) +print('{}.{}, {} frames in total, {}FPS to {}FPS'.format(video_path_wo_ext, args.ext, tot_frame, fps, args.fps)) pbar = tqdm(total=tot_frame) img_list = [frame] while success: