Skip to content

Commit 32d233c

Browse files
committed
Add video frame __format__
1 parent 19e8c8c commit 32d233c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

linuxpy/video/device.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,17 @@ def __repr__(self) -> str:
16541654
f"format={self.pixel_format.name}, frame_nb={self.frame_nb}, timestamp={self.timestamp}>"
16551655
)
16561656

1657+
def __format__(self, spec):
1658+
if spec in {"", "s"}:
1659+
return str(self)
1660+
elif spec == "r":
1661+
return repr(self)
1662+
elif spec == "f":
1663+
return f"{self.width}x{self.height} {self.pixel_format.name}"
1664+
elif spec == "l":
1665+
return f"#{self.frame_nb} {self.timestamp} {self:f}"
1666+
return str(getattr(self, spec))
1667+
16571668
@property
16581669
def width(self):
16591670
return self.format.width

0 commit comments

Comments
 (0)