Skip to content

Commit

Permalink
Merge pull request #155 from bbc/philipn-presentation-timeline
Browse files Browse the repository at this point in the history
Add Grain.presentation_origin_timestamp/range
  • Loading branch information
philipnbbc authored Apr 8, 2024
2 parents 060e1f1 + f8cf931 commit 94662fd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
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

0 comments on commit 94662fd

Please sign in to comment.