forked from albertz/music-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bmpthumb.py
55 lines (45 loc) · 1.63 KB
/
test_bmpthumb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Song:
def __init__(self, fn):
self.url = fn
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()
import sys, os
if len(sys.argv) == 2 and os.path.isfile(sys.argv[1]):
filename = sys.argv[1]
else:
files = [
"/Users/az/Music/Classic/Glenn Gould Plays Bach/Two- & Three-Part Inventions - Gould/19 Bach - Invention 13 in a (BWV 784).mp3",
"/Users/az/Music/Rock/Tool/Lateralus/09 Lateralus.flac",
"/Users/az/Music/Cults - Cults 7/Cults - Cults 7- - 03 The Curse.flac",
"/Users/az/Music/Special/zorba/(01) - Theme From Zorba The Greek.ogg",
"/Users/az/Music/Classic/Glenn Gould Plays Bach/French Suites, BWV812-7 - Gould/Bach, French Suite 5 in G, BWV816 - 5 Bourree.mp3",
"/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")