aboutsummaryrefslogtreecommitdiff
path: root/encoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'encoder.py')
-rw-r--r--encoder.py79
1 files changed, 24 insertions, 55 deletions
diff --git a/encoder.py b/encoder.py
index 3b67cf0..15ee859 100644
--- a/encoder.py
+++ b/encoder.py
@@ -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))