32 lines
1018 B
Python
32 lines
1018 B
Python
# 使用PyAV(FFmpeg的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() |