# Timestamp for .pcd files

**URL:** <https://community.ouster.com/t/timestamp-for-pcd-files/336>\
**Category:** Software\
**Tags:** pcap\
**Created:** [May 21, 2025, 10:38am UTC](https://community.ouster.com/t/timestamp-for-pcd-files/336 "2025-05-21T10:38:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhilpk](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@adhilpk](https://community.ouster.com/u/adhilpk)\
**Post date:** [May 21, 2025, 10:38am UTC](https://community.ouster.com/t/timestamp-for-pcd-files/336/1 "2025-05-21T10:38:04Z")

</div>

> { “scan\_0000.pcd”: “1970-01-01 05:30:00”,  
> “scan\_0001.pcd”: “2025-05-15 18:31:03.836641”,  
> “scan\_0002.pcd”: “2025-05-15 18:31:03.936679”,  
> “scan\_0003.pcd”: “2025-05-15 18:31:04.036767”,  
> “scan\_0004.pcd”: “2025-05-15 18:31:04.136839”,  
> “scan\_0005.pcd”: “2025-05-15 18:31:04.236961”,  
> “scan\_0006.pcd”: “2025-05-15 18:31:04.336999”,  
> “scan\_0007.pcd”: “2025-05-15 18:31:04.436982”,  
> “scan\_0008.pcd”: “2025-05-15 18:31:04.536951”,  
> “scan\_0009.pcd”: “2025-05-15 18:31:04.636932”}

This is the timestamp I got when I converted the .pcap to .pcd along with timestamp for each pcd files. why is there a discrepancy in the timestamp for first .pcd file. The below code is I used for conversion, correct me if anything is wrong.

```auto
info = client.SensorInfo(open(meta_path).read())
source = pcap.Pcap(pcap_path, info)
scans = client.Scans(source)
xyzlut = client.XYZLut(info)

timestamps = {}

for i, scan in enumerate(scans):
    xyz = xyzlut(scan.field(client.ChanField.RANGE))
    points = xyz.reshape(-1, 3)
    
    timestamp_ns = scan.timestamp # timestamp: nanoseconds
    if isinstance(timestamp_ns, np.ndarray):
        timestamp_ns = timestamp_ns[0]

    timestamps[f"scan_{i:04d}.pcd"] = str(datetime.datetime.fromtimestamp(timestamp_ns / 1e9))

```

---

<div class="post-metadata">

**Author:** ![Samahu](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.ouster.com/samahu/32/39_2.png) [@Samahu](https://community.ouster.com/u/Samahu)\
**Post date:** [May 21, 2025, 4:33pm UTC](https://community.ouster.com/t/timestamp-for-pcd-files/336/2 "2025-05-21T16:33:01Z")

</div>

> [@adhilpk](#):
>
> ```auto
> timestamp_ns = scan.timestamp # timestamp: nanoseconds
> if isinstance(timestamp_ns, np.ndarray):
> timestamp_ns = timestamp_ns[0]
> 
> ```

You probably want to update this to the following:

```auto
    from ouster.sdk.client import first_valid_column_ts # alternatively you could use `first_valid_packet_ts`
    timestamp_ns = scan.timestamp # timestamp: nanoseconds
    if isinstance(timestamp_ns, np.ndarray):
        timestamp_ns = first_valid_column_ts(timestamp_ns)

```

The reason being is that some lidar may have missing packets from the frame and this is especially the case for very first frame of your capture. So by using the `first_valid_column_ts` you look for the first valid timestamp of the scan.

---

<div class="post-metadata">

**Author:** ![adhilpk](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@adhilpk](https://community.ouster.com/u/adhilpk)\
**Post date:** [May 22, 2025, 1:47pm UTC](https://community.ouster.com/t/timestamp-for-pcd-files/336/3 "2025-05-22T13:47:49Z")

</div>

```auto
for i, scan in enumerate(scans):
    xyz = client.XYZLut(info)(scan)
    points = xyz.reshape(-1, 3)
        
    timestamp_ns = client.first_valid_column_ts(scan) 

```

This is the right syntax, otherwise it will throw an error since it didn’t expect numpy array.

Another issue I faced is:

1. The timestamp obtained is not matching with one which I obtained in wireshark tool(with the same pcap file).
2. Also the output from `timestamp_ns = client.first_valid_column_ts(scan)` is in nanoseconds right? Am I converting it in to human readable format in the peoper way (`str(datetime.fromtimestamp(timestamp_ns / 1e9))`) ?

---

<div class="post-metadata">

**Author:** ![Samahu](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.ouster.com/samahu/32/39_2.png) [@Samahu](https://community.ouster.com/u/Samahu)\
**Post date:** [May 23, 2025, 3:28pm UTC](https://community.ouster.com/t/timestamp-for-pcd-files/336/4 "2025-05-23T15:28:37Z")

</div>

> [@adhilpk](#):
>
> client.first\_valid\_column\_ts(scan)

The `client.first_valid_column_ts` retrieves the measurements timestamp as reported by the sensor. You can’t compare this with your host machine and expect them to be relevant unless you have PTP enabled. Instead, check out `client.first_valid_packet_ts(scan)` which reports the timestamp of when the packet was received.

Hope this helps!
