[pitivi/1.0] utils: Display framerate nicely in clip properties
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/1.0] utils: Display framerate nicely in clip properties
- Date: Sun, 18 Feb 2018 16:42:09 +0000 (UTC)
commit 97658bb5729bbb5ad7bb9eec9f37344a9ebfdea5
Author: yatinmaan <yatinmaan1 gmail com>
Date: Mon Jan 22 20:53:00 2018 +0530
utils: Display framerate nicely in clip properties
Show 24 fps instead of 24.000 fps
Fixes T3422
Differential Revision: https://phabricator.freedesktop.org/D1946
pitivi/utils/ui.py | 36 ++++++++++++++++++++++--------------
tests/test_utils.py | 29 +++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 14 deletions(-)
---
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index a6545da..3a6ab02 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -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×%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×%d <i>pixels</i> at %s <i>fps</i>")
+ return templ % (par * width, height, fps)
else:
templ = _("<b>Image:</b> %d×%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
diff --git a/tests/test_utils.py b/tests/test_utils.py
index dcbe15c..c6b9c2f 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -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):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]