diff --git a/hls_service_ws_kadian.py b/hls_service_ws_kadian.py index e7b9a0d..b44720c 100644 --- a/hls_service_ws_kadian.py +++ b/hls_service_ws_kadian.py @@ -58,6 +58,7 @@ class HLSFrameProcessor(threading.Thread): self.pts_diff = 0 self.should_reset_time = False + self.current_segment_duration = None # 当前分片时长(秒) def get_latest_n_segments(self, n: int) -> list: """获取最新的n个TS分片(委托给工具函数)""" @@ -152,6 +153,8 @@ class HLSFrameProcessor(threading.Thread): "timestamp": current_time, "camera_index": self.camera_cfg.index, "frame": frame_data, + "segment_path": self.current_segment_path, + "segment_duration": self.current_segment_duration, } try: @@ -234,6 +237,12 @@ class HLSFrameProcessor(threading.Thread): container = av.open(segment_path) video_stream = container.streams.video[0] + # 获取分片时长 + if video_stream.duration: + self.current_segment_duration = float(video_stream.duration * video_stream.time_base) + else: + self.current_segment_duration = None + # 重置时间轴:使用新分片的第一帧PTS重新设置时间基准 current_time = time.time()