diff options
author | Anthony Wang | 2024-04-23 21:12:39 -0400 |
---|---|---|
committer | Anthony Wang | 2024-04-23 21:12:39 -0400 |
commit | 74b6ae8ddc7506a57b6ba197b67b629f869794a8 (patch) | |
tree | e491ab85674b36c44383f6ad71a26d51c7e328eb /encoder.py | |
parent | 6d315e7a8e476ef9e20691f8c991614bcab7205a (diff) |
Purge PyQt
Diffstat (limited to 'encoder.py')
-rw-r--r-- | encoder.py | 79 |
1 files changed, 24 insertions, 55 deletions
@@ -1,12 +1,7 @@ import argparse -import sys import cv2 import numpy as np from creedsolo import RSCodec -from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout -from PyQt6.QtGui import QPixmap -from PyQt6.QtCore import QTimer -from PIL import Image, ImageQt from raptorq import Encoder parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) @@ -78,55 +73,29 @@ def get_frame(): ).astype(np.uint8) -class EncoderWidget(QWidget): - def __init__(self): - super().__init__() - self.timer = QTimer(self) - self.timer.timeout.connect(self.update) - self.timer.start(1000 // args.fps) - self.label = QLabel(self) - layout = QVBoxLayout(self) - layout.addWidget(self.label) - layout.setContentsMargins(0, 0, 0, 0) - self.setLayout(layout) - self.showFullScreen() - - def update(self): - img = Image.fromarray(get_frame()) - qt_img = ImageQt.ImageQt(img) - pixmap = QPixmap.fromImage(qt_img).scaled(self.size()) - self.label.setPixmap(pixmap) - - -if args.output: - if args.mix: - cap = cv2.VideoCapture(args.input) - height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) - width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) - hscale = height // args.height - wscale = width // args.width - out = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc(*"RGBA"), args.fps, (width, height)) - while cap.isOpened(): - ret, frame = cap.read() - if not ret: - break - frame = frame.astype(np.float64) / 255 - frame[: hscale * cheight, : wscale * cwidth] = 1 - frame[: hscale * cheight, wscale * (args.width - cwidth) :] = 1 - frame[hscale * (args.height - cheight) :, : wscale * cwidth] = 1 - frame[hscale * (args.height - cheight) :, wscale * (args.width - cwidth) :] = 1 - out.write( - cv2.cvtColor( - (frame * np.repeat(np.repeat(get_frame(), hscale, 0), wscale, 1)).astype(np.uint8), - cv2.COLOR_RGB2BGR, - ) +if args.mix: + cap = cv2.VideoCapture(args.input) + height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + hscale = height // args.height + wscale = width // args.width + out = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc(*"FFV1"), args.fps, (width, height)) + while cap.isOpened(): + ret, frame = cap.read() + if not ret: + break + frame = frame.astype(np.float64) / 255 + frame[: hscale * cheight, : wscale * cwidth] = 1 + frame[: hscale * cheight, wscale * (args.width - cwidth) :] = 1 + frame[hscale * (args.height - cheight) :, : wscale * cwidth] = 1 + frame[hscale * (args.height - cheight) :, wscale * (args.width - cwidth) :] = 1 + out.write( + cv2.cvtColor( + (frame * np.repeat(np.repeat(get_frame(), hscale, 0), wscale, 1)).astype(np.uint8), + cv2.COLOR_RGB2BGR, ) - else: - out = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc(*"RGBA"), args.fps, (args.width, args.height)) - for _ in packets: - out.write(cv2.cvtColor(get_frame(), cv2.COLOR_RGB2BGR)) + ) else: - input("Seizure warning!") - app = QApplication([]) - widget = EncoderWidget() - sys.exit(app.exec()) + out = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc(*"FFV1"), args.fps, (args.width, args.height)) + for _ in packets: + out.write(cv2.cvtColor(get_frame(), cv2.COLOR_RGB2BGR)) |