From 576b6d5ce43e12a16cc4d70431cfaa1e5f2caa4f Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Thu, 5 Mar 2026 10:50:40 +0800 Subject: [PATCH] =?UTF-8?q?hls=E6=AF=8F=E4=B8=80=E5=B8=A7=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=88=86=E7=89=87=E8=B7=AF=E5=BE=84=EF=BC=8C=E5=88=86?= =?UTF-8?q?=E7=89=87=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hls_service_ws_kadian.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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()