ITADN

`mcap info` frequency estimation appears to be broken

#1504Openjoe-saronic 创建于 2025-12-16
bug
J
joe-saroniccommented
**Description** - Version: 0.0.51 - Platform: Ubuntu **Steps To Reproduce** Generate an MCAP with two frames. The example here uses python for brevity, but it doesn't matter. ```python from io import BytesIO from time import time_ns import numpy as np from foxglove_schemas_protobuf.CompressedImage_pb2 import CompressedImage from google.protobuf.timestamp_pb2 import Timestamp from mcap_protobuf.writer import Writer from PIL import Image count = 2 period_nanos = 100_000_000 width = 1080 height = 920 buf = BytesIO() Image.new("L", (width, height), color=0).save(buf, format="png", optimize=True) png_bytes = buf.getvalue() with open("test.mcap", "wb") as file: writer = Writer(file) nano_time = time_ns() for i in range(count): timestamp = Timestamp(seconds=nano_time // 1_000_000_000, nanos=nano_time % 1_000_000_000) for topic in ["video1"]: msg = CompressedImage(timestamp=timestamp, format="png", data=png_bytes) writer.write_message(topic=topic, message=msg, log_time=nano_time, publish_time=nano_time) nano_time += period_nanos writer.finish() ``` Running `info` on the file shows: ``` $ mcap info test.mcap library: python mcap-protobuf-support 0.5.1; mcap 1.1.1 profile: messages: 2 duration: 100ms start: 2025-12-15T19:51:30.520928453-06:00 (1765849890.520928453) end: 2025-12-15T19:51:30.620928453-06:00 (1765849890.620928453) compression: zstd: [1/1 chunks] [2.68 KiB/496.00 B (81.94%)] [4.84 KiB/sec] channels: (1) video1 2 msgs (20.00 Hz) : foxglove.CompressedImage [protobuf] channels: 1 attachments: 0 metadata: 0 ``` **Expected Behavior** Frequency of messages 100ms apart should be 10Hz = (2msgs - 1) / 100ms, but it looks like the calculation is 2msgs / 100ms. Similar behavior if we increase `count` in the code above to `10`: ``` $ mcap info test.mcap library: python mcap-protobuf-support 0.5.1; mcap 1.1.1 profile: messages: 10 duration: 900ms start: 2025-12-15T19:58:42.977567989-06:00 (1765850322.977567989) end: 2025-12-15T19:58:43.877567989-06:00 (1765850323.877567989) compression: zstd: [1/1 chunks] [11.25 KiB/629.00 B (94.54%)] [698.00 B/sec] channels: (1) video1 10 msgs (11.11 Hz) : foxglove.CompressedImage [protobuf] channels: 1 attachments: 0 metadata: 0 ``` Same actual frequency, but reported as 10/900ms instead of 9/900ms. FWIW, computation is correct when `count = 1`, but apparently because `dt = 0`, not `n - 1 = 0`: ``` $ mcap info test.mcap library: python mcap-protobuf-support 0.5.1; mcap 1.1.1 profile: messages: 1 duration: 0s start: 2025-12-15T19:57:43.194698262-06:00 (1765850263.194698262) end: 2025-12-15T19:57:43.194698262-06:00 (1765850263.194698262) compression: zstd: [1/1 chunks] [1.61 KiB/476.00 B (71.12%)] channels: (1) video1 1 msgs : foxglove.CompressedImage [protobuf] channels: 1 attachments: 0 metadata: 0 ``` I have added multiple channels using the loop `for topic in ["video1"]:` and all of them exhibit this behavior.
4 条评论