Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WIDTH1 = 0
- HEIGHT1 = 0
- import re
- import os
- import time
- import cv2
- from colormap import rgb2hex
- from PIL import Image
- from shutil import move
- mode = 2
- def tobyte(r,g,b):
- a = chr(r)+chr(g)+chr(b)
- return a
- FILEINPUT = input("Input video file. ")
- if not FILEINPUT or not os.path.exists(FILEINPUT):
- print("Invalid video file.")
- else:
- #
- vid = cv2.VideoCapture(FILEINPUT)
- height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
- width = vid.get(cv2.CAP_PROP_FRAME_WIDTH)
- div = float(input("Input multiplier size. "))
- WIDTH1 = round(width*div)
- HEIGHT1 = round(height*div)
- bruh = True
- c1 = input("Video will be " + str(HEIGHT1) + "x" + str(WIDTH1) + " resolution. Continue? (y/n)")
- if str.lower(c1) == 'y':
- print("Running..")
- pass
- else:
- print("Quitting..")
- bruh = False
- #
- while bruh:
- time.sleep(1/10)
- count = 0
- while True:
- #
- time.sleep(1/10)
- count += 1
- ret, frame = vid.read()
- if not ret:
- break
- new_im = cv2.resize(frame,(WIDTH1, HEIGHT1),fx=0,fy=0,interpolation=cv2.INTER_CUBIC)
- new_im = cv2.cvtColor(new_im, cv2.COLOR_BGR2RGB)
- npd = ''
- for y in new_im:
- for x in y:
- r,g,b = x
- if mode == 2: #hex compression
- npd = npd + rgb2hex(r,g,b)
- elif mode == 3: #byte compression
- npd = npd + tobyte(r,g,b)
- else: #grayscale compression
- npd = npd + str("{:03d}".format(r+g+b))
- if mode == 3:
- npd = npd.encode('utf8')
- pixf = open("data_r.json", "wb+")
- elif mode == 2:
- npd = npd.replace('#', '', len(npd))
- pixf = open("data_r.json", "w+")
- else:
- pixf = open("data_r.json", "w+")
- sizef = open("size_r.json", "w+")
- st = [WIDTH1, HEIGHT1]
- fst = re.sub('[ ]', '', str(st))
- pixf.write(npd)
- sizef.write(fst)
- pixf.close()
- sizef.close()
- f = 'data_r.json'
- move(f,f.replace('_r.json','.json'))
- f2 = 'size_r.json'
- move(f2,f2.replace('_r.json','.json'))
- #
- print("Success frame: " + str(count))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement