[pitivi] proxy: Fix traceback due to audio files
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] proxy: Fix traceback due to audio files
- Date: Fri, 17 Apr 2020 22:36:37 +0000 (UTC)
commit 2e975a5703df4302a2c84b07f951ae7bec49b720
Author: Ritwik Puri <ritwikpuri5678 gmail com>
Date: Sun Feb 16 16:37:07 2020 +0530
proxy: Fix traceback due to audio files
fixes #2412
pitivi/utils/proxy.py | 136 ++++++++++++++++++++++++---------------------
tests/test_medialibrary.py | 27 ++++++---
2 files changed, 92 insertions(+), 71 deletions(-)
---
diff --git a/pitivi/utils/proxy.py b/pitivi/utils/proxy.py
index 40fba6ba..91fc933c 100644
--- a/pitivi/utils/proxy.py
+++ b/pitivi/utils/proxy.py
@@ -29,10 +29,10 @@ from gi.repository import GstTranscoder
from pitivi.configure import get_gstpresets_dir
from pitivi.dialogs.prefs import PreferencesDialog
-from pitivi.utils.misc import ASSET_DURATION_META
-from pitivi.utils.misc import asset_get_duration
from pitivi.settings import GlobalSettings
from pitivi.utils.loggable import Loggable
+from pitivi.utils.misc import ASSET_DURATION_META
+from pitivi.utils.misc import asset_get_duration
# Make sure gst knowns about our own GstPresets
Gst.preset_set_app_dir(get_gstpresets_dir())
@@ -466,10 +466,9 @@ class ProxyManager(GObject.Object, Loggable):
proxy_duration = asset_get_duration(proxy)
if asset_duration != proxy_duration:
duration = min(asset_duration, proxy_duration)
-
self.info("Resetting %s duration from %s to %s as"
- " new proxy has a different duration",
- asset.props.id, Gst.TIME_ARGS(asset_duration), Gst.TIME_ARGS(duration))
+ " new proxy has a different duration",
+ asset.props.id, Gst.TIME_ARGS(asset_duration), Gst.TIME_ARGS(duration))
asset.set_uint64(ASSET_DURATION_META, duration)
proxy.set_uint64(ASSET_DURATION_META, duration)
target_uri = self.get_target_uri(asset)
@@ -482,15 +481,15 @@ class ProxyManager(GObject.Object, Loggable):
new_duration = duration - clip.props.in_point
if new_duration > 0:
self.warning("%s resetting duration to %s as"
- " new proxy has a shorter duration",
- clip, Gst.TIME_ARGS(new_duration))
+ " new proxy has a shorter duration",
+ clip, Gst.TIME_ARGS(new_duration))
clip.set_duration(new_duration)
else:
new_inpoint = new_duration - clip.props.in_point
self.error("%s resetting duration to %s"
- " and inpoint to %s as the proxy"
- " is shorter",
- clip, Gst.TIME_ARGS(new_duration), Gst.TIME_ARGS(new_inpoint))
+ " and inpoint to %s as the proxy"
+ " is shorter",
+ clip, Gst.TIME_ARGS(new_duration), Gst.TIME_ARGS(new_inpoint))
clip.set_inpoint(new_inpoint)
clip.set_duration(duration - new_inpoint)
clip.set_max_duration(duration)
@@ -638,10 +637,20 @@ class ProxyManager(GObject.Object, Loggable):
self._total_time_to_transcode += asset.get_duration() / Gst.SECOND
asset_uri = asset.get_id()
- if width and height:
- proxy_uri = self.get_proxy_uri(asset, scaled=True)
- else:
- proxy_uri = self.get_proxy_uri(asset)
+ scaled = width or height
+ proxy_uri = self.get_proxy_uri(asset, scaled=scaled)
+
+ if Gio.File.new_for_uri(proxy_uri).query_exists(None):
+ self.debug("Using proxy already generated: %s", proxy_uri)
+ GES.Asset.request_async(GES.UriClip,
+ proxy_uri, None,
+ self.__asset_loaded_cb, asset,
+ None)
+ return
+
+ self.debug("Creating a proxy for %s (strategy: %s, force: %s, scaled: %s)",
+ asset.get_id(), self.app.settings.proxying_strategy,
+ asset.force_proxying, scaled)
dispatcher = GstTranscoder.TranscoderGMainContextSignalDispatcher.new()
@@ -719,60 +728,63 @@ class ProxyManager(GObject.Object, Loggable):
to shadow a scaled proxy.
"""
force_proxying = asset.force_proxying
- # Handle Automatic scaling
- if self.app.settings.auto_scaling_enabled and not force_proxying \
- and not shadow and not self.asset_matches_target_res(asset):
- scaled = True
-
- # Create shadow proxies for unsupported assets
- if not self.is_asset_format_well_supported(asset) and not \
- self.app.settings.proxying_strategy == ProxyingStrategy.NOTHING \
- and not shadow and scaled:
- hq_uri = self.app.proxy_manager.get_proxy_uri(asset)
- if not Gio.File.new_for_uri(hq_uri).query_exists(None):
- self.add_job(asset, shadow=True)
-
- if scaled:
- if self.is_asset_queued(asset, optimisation=False):
- self.log("Asset already queued for scaling: %s", asset)
- return
-
+ video_streams = asset.get_info().get_video_streams()
+ if video_streams:
+ # Handle Automatic scaling
+ if self.app.settings.auto_scaling_enabled and not force_proxying \
+ and not shadow and not self.asset_matches_target_res(asset):
+ scaled = True
+
+ # Create shadow proxies for unsupported assets
+ if not self.is_asset_format_well_supported(asset) and not \
+ self.app.settings.proxying_strategy == ProxyingStrategy.NOTHING \
+ and not shadow and scaled:
+ hq_uri = self.app.proxy_manager.get_proxy_uri(asset)
+ if not Gio.File.new_for_uri(hq_uri).query_exists(None):
+ self.add_job(asset, shadow=True)
+
+ if scaled:
+ if self.is_asset_queued(asset, optimisation=False):
+ self.log("Asset already queued for scaling: %s", asset)
+ return
+ else:
+ if self.is_asset_queued(asset, scaling=False):
+ self.log("Asset already queued for optimization: %s", asset)
+ return
+
+ if not force_proxying:
+ if not self.__asset_needs_transcoding(asset, scaled):
+ self.debug("Not proxying asset (proxying disabled: %s)",
+ self.proxying_unsupported)
+ # Make sure to notify we do not need a proxy for that asset.
+ self.emit("proxy-ready", asset, None)
+ return
+
+ if scaled:
+ project = self.app.project_manager.current_project
+ w = project.scaled_proxy_width
+ h = project.scaled_proxy_height
+ if not project.has_scaled_proxy_size():
+ project.scaled_proxy_width = w
+ project.scaled_proxy_height = h
+ t_width, t_height = self._scale_asset_resolution(asset, w, h)
+ self.__create_transcoder(asset, width=t_width, height=t_height, shadow=shadow)
+ else:
+ self.__create_transcoder(asset, shadow=shadow)
else:
if self.is_asset_queued(asset, scaling=False):
self.log("Asset already queued for optimization: %s", asset)
return
- if not force_proxying:
- if not self.__asset_needs_transcoding(asset, scaled):
- self.debug("Not proxying asset (proxying disabled: %s)",
- self.proxying_unsupported)
- # Make sure to notify we do not need a proxy for that asset.
- self.emit("proxy-ready", asset, None)
- return
-
- proxy_uri = self.get_proxy_uri(asset, scaled)
- if Gio.File.new_for_uri(proxy_uri).query_exists(None):
- self.debug("Using proxy already generated: %s", proxy_uri)
- GES.Asset.request_async(GES.UriClip,
- proxy_uri, None,
- self.__asset_loaded_cb, asset,
- None)
- return
+ if not force_proxying:
+ if not self.__asset_needs_transcoding(asset, scaled):
+ self.debug("Not proxying asset (proxying disabled: %s)",
+ self.proxying_unsupported)
+ # Make sure to notify we do not need a proxy for that asset.
+ self.emit("proxy-ready", asset, None)
+ return
- self.debug("Creating a proxy for %s (strategy: %s, force: %s, scaled: %s)",
- asset.get_id(), self.app.settings.proxying_strategy,
- force_proxying, scaled)
- if scaled:
- project = self.app.project_manager.current_project
- w = project.scaled_proxy_width
- h = project.scaled_proxy_height
- if not project.has_scaled_proxy_size():
- project.scaled_proxy_width = w
- project.scaled_proxy_height = h
- t_width, t_height = self._scale_asset_resolution(asset, w, h)
- self.__create_transcoder(asset, width=t_width, height=t_height, shadow=shadow)
- else:
- self.__create_transcoder(asset, shadow=shadow)
+ self.__create_transcoder(asset)
def get_proxy_target(obj):
diff --git a/tests/test_medialibrary.py b/tests/test_medialibrary.py
index f72b42fe..ac628486 100644
--- a/tests/test_medialibrary.py
+++ b/tests/test_medialibrary.py
@@ -22,16 +22,15 @@ from unittest import mock
from gi.repository import Gdk
from gi.repository import GES
-from gi.repository import GObject
from gi.repository import Gst
from pitivi import medialibrary
from pitivi.project import ProjectManager
+from pitivi.utils.misc import ASSET_DURATION_META
+from pitivi.utils.misc import asset_get_duration
from pitivi.utils.proxy import ProxyingStrategy
from pitivi.utils.validate import create_event
from tests import common
-from pitivi.utils.misc import asset_get_duration
-from pitivi.utils.misc import ASSET_DURATION_META
class BaseTestMediaLibrary(common.TestCase):
@@ -96,10 +95,12 @@ class BaseTestMediaLibrary(common.TestCase):
common.get_sample_uri(sample_name), GES.UriClip)
def check_import(self, samples, proxying_strategy=ProxyingStrategy.ALL,
- check_no_transcoding=False):
+ check_no_transcoding=False, auto_scaling_enabled=False):
+ """Simulates the user importing an asset."""
self._custom_set_up(proxying_strategy=proxying_strategy,
num_transcoding_jobs=4,
- last_clip_view=medialibrary.SHOW_TREEVIEW)
+ last_clip_view=medialibrary.SHOW_TREEVIEW,
+ auto_scaling_enabled=auto_scaling_enabled)
self.check_no_transcoding = check_no_transcoding
self.medialibrary._progressbar.connect(
@@ -111,6 +112,7 @@ class BaseTestMediaLibrary(common.TestCase):
def check_add_proxy(self, asset, scaled=False, w=160, h=120,
check_progress=True):
+ """Simulates the user requesting an asset to be proxied."""
self.assertFalse(self.app.proxy_manager.is_proxy_asset(asset))
# Check the initial state of the asset, nothing should be going on.
@@ -162,11 +164,13 @@ class BaseTestMediaLibrary(common.TestCase):
medialibrary.AssetThumbnail.PROXIED)
proxy = self.medialibrary.storemodel[0][medialibrary.COL_ASSET]
- stream = proxy.get_info().get_video_streams()[0]
- resolution = [stream.get_width(), stream.get_height()]
self.assertEqual(proxy.props.proxy_target.props.id, asset.props.id)
- if scaled:
- self.assertEqual(resolution, [w, h])
+ # Check if the asset is video or not
+ if w:
+ stream = proxy.get_info().get_video_streams()[0]
+ resolution = [stream.get_width(), stream.get_height()]
+ if scaled:
+ self.assertEqual(resolution, [w, h])
return proxy
@@ -470,6 +474,11 @@ class TestMediaLibrary(BaseTestMediaLibrary):
self.check_import([sample], check_no_transcoding=True,
proxying_strategy=ProxyingStrategy.AUTOMATIC)
+ def test_import_supported_forced_scaled_audio(self):
+ sample = "mp3_sample.mp3"
+ with common.cloned_sample(sample):
+ self.check_import([sample], auto_scaling_enabled=True)
+
def test_missing_uri_displayed(self):
asset_uri = common.get_sample_uri("image-which-does-not-exist.png")
with common.created_project_file(asset_uri) as uri:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]