aboutsummaryrefslogtreecommitdiff
path: root/encoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'encoder.py')
-rw-r--r--encoder.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/encoder.py b/encoder.py
index bd44876..634a166 100644
--- a/encoder.py
+++ b/encoder.py
@@ -39,12 +39,14 @@ rcorner = np.pad(np.dstack((ones, zeros, zeros)), ((0, 1), (1, 0), (0, 0)))
gcorner = np.pad(np.dstack((zeros, ones, zeros)), ((1, 0), (0, 1), (0, 0)))
bcorner = np.pad(np.dstack((zeros, zeros, ones)), ((1, 0), (1, 0), (0, 0)))
+# Output flags for decoder
print(f"-x {args.height} -y {args.width} -l {args.level} -s {len(data)} -p {len(packets[0])}", end="")
def mkframe(packet):
frame = np.array(rsc.encode(bytearray(packet)))
frame = np.unpackbits(np.pad(frame, (0, frame_bytes - len(frame))) ^ frame_xor)
+ # Pad to be multiple of 3 so we can reshape into RGB channels
frame = np.pad(frame, (0, (3 - len(frame)) % 3))
frame = np.reshape(frame, (frame_size, 3))
frame = np.concatenate(
@@ -66,6 +68,7 @@ def mkframe(packet):
if args.mix:
+ # Mix frames with original video
cap = cv2.VideoCapture(args.input)
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
@@ -81,12 +84,13 @@ if args.mix:
vidframe[: hscale * cheight, wscale * (args.width - cwidth) :] = 0
vidframe[hscale * (args.height - cheight) :, : wscale * cwidth] = 0
vidframe[hscale * (args.height - cheight) :, wscale * (args.width - cwidth) :] = 0
-
frame = np.repeat(np.repeat(mkframe(packets[i]), hscale, 0), wscale, 1)
+ # Set edges in original video to black
frame[vidframe % 255 != 0] = 0
out.write(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
i = (i + 1) % len(packets)
else:
+ # Create a new video
out = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc(*"FFV1"), args.fps, (args.width, args.height))
for packet in packets:
out.write(cv2.cvtColor(mkframe(packet), cv2.COLOR_RGB2BGR))