def _calc_bmpThumbnail(self): song = Song(url = self.url, _useDb = False) song.gain = self.gain # useful for the adopted BMP song.openFile() # this is another process, so safe # We have song.gain which mostly lowers the volume. So increase here for nicer display. import ffmpeg duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume = 1.5) return {"duration": duration, "bmpThumbnail": bmpData}
def _calc_bmpThumbnail(self): song = Song(url = self.url, _useDb = False) try: song.openFile() except IOError as exc: return {"error": exc} song.gain,_ = self.get("gain", accuracy=0, fastOnly=True) # useful for the adopted BMP import ffmpeg try: # We have song.gain which mostly lowers the volume. So increase here for nicer display. duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume = 1.5) except Exception as exc: return {"error": exc} return {"duration": duration, "bmpThumbnail": bmpData}
def _calc_bmpThumbnail(self): song = Song(url = self.url, _useDb = False) try: song.openFile() except IOError as exc: return {"error": exc} # Earlier, we copied the song.gain. Because of some internal ffmpeg redesign, # ffmpeg currently ignores the gain when it calculates the bmpThumnail. # But I think the thumbnails actually look better without the gain adoption, # so I'll just leave it that way now. import ffmpeg try: # We have song.gain which mostly lowers the volume. So increase here for nicer display. duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume = 1.5) except Exception as exc: return {"error": exc} return {"duration": duration, "bmpThumbnail": bmpData}
def doBmpCalc(queue): try: def calcBmpCallback(song, completion, duration, bmpData): if subview.window() is None: return False # window was closed with self.lock: if song != self.curSong: return False queue.put((duration, bmpData)) return True song.openFile() import ffmpeg bmpThumbRet = ffmpeg.calcBitmapThumbnail(song, 600, 81, procCallback = calcBmpCallback) if bmpThumbRet: queue.put(bmpThumbRet) except: print "doBmpCalc raised exception" sys.excepthook(*sys.exc_info()) queue.put(None)
def _calc_bmpThumbnail(self): song = Song(url=self.url, _useDb=False) try: song.openFile() except IOError as exc: return {"error": exc} song.gain, _ = self.get("gain", accuracy=0, fastOnly=True) # useful for the adopted BMP import ffmpeg try: # We have song.gain which mostly lowers the volume. So increase here for nicer display. duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume=1.5) except Exception as exc: return {"error": exc} return {"duration": duration, "bmpThumbnail": bmpData}
def _calc_bmpThumbnail(self): song = Song(url=self.url, _useDb=False) try: song.openFile() except IOError as exc: return {"error": exc} # Earlier, we copied the song.gain. Because of some internal ffmpeg redesign, # ffmpeg currently ignores the gain when it calculates the bmpThumnail. # But I think the thumbnails actually look better without the gain adoption, # so I'll just leave it that way now. import ffmpeg try: # We have song.gain which mostly lowers the volume. So increase here for nicer display. duration, bmpData = ffmpeg.calcBitmapThumbnail(song, 600, 81, volume=1.5) except Exception as exc: return {"error": exc} return {"duration": duration, "bmpThumbnail": bmpData}
def doBmpCalc(queue): try: def calcBmpCallback(song, completion, duration, bmpData): if subview.window() is None: return False # window was closed with self.lock: if song != self.curSong: return False queue.put((duration, bmpData)) return True song.openFile() import ffmpeg bmpThumbRet = ffmpeg.calcBitmapThumbnail( song, 600, 81, procCallback=calcBmpCallback) if bmpThumbRet: queue.put(bmpThumbRet) except: print "doBmpCalc raised exception" sys.excepthook(*sys.exc_info()) queue.put(None)
self.f = open(fn) def readPacket(self, bufSize): s = self.f.read(bufSize) return s def seekRaw(self, offset, whence): r = self.f.seek(offset, whence) return self.f.tell() for f in files: ffmpeg.getMetadata(Song(f)) progr() print "after getMetadata" step() for f in files: ffmpeg.calcAcoustIdFingerprint(Song(f)) progr() print "after calcAcoustIdFingerprint" step() for f in files: ffmpeg.calcBitmapThumbnail(Song(f)) progr() print "after calcBitmapThumbnail" step()
"/Users/az/Music/Electronic/Von Paul Kalkbrenner - Aaron.mp3", "/Users/az/Music/Electronic/One Day_Reckoning Song (Wankelmut Remix) - Asaf Avidan & the Mojos.mp3", ] i = 5 if len(sys.argv) >= 2: i = int(sys.argv[1]) filename = files[i] bmpWidth = 500 bmpHeight = 151 bgColor = (50,50,50) timelineColor = (100,100,100) timelineInterval = 5 # every 5 sec assert os.path.isfile(filename) import ffmpeg duration, bmp = ffmpeg.calcBitmapThumbnail(Song(filename), bmpWidth, bmpHeight, bgColor, timelineColor, timelineInterval) def formatTime(t): if t is None: return "?" mins = long(t // 60) t -= mins * 60 hours = mins // 60 mins -= hours * 60 if hours: return "%02i:%02i:%02.0f" % (hours,mins,t) return "%02i:%02.0f" % (mins,t) print filename, formatTime(duration) open("thumbnail.bmp", "w").write(bmp) os.system("open thumbnail.bmp")
def readPacket(self, bufSize): s = self.f.read(bufSize) return s def seekRaw(self, offset, whence): r = self.f.seek(offset, whence) return self.f.tell() for f in files: ffmpeg.getMetadata(Song(f)) progr() print "after getMetadata" step() for f in files: ffmpeg.calcAcoustIdFingerprint(Song(f)) progr() print "after calcAcoustIdFingerprint" step() for f in files: ffmpeg.calcBitmapThumbnail(Song(f)) progr() print "after calcBitmapThumbnail" step()
"/Users/az/Music/Electronic/One Day_Reckoning Song (Wankelmut Remix) - Asaf Avidan & the Mojos.mp3", ] i = 5 if len(sys.argv) >= 2: i = int(sys.argv[1]) filename = files[i] bmpWidth = 500 bmpHeight = 151 bgColor = (50, 50, 50) timelineColor = (100, 100, 100) timelineInterval = 5 # every 5 sec assert os.path.isfile(filename) import ffmpeg duration, bmp = ffmpeg.calcBitmapThumbnail(Song(filename), bmpWidth, bmpHeight, bgColor, timelineColor, timelineInterval) def formatTime(t): if t is None: return "?" mins = long(t // 60) t -= mins * 60 hours = mins // 60 mins -= hours * 60 if hours: return "%02i:%02i:%02.0f" % (hours, mins, t) return "%02i:%02.0f" % (mins, t) print filename, formatTime(duration)