Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename timestamps (and related operations) to container_timestamps #7

Merged
merged 5 commits into from
Feb 3, 2025

Conversation

marc-tonsen
Copy link
Contributor

No description provided.

assert frame.time == ts and frame.index == 10

frames = video.by_timestamp[ts : ts + 10]
frames = video.by_video_time[ts : ts + 10]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by_video_time or by_container_timestamps?


Timestamps = NPTimestamps | list[int | float]
"Timestamps for frames in video time seconds"
PTSArray = npt.NDArray[np.float64]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect PTSArray to be integer PTS in stream time_base, ie. what frame.pts returns, it's confusing otherwise.

# TODO: why does mypy fail the above check?
if self.fps is None:
stream = self.container.add_stream("h264_nvenc") # type: ignore
# TODO: why does mypy fail the above check?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy fails because av hardcodes the h264 case to return a VideoStream but returns Stream otherwise

I would refactor this stream = self.container.add_stream(stream_name, rate=self.fps)


stream.codec_context.time_base = Fraction(1, 90000)
# stream.codec_context.time_base = Fraction(1, 90000)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be set if the frame rate is not constant to maximize precision of the variable frame rate frames.

Large slices are returned as a lazy view, which avoids immediately loading all
frames into RAM.
Note that numerical imprecisions of float numbers can lead to issues when
accessing individual frames by their container timestamp. I is recommended to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It*

stream: Literal["video"] = "video",
pre_loaded_container_timestamps: Optional[PTSArray | list[float]] | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the pre_loaded here?

to specify which stream to use, e.g. `("audio", 2)` to use the audio
stream at index `2`.
pre_loaded_container_timestamps: Array containing the PTS of the video
seconds. If not provided, PTS will be read from the video container.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTS to me and anyone that works with pyav imples integer values in stream time_base, not float video seconds, it's confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the description. Do you think this is better?

@marc-tonsen marc-tonsen merged commit 8defe6d into master Feb 3, 2025
3 of 6 checks passed
@marc-tonsen marc-tonsen deleted the no_abs_ts branch February 3, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants