[pitivi] previewers: Scale waveform
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] previewers: Scale waveform
- Date: Thu, 29 Aug 2019 05:49:06 +0000 (UTC)
commit f5097436fc9d80e2c453d7c3fb70843dbbe6153d
Author: Alexander Lopatin <alopatindev gmail com>
Date: Sat Jan 19 17:29:04 2019 +0300
previewers: Scale waveform
The waveform was almost invisible for videos with low sound volume
Fixes #2270
pitivi/timeline/previewers.py | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/pitivi/timeline/previewers.py b/pitivi/timeline/previewers.py
index 56c21425..ed57e0cb 100644
--- a/pitivi/timeline/previewers.py
+++ b/pitivi/timeline/previewers.py
@@ -185,7 +185,7 @@ class WaveformPreviewer(PreviewerBin):
self.uri = None
self.wavefile = None
self.passthrough = False
- self.samples = []
+ self.samples = None
self.n_samples = 0
self.duration = 0
self.prev_pos = 0
@@ -261,10 +261,11 @@ class WaveformPreviewer(PreviewerBin):
else:
samples = numpy.array(self.peaks[0])
- self.samples = list(samples)
with open(self.wavefile, 'wb') as wavefile:
numpy.save(wavefile, samples)
+ self.samples = samples
+
if proxy and not proxy.get_error():
proxy_wavefile = get_wavefile_location_for_uri(proxy.get_id())
self.debug("symlinking %s and %s", self.wavefile, proxy_wavefile)
@@ -1112,12 +1113,27 @@ class AudioPreviewer(Gtk.Layout, Previewer, Zoomable, Loggable):
if os.path.exists(filename):
with open(filename, "rb") as samples:
- self.samples = list(numpy.load(samples))
+ self.samples = self._scale_samples(numpy.load(samples))
self.queue_draw()
else:
self.wavefile = filename
self._launchPipeline()
+ @staticmethod
+ def _scale_samples(samples):
+ max_value = max(samples)
+ has_sound = max_value > 0.0001
+ if has_sound:
+ # TODO: The 65 value comes from the height of the widget.
+ # It should not be hardcoded though. We can fix this
+ # when we implement a waveform samples cache, because it's
+ # wasteful if multiple clips backed by the same asset
+ # keep their own samples copy.
+ factor = 65 / max_value
+ samples = samples * factor
+
+ return list(samples)
+
def _launchPipeline(self):
self.debug(
'Now generating waveforms for: %s', path_from_uri(self._uri))
@@ -1145,7 +1161,7 @@ class AudioPreviewer(Gtk.Layout, Previewer, Zoomable, Loggable):
def _prepareSamples(self):
proxy = self.ges_elem.get_parent().get_asset().get_proxy_target()
self._wavebin.finalize(proxy=proxy)
- self.samples = self._wavebin.samples
+ self.samples = self._scale_samples(self._wavebin.samples)
def _busMessageCb(self, bus, message):
if message.type == Gst.MessageType.EOS:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]