Files
SupervisorAI/hls_test.py
2026-02-04 14:25:43 +08:00

32 lines
1018 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用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()