|
|
|
@ -57,6 +57,8 @@ class NeRFReal:
|
|
|
|
|
self.ind_index = 0
|
|
|
|
|
self.ind_num = trainer.model.individual_codes.shape[0]
|
|
|
|
|
|
|
|
|
|
self.customimg_index = 0
|
|
|
|
|
|
|
|
|
|
# build asr
|
|
|
|
|
if self.opt.asr:
|
|
|
|
|
self.asr = ASR(opt)
|
|
|
|
@ -114,6 +116,15 @@ class NeRFReal:
|
|
|
|
|
def before_push_audio(self):
|
|
|
|
|
self.asr.before_push_audio()
|
|
|
|
|
|
|
|
|
|
def mirror_index(self, index):
|
|
|
|
|
size = self.opt.customvideo_imgnum
|
|
|
|
|
turn = index // size
|
|
|
|
|
res = index % size
|
|
|
|
|
if turn % 2 == 0:
|
|
|
|
|
return res
|
|
|
|
|
else:
|
|
|
|
|
return size - res - 1
|
|
|
|
|
|
|
|
|
|
def prepare_buffer(self, outputs):
|
|
|
|
|
if self.mode == 'image':
|
|
|
|
|
return outputs['image']
|
|
|
|
@ -136,53 +147,60 @@ class NeRFReal:
|
|
|
|
|
# use the live audio stream
|
|
|
|
|
data['auds'] = self.asr.get_next_feat()
|
|
|
|
|
|
|
|
|
|
#t = time.time()
|
|
|
|
|
outputs = self.trainer.test_gui_with_data(data, self.W, self.H)
|
|
|
|
|
#print('-------ernerf time: ',time.time()-t)
|
|
|
|
|
#print(f'[INFO] outputs shape ',outputs['image'].shape)
|
|
|
|
|
image = (outputs['image'] * 255).astype(np.uint8)
|
|
|
|
|
if not self.opt.fullbody:
|
|
|
|
|
if self.opt.transport=='rtmp':
|
|
|
|
|
self.streamer.stream_frame(image)
|
|
|
|
|
else:
|
|
|
|
|
new_frame = VideoFrame.from_ndarray(image, format="rgb24")
|
|
|
|
|
asyncio.run_coroutine_threadsafe(video_track._queue.put(new_frame), loop)
|
|
|
|
|
else: #fullbody human
|
|
|
|
|
#print("frame index:",data['index'])
|
|
|
|
|
image_fullbody = cv2.imread(os.path.join(self.opt.fullbody_img, str(data['index'][0])+'.jpg'))
|
|
|
|
|
image_fullbody = cv2.cvtColor(image_fullbody, cv2.COLOR_BGR2RGB)
|
|
|
|
|
start_x = self.opt.fullbody_offset_x # 合并后小图片的起始x坐标
|
|
|
|
|
start_y = self.opt.fullbody_offset_y # 合并后小图片的起始y坐标
|
|
|
|
|
image_fullbody[start_y:start_y+image.shape[0], start_x:start_x+image.shape[1]] = image
|
|
|
|
|
if self.opt.transport=='rtmp':
|
|
|
|
|
self.streamer.stream_frame(image_fullbody)
|
|
|
|
|
else:
|
|
|
|
|
new_frame = VideoFrame.from_ndarray(image_fullbody, format="rgb24")
|
|
|
|
|
asyncio.run_coroutine_threadsafe(video_track._queue.put(new_frame), loop)
|
|
|
|
|
#self.pipe.stdin.write(image.tostring())
|
|
|
|
|
audiotype = 0
|
|
|
|
|
if self.opt.transport=='rtmp':
|
|
|
|
|
for _ in range(2):
|
|
|
|
|
frame = self.asr.get_audio_out()
|
|
|
|
|
frame,type = self.asr.get_audio_out()
|
|
|
|
|
audiotype += type
|
|
|
|
|
#print(f'[INFO] get_audio_out shape ',frame.shape)
|
|
|
|
|
self.streamer.stream_frame_audio(frame)
|
|
|
|
|
else:
|
|
|
|
|
for _ in range(2):
|
|
|
|
|
frame = self.asr.get_audio_out()
|
|
|
|
|
frame,type = self.asr.get_audio_out()
|
|
|
|
|
audiotype += type
|
|
|
|
|
frame = (frame * 32767).astype(np.int16)
|
|
|
|
|
new_frame = AudioFrame(format='s16', layout='mono', samples=frame.shape[0])
|
|
|
|
|
new_frame.planes[0].update(frame.tobytes())
|
|
|
|
|
new_frame.sample_rate=16000
|
|
|
|
|
asyncio.run_coroutine_threadsafe(audio_track._queue.put(new_frame), loop)
|
|
|
|
|
# frame1 = self.asr.get_audio_out()
|
|
|
|
|
# frame2 = self.asr.get_audio_out()
|
|
|
|
|
# frame = np.concatenate((frame1,frame2))
|
|
|
|
|
# frame = (frame * 32767).astype(np.int16)
|
|
|
|
|
# new_frame = AudioFrame(format='s16', layout='mono', samples=frame.shape[0])
|
|
|
|
|
# new_frame.planes[0].update(frame.tobytes())
|
|
|
|
|
# new_frame.sample_rate=16000
|
|
|
|
|
# asyncio.run_coroutine_threadsafe(audio_track._queue.put(new_frame), loop)
|
|
|
|
|
# frame = (frame * 32767).astype(np.int16).tobytes()
|
|
|
|
|
# self.fifo_audio.write(frame)
|
|
|
|
|
#t = time.time()
|
|
|
|
|
if self.opt.customvideo and audiotype!=0:
|
|
|
|
|
self.loader = iter(self.data_loader) #init
|
|
|
|
|
imgindex = self.mirror_index(self.customimg_index)
|
|
|
|
|
#print('custom img index:',imgindex)
|
|
|
|
|
image = cv2.imread(os.path.join(self.opt.customvideo_img, str(int(imgindex))+'.png'))
|
|
|
|
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
|
|
|
|
if self.opt.transport=='rtmp':
|
|
|
|
|
self.streamer.stream_frame(image)
|
|
|
|
|
else:
|
|
|
|
|
new_frame = VideoFrame.from_ndarray(image, format="rgb24")
|
|
|
|
|
asyncio.run_coroutine_threadsafe(video_track._queue.put(new_frame), loop)
|
|
|
|
|
self.customimg_index += 1
|
|
|
|
|
else:
|
|
|
|
|
self.customimg_index = 0
|
|
|
|
|
outputs = self.trainer.test_gui_with_data(data, self.W, self.H)
|
|
|
|
|
#print('-------ernerf time: ',time.time()-t)
|
|
|
|
|
#print(f'[INFO] outputs shape ',outputs['image'].shape)
|
|
|
|
|
image = (outputs['image'] * 255).astype(np.uint8)
|
|
|
|
|
if not self.opt.fullbody:
|
|
|
|
|
if self.opt.transport=='rtmp':
|
|
|
|
|
self.streamer.stream_frame(image)
|
|
|
|
|
else:
|
|
|
|
|
new_frame = VideoFrame.from_ndarray(image, format="rgb24")
|
|
|
|
|
asyncio.run_coroutine_threadsafe(video_track._queue.put(new_frame), loop)
|
|
|
|
|
else: #fullbody human
|
|
|
|
|
#print("frame index:",data['index'])
|
|
|
|
|
image_fullbody = cv2.imread(os.path.join(self.opt.fullbody_img, str(data['index'][0])+'.jpg'))
|
|
|
|
|
image_fullbody = cv2.cvtColor(image_fullbody, cv2.COLOR_BGR2RGB)
|
|
|
|
|
start_x = self.opt.fullbody_offset_x # 合并后小图片的起始x坐标
|
|
|
|
|
start_y = self.opt.fullbody_offset_y # 合并后小图片的起始y坐标
|
|
|
|
|
image_fullbody[start_y:start_y+image.shape[0], start_x:start_x+image.shape[1]] = image
|
|
|
|
|
if self.opt.transport=='rtmp':
|
|
|
|
|
self.streamer.stream_frame(image_fullbody)
|
|
|
|
|
else:
|
|
|
|
|
new_frame = VideoFrame.from_ndarray(image_fullbody, format="rgb24")
|
|
|
|
|
asyncio.run_coroutine_threadsafe(video_track._queue.put(new_frame), loop)
|
|
|
|
|
#self.pipe.stdin.write(image.tostring())
|
|
|
|
|
else:
|
|
|
|
|
if self.audio_features is not None:
|
|
|
|
|
auds = get_audio_features(self.audio_features, self.opt.att, self.audio_idx)
|
|
|
|
|