Commit 3cf0545b authored by yatinmaan's avatar yatinmaan Committed by Alexandru Băluț

utils: Display framerate nicely in clip properties

Show 24 fps instead of 24.000 fps
Fixes T3422

Differential Revision: https://phabricator.freedesktop.org/D1946
parent bbdbd848
......@@ -158,6 +158,18 @@ TIMELINE_CSS = """
""" % ({'trimbar_normal': os.path.join(get_pixmap_dir(), "trimbar-normal.png"),
'trimbar_focused': os.path.join(get_pixmap_dir(), "trimbar-focused.png")})
def get_framerate(stream):
"""Formats the framerate of the stream for display."""
num = stream.get_framerate_num()
denom = stream.get_framerate_denom()
if num == 0 or denom == 0:
# Gst returns 0/1 if unable to determine it or in case of an image.
return "0"
return "{0:.5n}".format(num / denom)
# ---------------------- ARGB color helper-------------------------------------#
......@@ -293,7 +305,7 @@ def beautify_missing_asset(asset):
"""Formats the specified missing asset for display.
Args:
asset (GES.Asset): The asset to display.
asset (GES.UriClipAsset): The asset to display.
"""
uri = asset.get_id()
path = path_from_uri(uri)
......@@ -335,24 +347,20 @@ def beautify_stream(stream):
"<b>Audio:</b> %d channel at %d <i>Hz</i> (%d <i>bits</i>)",
"<b>Audio:</b> %d channels at %d <i>Hz</i> (%d <i>bits</i>)",
stream.get_channels())
templ = templ % (stream.get_channels(), stream.get_sample_rate(),
stream.get_depth())
return templ
return templ % (stream.get_channels(), stream.get_sample_rate(),
stream.get_depth())
elif type(stream) is DiscovererVideoInfo:
par = stream.get_par_num() / stream.get_par_denom()
width = stream.get_width()
height = stream.get_height()
if not stream.is_image():
templ = _("<b>Video:</b> %%d <i>pixels</i> at %.3f <i>fps</i>")
try:
templ = templ % (par * stream.get_width(), stream.get_height(),
float(stream.get_framerate_num()) / stream.get_framerate_denom())
except ZeroDivisionError:
templ = templ % (
par * stream.get_width(), stream.get_height(), 0)
fps = get_framerate(stream)
templ = _("<b>Video:</b> %%d <i>pixels</i> at %s <i>fps</i>")
return templ % (par * width, height, fps)
else:
templ = _("<b>Image:</b> %%d <i>pixels</i>")
templ = templ % (par * stream.get_width(), stream.get_height())
return templ
return templ % (par * width, height)
elif type(stream) is DiscovererSubtitleInfo:
# Ignore subtitle streams
......@@ -573,7 +581,7 @@ def fix_infobar(infobar):
infobar.forall(make_sure_revealer_does_nothing)
# ----------------------- encoding datas --------------------------------------- #
# ----------------------- encoding datas --------------------------------------#
# FIXME This should into a special file
frame_rates = model((str, object), (
# Translators: fps is for frames per second
......
......@@ -18,6 +18,7 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
from unittest import TestCase
from unittest.mock import Mock
from gi.repository import GLib
from gi.repository import Gst
......@@ -28,6 +29,7 @@ from pitivi.check import GstDependency
from pitivi.check import GtkDependency
from pitivi.utils.misc import fixate_caps_with_default_values
from pitivi.utils.ui import beautify_length
from pitivi.utils.ui import get_framerate
second = Gst.SECOND
minute = second * 60
......@@ -60,6 +62,33 @@ class TestBeautifyLength(TestCase):
self.assertEqual(beautify_length(Gst.CLOCK_TIME_NONE), "")
class TestGetFramerate(TestCase):
def __check(self, num, denom, expected):
stream = Mock()
stream.get_framerate_num = Mock(return_value=num)
stream.get_framerate_denom = Mock(return_value=denom)
self.assertEqual(get_framerate(stream), expected)
def test_invalid_fps(self):
self.__check(0, 1, "0")
self.__check(0, 0, "0")
self.__check(1, 0, "0")
def test_int_fps(self):
self.__check(1, 1, "1")
self.__check(24, 1, "24")
def test_float_fps(self):
self.__check(24000, 1001, "23.976")
self.__check(30000, 1001, "29.97")
self.__check(60000, 1001, "59.94")
def test_high_fps(self):
self.__check(2500, 1, "2,500")
self.__check(120, 1, "120")
class TestDependencyChecks(TestCase):
def testDependencies(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment