fix time delay and warmup

This commit is contained in:
lipku 2024-04-20 08:29:08 +08:00
parent 1e52055d65
commit b9d77f9fb5
1 changed files with 6 additions and 5 deletions

View File

@ -61,6 +61,7 @@ class NeRFReal:
# build asr # build asr
if self.opt.asr: if self.opt.asr:
self.asr = ASR(opt) self.asr = ASR(opt)
self.asr.warm_up()
''' '''
video_path = 'video_stream' video_path = 'video_stream'
@ -185,8 +186,8 @@ class NeRFReal:
#t = starter.elapsed_time(ender) #t = starter.elapsed_time(ender)
def render(self,quit_event,loop=None,audio_track=None,video_track=None): def render(self,quit_event,loop=None,audio_track=None,video_track=None):
if self.opt.asr: #if self.opt.asr:
self.asr.warm_up() # self.asr.warm_up()
count=0 count=0
totaltime=0 totaltime=0
@ -216,19 +217,19 @@ class NeRFReal:
while not quit_event.is_set(): #todo while not quit_event.is_set(): #todo
# update texture every frame # update texture every frame
# audio stream thread... # audio stream thread...
t = time.time() t = time.perf_counter()
if self.opt.asr and self.playing: if self.opt.asr and self.playing:
# run 2 ASR steps (audio is at 50FPS, video is at 25FPS) # run 2 ASR steps (audio is at 50FPS, video is at 25FPS)
for _ in range(2): for _ in range(2):
self.asr.run_step() self.asr.run_step()
self.test_step(loop,audio_track,video_track) self.test_step(loop,audio_track,video_track)
totaltime += (time.time() - t) totaltime += (time.perf_counter() - t)
count += 1 count += 1
if count==100: if count==100:
print(f"------actual avg fps:{count/totaltime:.4f}") print(f"------actual avg fps:{count/totaltime:.4f}")
count=0 count=0
totaltime=0 totaltime=0
delay = 0.04 - (time.time() - t) #40ms delay = 0.04 - (time.perf_counter() - t) #40ms
if delay > 0: if delay > 0:
time.sleep(delay) time.sleep(delay)