add pixel audio timeline
This commit is contained in:
parent
d831314554
commit
651cf95297
2 changed files with 44 additions and 30 deletions
|
@ -24,7 +24,7 @@ if __name__ == '__main__':
|
|||
parser.add_option('-y', '--height', dest='height', help='timeline height, defaults to 64px', default=64, type="int")
|
||||
parser.add_option('-o', '--prefix', dest='prefix', help='prefix for timeline tiles')
|
||||
parser.add_option('-i', '--input', dest='input', help='video input')
|
||||
parser.add_option('-m', '--mode', dest='mode', default='average', help='timeline mode: average(default), center')
|
||||
parser.add_option('-m', '--mode', dest='mode', default='average', help='timeline mode: average(default), center for video and waveform(default), pixel for audio')
|
||||
parser.add_option('-a', '--audio', action="store_true", dest="audio", default=False)
|
||||
(opts, args) = parser.parse_args()
|
||||
|
||||
|
@ -37,13 +37,15 @@ if __name__ == '__main__':
|
|||
opts.input = os.path.abspath(opts.input)
|
||||
|
||||
info = ox.avinfo(opts.input)
|
||||
if not info['video'] or opts.audio:
|
||||
audio.Timeline(opts.input, opts.prefix, opts.width, opts.height)
|
||||
if not info['video'] or opts.audio or opts.mode in ('waveform', 'pixel'):
|
||||
if opts.mode == 'average':
|
||||
opts.mode = 'waveform'
|
||||
audio.Timeline(opts.input, opts.prefix, opts.width, opts.height, opts.mode)
|
||||
else:
|
||||
video.Timeline(opts.input, opts.prefix, opts.width, opts.height, opts.mode)
|
||||
|
||||
#oxtimeline.createTimelineMultiline(opts.prefix)
|
||||
oxtimeline.makeTiles(opts.prefix, 16, 3600)
|
||||
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=16)
|
||||
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=64)
|
||||
|
||||
if opts.mode not in ('center', 'pixel'):
|
||||
#oxtimeline.createTimelineMultiline(opts.prefix)
|
||||
oxtimeline.makeTiles(opts.prefix, 16, 3600)
|
||||
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=16)
|
||||
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=64)
|
||||
|
|
|
@ -90,8 +90,9 @@ class Audio(gst.Pipeline):
|
|||
self.done()
|
||||
|
||||
class Timeline(Audio):
|
||||
def __init__(self, uri, prefix, width, height):
|
||||
def __init__(self, uri, prefix, width, height, mode='waveform'):
|
||||
Audio.__init__(self, uri)
|
||||
self.mode = mode
|
||||
|
||||
bus = self.get_bus()
|
||||
bus.add_signal_watch()
|
||||
|
@ -101,6 +102,8 @@ class Timeline(Audio):
|
|||
|
||||
self.tile_width = width
|
||||
self.tile_height = height
|
||||
if self.mode == 'pixel':
|
||||
self.tile_height = self.channels
|
||||
self.prefix = prefix
|
||||
self.timeline_fps = 25
|
||||
self.input_tile_width = int(math.ceil((float(self.framerate)/self.timeline_fps) * width))
|
||||
|
@ -113,30 +116,39 @@ class Timeline(Audio):
|
|||
self.set_state(gst.STATE_PLAYING)
|
||||
self.mainloop.run()
|
||||
|
||||
normalize = 1/max([max(*v) for v in self.volume])
|
||||
for volume in self.volume:
|
||||
tile = int(math.floor(float(self.position) / self.input_tile_width))
|
||||
tilePos = int(self.position - (tile * self.input_tile_width))
|
||||
if self.mode == 'pixel':
|
||||
for volume in self.volume:
|
||||
tile = int(math.floor(float(self.position) / self.input_tile_width))
|
||||
tilePos = int(self.position - (tile * self.input_tile_width))
|
||||
for c in range(0, self.channels):
|
||||
color = tuple(3 * [int(volume[c]*255)])
|
||||
self.tiles[tile].putpixel((tilePos, c), color)
|
||||
self.position += 1
|
||||
else:
|
||||
normalize = 1/max([max(*v) for v in self.volume])
|
||||
for volume in self.volume:
|
||||
tile = int(math.floor(float(self.position) / self.input_tile_width))
|
||||
tilePos = int(self.position - (tile * self.input_tile_width))
|
||||
|
||||
def plot(p, start):
|
||||
height = normalize * p * self.tile_height
|
||||
crop = int((self.tile_height-height) / 2)
|
||||
color = (p, p, p)
|
||||
color = (255,255,255)
|
||||
def plot(p, start):
|
||||
height = normalize * p * self.tile_height
|
||||
crop = int((self.tile_height-height) / 2)
|
||||
color = (p, p, p)
|
||||
color = (255,255,255)
|
||||
|
||||
if start:
|
||||
end = self.tile_height - crop
|
||||
else:
|
||||
start = crop
|
||||
end = int(self.tile_height/2)
|
||||
for i in range(start, end):
|
||||
self.tiles[tile].putpixel((tilePos, i), color)
|
||||
#left
|
||||
plot(volume[0], 0)
|
||||
#right
|
||||
plot(volume[1], int(self.tile_height/2))
|
||||
if start:
|
||||
end = self.tile_height - crop
|
||||
else:
|
||||
start = crop
|
||||
end = int(self.tile_height/2)
|
||||
for i in range(start, end):
|
||||
self.tiles[tile].putpixel((tilePos, i), color)
|
||||
#left
|
||||
plot(volume[0], 0)
|
||||
#right
|
||||
plot(volume[1], int(self.tile_height/2))
|
||||
|
||||
self.position += 1
|
||||
self.position += 1
|
||||
|
||||
for i in range(ntiles):
|
||||
tile = self.tiles[i]
|
||||
|
|
Loading…
Reference in a new issue