Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
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
16 changes: 14 additions & 2 deletions 16 ffprobe/ffprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ def __repr__(self):

return template.format(**self.__dict__)

def __len__(self):
"""
Returns the truncated integer duration of the stream (in seconds), if available, defaulting to 0.

Raises a TypeError if called on a stream that is not labelled as video or audio.
"""
if self.is_video() or self.is_audio():
return int(float(self.__dict__.get('duration', '0.0')))

__subclass = f"[{self.__dict__.get('codec_type', None)}]".replace("[]","")
raise TypeError(f"object of type '{self.__class__.__name__}{__subclass}' has no len()")

def is_audio(self):
"""
Is this stream labelled as an audio stream?
Expand Down Expand Up @@ -219,8 +231,8 @@ def frames(self):

def duration_seconds(self):
"""
Returns the runtime duration of the video stream as a floating point number of seconds.
Returns 0.0 if not a video stream.
Returns the runtime duration of the audio/video stream as a floating point number of seconds.
Returns 0.0 if not an audio stream or video stream.
"""
if self.is_video() or self.is_audio():
try:
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.