hls每一帧新增分片路径,分片时长

This commit is contained in:
zqc
2026-03-05 10:50:40 +08:00
parent fffef90e98
commit 576b6d5ce4

View File

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