新增hls测试

This commit is contained in:
zqc
2026-02-04 14:25:43 +08:00
parent ec97c1fc20
commit a92571681f
2 changed files with 228 additions and 0 deletions

32
hls_test.py Normal file
View File

@@ -0,0 +1,32 @@
# 使用PyAVFFmpeg的Python绑定
import av
def extract_timestamps_from_ts(ts_file):
container = av.open(ts_file)
video_stream = container.streams.video[0]
frame_index = 0
for packet in container.demux(video_stream):
for frame in packet.decode():
# 获取精确时间信息
pts_ms = frame.pts * video_stream.time_base * 1000
dts_ms = frame.dts * video_stream.time_base * 1000 if frame.dts else None
print(f"{frame_index}:")
print(f" PTS: {pts_ms:.3f} ms")
print(f" DTS: {dts_ms:.3f} ms" if dts_ms else " DTS: None")
print(f" 类型: {frame.pict_type}") # I, P, B
print(f" 关键帧: {frame.key_frame}")
frame_index += 1
# 精度:可以达到微秒级
def main():
# extract_timestamps_from_ts("D:\\ProjectDoc\\Police\\data\\hls\\segment_00000001.ts")
extract_timestamps_from_ts("raw_segments\\segment_00001619.ts")
if __name__ == "__main__":
main()