better aevalsrc inputs for spectrum previews

This commit is contained in:
tassaron 2017-08-14 14:28:30 -04:00
parent bed07479f1
commit ea1a422cc5
4 changed files with 55 additions and 21 deletions

View File

@ -19,7 +19,7 @@ log = logging.getLogger('AVP.Components.Spectrum')
class Component(Component):
name = 'Spectrum'
version = '1.0.0'
version = '1.0.1'
def widget(self, *args):
self.previewFrame = None
@ -65,8 +65,17 @@ class Component(Component):
self.changedOptions = True
def update(self):
self.page.stackedWidget.setCurrentIndex(
self.page.comboBox_filterType.currentIndex())
filterType = self.page.comboBox_filterType.currentIndex()
self.page.stackedWidget.setCurrentIndex(filterType)
if filterType == 3:
self.page.spinBox_hue.setEnabled(False)
else:
self.page.spinBox_hue.setEnabled(True)
if filterType == 2 or filterType == 4:
self.page.checkBox_mono.setEnabled(False)
else:
self.page.checkBox_mono.setEnabled(True)
super().update()
def previewRender(self):
@ -81,6 +90,8 @@ class Component(Component):
frame = self.getPreviewFrame()
self.changedOptions = False
if not frame:
log.warning(
'Spectrum #%s failed to create a preview frame' % self.compPos)
self.previewFrame = None
return BlankFrame(self.width, self.height)
else:
@ -244,13 +255,21 @@ class Component(Component):
)
)
if self.filterType < 2:
exampleSnd = exampleSound('freq')
elif self.filterType == 2 or self.filterType == 4:
exampleSnd = exampleSound('stereo')
elif self.filterType == 3:
exampleSnd = exampleSound('white')
return [
'-filter_complex',
'%s%s%s%s [v1]; '
'[v1] %s%s%s%s%s [v]' % (
exampleSound() if preview and genericPreview else '[0:a] ',
exampleSnd if preview and genericPreview else '[0:a] ',
'compand=gain=4,' if self.compress else '',
'aformat=channel_layouts=mono,' if self.mono else '',
'aformat=channel_layouts=mono,'
if self.mono and self.filterType not in (2, 4) else '',
filter_,
'hflip, ' if self.mirror else '',
'trim=start=%s:end=%s, ' % (
@ -259,7 +278,8 @@ class Component(Component):
) if preview else '',
'scale=%sx%s' % scale(
self.scale, self.width, self.height, str),
', hue=h=%s:s=10' % str(self.hue) if self.hue > 0 else '',
', hue=h=%s:s=10' % str(self.hue)
if self.hue > 0 and self.filterType != 3 else '',
', convolution=-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2:-2 '
'-1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2'
if self.filterType == 3 else ''

View File

@ -140,13 +140,16 @@ class Component(Component):
opacity = "{0:.1f}".format(self.opacity / 100)
genericPreview = self.settings.value("pref_genericPreview")
if self.mode < 3:
filter_ = 'showwaves=r=%s:s=%sx%s:mode=%s:colors=%s@%s:scale=%s' % (
self.settings.value("outputFrameRate"),
self.settings.value("outputWidth"),
self.settings.value("outputHeight"),
self.page.comboBox_mode.currentText().lower()
if self.mode != 3 else 'p2p',
hexcolor, opacity, amplitude,
filter_ = (
'showwaves='
'r=%s:s=%sx%s:mode=%s:colors=%s@%s:scale=%s' % (
self.settings.value("outputFrameRate"),
self.settings.value("outputWidth"),
self.settings.value("outputHeight"),
self.page.comboBox_mode.currentText().lower()
if self.mode != 3 else 'p2p',
hexcolor, opacity, amplitude,
)
)
elif self.mode > 2:
filter_ = (
@ -160,18 +163,20 @@ class Component(Component):
)
)
baselineHeight = int(self.height * (4 / 1080))
return [
'-filter_complex',
'%s%s%s'
'%s%s%s [v1]; '
'[v1] scale=%s:%s%s [v]' % (
exampleSound() if preview and genericPreview else '[0:a] ',
exampleSound('wave', extra='')
if preview and genericPreview else '[0:a] ',
'compand=gain=4,' if self.compress else '',
'aformat=channel_layouts=mono,'
if self.mono and self.mode < 3 else '',
filter_,
', drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=4:color=%s@%s' % (
hexcolor, opacity
', drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=%s:color=%s@%s' % (
baselineHeight, hexcolor, opacity,
) if self.mode < 2 else '',
', hflip' if self.mirror else'',
w, h,

View File

@ -457,8 +457,17 @@ def readAudioFile(filename, videoWorker):
return (completeAudioArray, duration)
def exampleSound():
return (
'aevalsrc=tan(random(1)*PI*t)*sin(random(0)*2*PI*t),'
'apulsator=offset_l=0.5:offset_r=0.5,'
)
def exampleSound(
style='white', extra='apulsator=offset_l=0.35:offset_r=0.67'):
'''Help generate an example sound for use in creating a preview'''
if style == 'white':
src = '-2+random(0)'
elif style == 'freq':
src = 'sin(1000*t*PI*t)'
elif style == 'wave':
src = 'sin(random(0)*2*PI*t)*tan(random(0)*2*PI*t)'
elif style == 'stereo':
src = '0.1*sin(2*PI*(360-2.5/2)*t) : 0.1*sin(2*PI*(360+2.5/2)*t)'
return "aevalsrc='%s', %s%s" % (src, extra, ', ' if extra else '')

BIN
test.wav Normal file

Binary file not shown.