【BadApple】badApple但坏掉的我并且是800年前画质,新人烂活

#代码极其简单:
import CV2 as cv
import os
import time
def PlayVideo(fileName):
# 替换字符列表
ascii_char = list(r" █")
char_len = len(ascii_char)
# 加载视频
cap = cv.VideoCapture(fileName)
termSize = os.get_terminal_size()
texts = []
while True:
# 读取视频每一帧 跳帧
for i in range(3):
hasFrame, frame = cap.read()
if not hasFrame:
break
# 视频长宽
width = frame.shape[0]
height = frame.shape[1]
# 转灰度图
img_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# 缩小图片并调整长宽比
img_resize = cv.resize(img_gray, (termSize.columns, termSize.lines - 1))
text = ''
# 遍历图片中的像素
for row in img_resize:
for pixel in row:
# 根据像素值,选取对应的字符
text += ascii_char[int(pixel / 256 * char_len)]
text += '\n'
texts.append(text)
for text in texts:
# 清屏
os.system('clear')
print(text)
time.sleep(0.005)
# PlayVideo END
filename = input("视频文件名:")
PlayVideo(filename)