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

Add Grain.presentation_origin_timestamp/range #155

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion mediagrains/grains/CodedVideoGrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Sized,
Iterable)
from uuid import UUID
from mediatimestamp.immutable import Timestamp, SupportsMediaTimestamp, mediatimestamp
from mediatimestamp.immutable import Timestamp, TimeRange, SupportsMediaTimestamp, mediatimestamp
from ..typing import (
CodedVideoGrainMetadataDict,
FractionDict,
Expand Down Expand Up @@ -412,3 +412,33 @@ def media_rate(self) -> Optional[Fraction]:
return self.rate
else:
return None

@property
def presentation_origin_timestamp(self) -> Timestamp:
if self.rate is not None and self.temporal_offset is not None:
return self.origin_timestamp + Timestamp.from_count(self.temporal_offset, self.rate)
else:
return self.origin_timestamp

def final_presentation_origin_timestamp(self) -> Timestamp:
if self.rate is not None and self.temporal_offset is not None:
return self.final_origin_timestamp() + Timestamp.from_count(self.temporal_offset, self.rate)
else:
return self.final_origin_timestamp()

def presentation_origin_timerange(self) -> TimeRange:
origin_tr = self.origin_timerange()
if self.rate is not None and self.temporal_offset is not None:
if origin_tr.start is not None:
start = origin_tr.start + Timestamp.from_count(self.temporal_offset, self.rate)
else:
start = None

if origin_tr.end is not None:
end = origin_tr.end + Timestamp.from_count(self.temporal_offset, self.rate)
else:
end = None

return TimeRange(start, end, origin_tr.inclusivity)
else:
return origin_tr
20 changes: 20 additions & 0 deletions mediagrains/grains/Grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ class Grain(Sequence):
origin_timerange()
The origin time range covered by the samples in the grain.

presentation_origin_timestamp
The presentation timeline origin timestamp for the grain.

final_presentation_origin_timestamp()
The presentation origin timestamp of the final sample in the grain. For most grain types this is the same as
presentation_origin_timestamp, but not for audio grains.

presentation_origin_timerange()
The presentation timeline origin time range covered by the samples in the grain.

normalise_time(value)
Returns a normalised Timestamp, TimeOffset or TimeRange using the media rate.

Expand Down Expand Up @@ -449,6 +459,16 @@ def final_origin_timestamp(self) -> Timestamp:
def origin_timerange(self) -> TimeRange:
return TimeRange(self.origin_timestamp, self.final_origin_timestamp(), TimeRange.INCLUSIVE)

@property
def presentation_origin_timestamp(self) -> Timestamp:
return self.origin_timestamp

def final_presentation_origin_timestamp(self) -> Timestamp:
return self.final_origin_timestamp()

def presentation_origin_timerange(self) -> TimeRange:
return self.origin_timerange()

@overload
def normalise_time(self, value: TimeOffset) -> TimeOffset: ...

Expand Down