From a2273e8c2765439a0d1943553474fc6ded8c030c Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 13 Jun 2017 00:26:21 +0300 Subject: [PATCH] video sending and playing, temporary hardcoded size --- toxygen/callbacks.py | 28 +++++++++++++++++++++++----- toxygen/calls.py | 17 ++++++++++------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/toxygen/callbacks.py b/toxygen/callbacks.py index 01a14d4..f3cd71a 100644 --- a/toxygen/callbacks.py +++ b/toxygen/callbacks.py @@ -12,7 +12,6 @@ import util import cv2 import numpy as np - # ----------------------------------------------------------------------------------------------------------------- # Threads # ----------------------------------------------------------------------------------------------------------------- @@ -325,10 +324,29 @@ def callback_audio(toxav, friend_number, samples, audio_samples_per_channel, aud def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, ustride, vstride, user_data): - pass - #frame = cv2.merge((np.asarray(y), np.asarray(u), np.asarray(v))) - #frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420) - #cv2.imshow("frame", frame) + try: + Y = abs(max(width, abs(ystride))) + U = abs(max(width//2, abs(ustride))) + V = abs(max(width//2, abs(vstride))) + y = np.asarray(y[:Y * height], dtype=np.uint8).reshape(height, Y) + u = np.asarray(u[:U * height // 2], dtype=np.uint8).reshape(height // 2, U) + v = np.asarray(v[:V * height // 2], dtype=np.uint8).reshape(height // 2, V) + frame = np.zeros((int(height * 1.5), width), dtype=np.uint8) + + frame[:height,:] = y[:,:width] + #tmp, tmp2 = u[::2,:width], frame[height:height * 5 // 4, :width // 2] + #print(tmp.shape, tmp2.shape + frame[height:height * 5 // 4, :width // 2] = u[:140:2,:width // 2] + frame[height:height * 5 // 4, width // 2:] = u[1:140:2,:width // 2] + + frame[height * 5 // 4 + 1:, :width // 2] = v[:140:2,:width // 2] + frame[height * 5 // 4 + 1:, width // 2:] = v[1:140:2,:width // 2] + + frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420) + + invoke_in_main_thread(cv2.imshow, str(friend_number), frame) + except Exception as ex: + print(ex) # ----------------------------------------------------------------------------------------------------------------- # Callbacks - initialization diff --git a/toxygen/calls.py b/toxygen/calls.py index f2600c9..a771470 100644 --- a/toxygen/calls.py +++ b/toxygen/calls.py @@ -218,14 +218,17 @@ class AV: def convert_bgr_to_yuv(frame): frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420) + y = frame[:480,:].tolist() y = list(itertools.chain.from_iterable(y)) - v = np.zeros((240, 320), dtype=np.int) - v[::2,:] = frame[480:600, :320] - v[1::2,:] = frame[480:600, 320:] - v = list(itertools.chain.from_iterable(v)) + u = np.zeros((240, 320), dtype=np.int) - u[::2,:] = frame[600:, :320] - u[1::2,:] = frame[600:, 320:] + u[::2,:] = frame[480:600, :320] + u[1::2,:] = frame[480:600, 320:] u = list(itertools.chain.from_iterable(u)) - return bytes(y), bytes(v), bytes(u) + + v = np.zeros((240, 320), dtype=np.int) + v[::2,:] = frame[600:, :320] + v[1::2,:] = frame[600:, 320:] + v = list(itertools.chain.from_iterable(v)) + return bytes(y), bytes(u), bytes(v)