video sending and playing, temporary hardcoded size

This commit is contained in:
ingvar1995 2017-06-13 00:26:21 +03:00
parent d0e2f61d03
commit a2273e8c27
2 changed files with 33 additions and 12 deletions

View file

@ -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

View file

@ -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)