﻿# PyAV video datasets: presentation timestamps are safer than frame-number clocks

Use frame presentation timestamps and explicit time bases when sampling variable-frame-rate video for multimodal datasets.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/data-guide-pyav-video-pts-timebase/
Language: en

## A decoded frame has a presentation time

PyAV exposes a frame's presentation timestamp, time base and presentation time in seconds. These describe when a frame should be shown. A sequential frame counter instead describes where a decoder returned it in a particular iteration.

For a dataset aligned with narration or events, retain temporal evidence from the decoded frame. Dividing a counter by a nominal rate can drift from the actual timeline when frame durations vary or frames are missing.

## Time bases belong to their context

The time documentation distinguishes stream, codec and container contexts. Integer timestamps are expressed in the relevant time base. Comparing integer values from different contexts without converting units can create a large alignment error even when each value looks plausible.

Store the timestamp and its unit together. The current documentation also explains how unset rational values are represented, so check the installed version's contract before testing for missing metadata. A default chosen by a pipeline should be recorded as an assumption, not disguised as an observed source timestamp.

## Average rate is a summary

PyAV's VideoStream documentation describes average_rate as a rate estimated from initial frames. Its base_rate is another quantity with a different definition. Neither field makes every later frame interval identical.

Choose a sampling rule explicitly: nearest presentation time, first frame after a boundary or another declared policy. These rules can select different images near an event transition. Keep selected frame timestamps so a later reviewer can reconstruct the choice.

## Decode and presentation timestamps answer different questions

The frame API distinguishes decoding and presentation timestamp fields. Decoding order and the time intended for display are not interchangeable concepts. An input pipeline should not select an arbitrary available timestamp without naming the fallback behavior.

Handle missing or corrupt frame evidence visibly. Skipping a frame can be reasonable for one corpus, while another task needs an error marker to preserve event alignment. Record the decision instead of silently compressing the remaining frames into a fictional constant-rate sequence.

## Sampling provenance should survive image export

Exported images can lose their connection to the video's original timing. Associate each image with parent recording identity, selected presentation timestamp, time-base interpretation and sampling revision. If the video was clipped or retimed, retain that transformation as well.

A proposed validation compares selected images with known event boundaries across variable-rate and ordinary clips. No timing accuracy or performance measurement is claimed here. The aim is an inspectable temporal contract for video examples, rather than an assumption that consecutive filenames form a trustworthy clock.

## Primary references

[PyAV time documentation](https://pyav.basswood.io/docs/stable/api/time.html).

[PyAV frame API](https://pyav.basswood.io/docs/stable/api/frame.html).

[PyAV video API](https://pyav.basswood.io/docs/stable/api/video.html).

Related explanations: [Visual and text evidence](/journal/clip-image-text-contrastive-space/); [Timed transcript evidence](/journal/meeting-search-transcript-speaker-evidence/).
