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
26 changes: 22 additions & 4 deletions 26 ffprobe/ffprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import platform
import re
import subprocess
from datetime import datetime

from ffprobe.exceptions import FFProbeError
from .exceptions import FFProbeError


class FFProbe:
Expand Down Expand Up @@ -211,7 +212,13 @@ def frames(self):
raise FFProbeError('None integer frame count')
else:
# When N/A is returned, set frame_count to 0 too
frame_count = 0
if self.is_video():
# Calculate Video framerate from Time and FPS
fps = self.frame_rate()
length = self.duration_seconds()
frame_count = round(fps * length)
else:
frame_count = 0
else:
frame_count = 0

Expand All @@ -225,8 +232,13 @@ def duration_seconds(self):
if self.is_video() or self.is_audio():
try:
duration = float(self.__dict__.get('duration', ''))
except ValueError:
raise FFProbeError('None numeric duration')

except:
# Get duration from tag
duration_tag = self.__dict__.get('TAG:DURATION')
pt = datetime.strptime(duration_tag[:-4],'%H:%M:%S.%f')
duration = pt.second + pt.minute*60 + pt.hour*3600 + pt.microsecond*0.000001

else:
duration = 0.0

Expand Down Expand Up @@ -264,3 +276,9 @@ def bit_rate(self):
return int(self.__dict__.get('bit_rate', ''))
except ValueError:
raise FFProbeError('None integer bit_rate')

def frame_rate(self):
"""
Returns framerate
"""
return float(self.__dict__.get('framerate',''))
Morty Proxy This is a proxified and sanitized view of the page, visit original site.