Skip to content

Commit d291919

Browse files
committed
update video2video script
1 parent 15c0f70 commit d291919

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

video2video.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
def get_args():
1212
parser = argparse.ArgumentParser("Image to ASCII")
1313
parser.add_argument("--input", type=str, default="data/input.mp4", help="Path to input video")
14-
parser.add_argument("--output", type=str, default="data/output.avi", help="Path to output video")
14+
parser.add_argument("--output", type=str, default="data/output.mp4", help="Path to output video")
1515
parser.add_argument("--mode", type=str, default="simple", choices=["simple", "complex"],
1616
help="10 or 70 different characters")
1717
parser.add_argument("--background", type=str, default="white", choices=["black", "white"],
1818
help="background's color")
1919
parser.add_argument("--num_cols", type=int, default=100, help="number of character for output's width")
2020
parser.add_argument("--scale", type=int, default=1, help="upsize output")
2121
parser.add_argument("--fps", type=int, default=0, help="frame per second")
22+
parser.add_argument("--overlay_ratio", type=float, default=0.2, help="Overlay width ratio")
2223
args = parser.parse_args()
2324
return args
2425

@@ -41,9 +42,9 @@ def main(opt):
4142
num_chars = len(CHAR_LIST)
4243
num_cols = opt.num_cols
4344
while cap.isOpened():
44-
flag, image = cap.read()
45+
flag, frame = cap.read()
4546
if flag:
46-
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
47+
image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
4748
else:
4849
break
4950
height, width = image.shape
@@ -81,6 +82,10 @@ def main(opt):
8182
out = cv2.VideoWriter(opt.output, cv2.VideoWriter_fourcc(*"XVID"), fps,
8283
((out_image.shape[1], out_image.shape[0])))
8384

85+
if opt.overlay_ratio:
86+
height, width, _ = out_image.shape
87+
overlay = cv2.resize(frame, (int(width * opt.overlay_ratio), int(height * opt.overlay_ratio)))
88+
out_image[height - int(height * opt.overlay_ratio):, width - int(width * opt.overlay_ratio):, :] = overlay
8489
out.write(out_image)
8590
cap.release()
8691
out.release()

0 commit comments

Comments
 (0)