@@ -90,39 +90,42 @@ async def _capture_video(self) -> None:
9090 while not self ._stopped :
9191 frame , timestamp = await self ._video_queue .get ()
9292
93- # debug
94- frame_rgba = np .frombuffer (frame .data , dtype = np .uint8 ).reshape (
95- frame .height , frame .width , 4
96- )
97- frame_bgr = cv2 .cvtColor (frame_rgba [:, :, :3 ], cv2 .COLOR_RGBA2BGR )
98- frame_bgr = cv2 .putText (
99- frame_bgr ,
100- f"{ self .actual_fps :.2f} fps, video time: { timestamp :.3f} s, audio time: { self .last_audio_time :.3f} s" ,
101- (10 , 100 ),
102- cv2 .FONT_HERSHEY_SIMPLEX ,
103- 1 ,
104- (0 , 0 , 255 ),
105- 2 ,
106- )
107- frame_rgba = cv2 .cvtColor (frame_bgr , cv2 .COLOR_BGR2RGBA )
108- frame = VideoFrame (
109- width = frame .width ,
110- height = frame .height ,
111- type = frame .type ,
112- data = frame_rgba .tobytes (),
113- )
114- count += 1
115- if count % 30 == 0 :
116- print (
117- f"{ self .actual_fps :.2f} fps, last video time: { self .last_video_time :.3f} s, "
118- f"last audio time: { self .last_audio_time :.3f} s"
93+ async with self ._fps_controller :
94+ # debug
95+ frame_rgba = np .frombuffer (frame .data , dtype = np .uint8 ).reshape (
96+ frame .height , frame .width , 4
97+ )
98+ frame_bgr = cv2 .cvtColor (frame_rgba [:, :, :3 ], cv2 .COLOR_RGBA2BGR )
99+ frame_bgr = cv2 .putText (
100+ frame_bgr ,
101+ f"{ self .actual_fps :.2f} fps, video time: { timestamp :.3f} s, "
102+ f"audio time: { self .last_audio_time :.3f} s, diff: { timestamp - self .last_audio_time :.3f} s" ,
103+ (10 , 100 ),
104+ cv2 .FONT_HERSHEY_SIMPLEX ,
105+ 1 ,
106+ (0 , 0 , 255 ),
107+ 2 ,
108+ )
109+ frame_rgba = cv2 .cvtColor (frame_bgr , cv2 .COLOR_BGR2RGBA )
110+ frame = VideoFrame (
111+ width = frame .width ,
112+ height = frame .height ,
113+ type = frame .type ,
114+ data = frame_rgba .tobytes (),
119115 )
120- # end debug
116+ count += 1
117+ # end debug
121118
122- async with self ._fps_controller :
123119 self ._video_source .capture_frame (frame )
124120 if timestamp is not None :
125121 self ._last_video_time = timestamp
122+
123+ if count % 30 == 0 :
124+ diff = self .last_video_time - self .last_audio_time
125+ print (
126+ f"{ self .actual_fps :.2f} fps, last video time: { self .last_video_time :.3f} s, "
127+ f"last audio time: { self .last_audio_time :.3f} s, diff: { diff :.3f} s"
128+ )
126129 self ._video_queue .task_done ()
127130
128131 async def aclose (self ) -> None :
@@ -140,7 +143,7 @@ def last_video_time(self) -> float:
140143
141144 @property
142145 def last_audio_time (self ) -> float :
143- return self ._last_audio_time
146+ return self ._last_audio_time - self . _audio_source . queued_duration
144147
145148
146149class _FPSController :
0 commit comments