diff options
| author | tassaron | 2017-06-04 13:00:36 -0400 |
|---|---|---|
| committer | tassaron | 2017-06-04 13:00:36 -0400 |
| commit | 39e66ffa2d07b87b57ed90b369ab26aedf0a69e8 (patch) | |
| tree | f11cf59368997a9b0dbd6cfd4cb9dd3e45f03583 /core.py | |
| parent | 443c65455a1cae8ccaea0f0af7cdda3919c709f8 (diff) | |
video component almost working, rm hardcoded backgrounds
Diffstat (limited to 'core.py')
| -rw-r--r-- | core.py | 61 |
1 files changed, 7 insertions, 54 deletions
@@ -13,11 +13,8 @@ from collections import OrderedDict class Core(): def __init__(self): - self.lastBackgroundImage = "" - self._image = None - self.FFMPEG_BIN = self.findFfmpeg() - self.tempDir = None + self.tempDir = os.path.join(tempfile.gettempdir(), 'audio-visualizer-python-data') atexit.register(self.deleteTempDir) def findFfmpeg(self): @@ -31,31 +28,6 @@ class Core(): except: return "avconv" - def parseBaseImage(self, backgroundImage, preview=False): - ''' determines if the base image is a single frame or list of frames ''' - if backgroundImage == "": - return [''] - else: - _, bgExt = os.path.splitext(backgroundImage) - if not bgExt == '.mp4': - return [backgroundImage] - else: - return self.getVideoFrames(backgroundImage, preview) - - def drawBaseImage(self, backgroundFile): - if backgroundFile == '': - im = Image.new("RGB", (int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))), "black") - else: - im = Image.open(backgroundFile) - - if self._image == None or not self.lastBackgroundImage == backgroundFile: - self.lastBackgroundImage = backgroundFile - # resize if necessary - if not im.size == (int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))): - im = im.resize((int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))), Image.ANTIALIAS) - - return im - def readAudioFile(self, filename, parent): command = [ self.FFMPEG_BIN, '-i', filename] @@ -121,30 +93,11 @@ class Core(): return completeAudioArray def deleteTempDir(self): - if self.tempDir and os.path.exists(self.tempDir): - rmtree(self.tempDir) - - def getVideoFrames(self, videoPath, firstOnly=False): - self.tempDir = os.path.join(tempfile.gettempdir(), 'audio-visualizer-python-data') - # recreate the temporary directory so it is empty - self.deleteTempDir() - os.mkdir(self.tempDir) - if firstOnly: - filename = 'preview%s.jpg' % os.path.basename(videoPath).split('.', 1)[0] - options = '-ss 10 -vframes 1' - else: - filename = '$frame%05d.jpg' - options = '' - sp.call( \ - '%s -i "%s" -y %s "%s"' % ( \ - self.FFMPEG_BIN, - videoPath, - options, - os.path.join(self.tempDir, filename) - ), - shell=True - ) - return sorted([os.path.join(self.tempDir, f) for f in os.listdir(self.tempDir)]) + try: + if os.path.exists(self.tempDir): + rmtree(self.tempDir) + except FileNotFoundError: + pass def cancel(self): self.canceled = True @@ -153,6 +106,6 @@ class Core(): self.canceled = False @staticmethod - def sortedStringDict(dictionary): + def stringOrderedDict(dictionary): sorted_ = OrderedDict(sorted(dictionary.items(), key=lambda t: t[0])) return repr(sorted_) |
