Skip to content

Commit

Permalink
prefer video stream duration, fallback to container duration if unava…
Browse files Browse the repository at this point in the history
…ilable (#64)
  • Loading branch information
amietn authored Jun 14, 2019
1 parent 1c5ae90 commit 7ab5119
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vcsi/vcsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ def compute_format(self):
"""
format_dict = self.ffprobe_dict["format"]

self.duration_seconds = float(format_dict["duration"])
try:
# try getting video stream duration first
self.duration_seconds = float(self.video_stream["duration"])
except (KeyError, AttributeError):
# otherwise fallback to format duration
self.duration_seconds = float(format_dict["duration"])

self.duration = MediaInfo.pretty_duration(self.duration_seconds)

self.filename = os.path.basename(format_dict["filename"])
Expand Down

0 comments on commit 7ab5119

Please sign in to comment.