add pixel audio timeline

This commit is contained in:
j 2012-03-09 13:50:17 +01:00
parent d831314554
commit 651cf95297
2 changed files with 44 additions and 30 deletions

View file

@ -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('-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('-o', '--prefix', dest='prefix', help='prefix for timeline tiles')
parser.add_option('-i', '--input', dest='input', help='video input') 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) parser.add_option('-a', '--audio', action="store_true", dest="audio", default=False)
(opts, args) = parser.parse_args() (opts, args) = parser.parse_args()
@ -37,13 +37,15 @@ if __name__ == '__main__':
opts.input = os.path.abspath(opts.input) opts.input = os.path.abspath(opts.input)
info = ox.avinfo(opts.input) info = ox.avinfo(opts.input)
if not info['video'] or opts.audio: if not info['video'] or opts.audio or opts.mode in ('waveform', 'pixel'):
audio.Timeline(opts.input, opts.prefix, opts.width, opts.height) if opts.mode == 'average':
opts.mode = 'waveform'
audio.Timeline(opts.input, opts.prefix, opts.width, opts.height, opts.mode)
else: else:
video.Timeline(opts.input, opts.prefix, opts.width, opts.height, opts.mode) video.Timeline(opts.input, opts.prefix, opts.width, opts.height, opts.mode)
#oxtimeline.createTimelineMultiline(opts.prefix) if opts.mode not in ('center', 'pixel'):
oxtimeline.makeTiles(opts.prefix, 16, 3600) #oxtimeline.createTimelineMultiline(opts.prefix)
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=16) oxtimeline.makeTiles(opts.prefix, 16, 3600)
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=64) oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=16)
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=64)

View file

@ -90,8 +90,9 @@ class Audio(gst.Pipeline):
self.done() self.done()
class Timeline(Audio): class Timeline(Audio):
def __init__(self, uri, prefix, width, height): def __init__(self, uri, prefix, width, height, mode='waveform'):
Audio.__init__(self, uri) Audio.__init__(self, uri)
self.mode = mode
bus = self.get_bus() bus = self.get_bus()
bus.add_signal_watch() bus.add_signal_watch()
@ -101,6 +102,8 @@ class Timeline(Audio):
self.tile_width = width self.tile_width = width
self.tile_height = height self.tile_height = height
if self.mode == 'pixel':
self.tile_height = self.channels
self.prefix = prefix self.prefix = prefix
self.timeline_fps = 25 self.timeline_fps = 25
self.input_tile_width = int(math.ceil((float(self.framerate)/self.timeline_fps) * width)) 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.set_state(gst.STATE_PLAYING)
self.mainloop.run() self.mainloop.run()
normalize = 1/max([max(*v) for v in self.volume]) if self.mode == 'pixel':
for volume in self.volume: for volume in self.volume:
tile = int(math.floor(float(self.position) / self.input_tile_width)) tile = int(math.floor(float(self.position) / self.input_tile_width))
tilePos = int(self.position - (tile * 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): def plot(p, start):
height = normalize * p * self.tile_height height = normalize * p * self.tile_height
crop = int((self.tile_height-height) / 2) crop = int((self.tile_height-height) / 2)
color = (p, p, p) color = (p, p, p)
color = (255,255,255) color = (255,255,255)
if start: if start:
end = self.tile_height - crop end = self.tile_height - crop
else: else:
start = crop start = crop
end = int(self.tile_height/2) end = int(self.tile_height/2)
for i in range(start, end): for i in range(start, end):
self.tiles[tile].putpixel((tilePos, i), color) self.tiles[tile].putpixel((tilePos, i), color)
#left #left
plot(volume[0], 0) plot(volume[0], 0)
#right #right
plot(volume[1], int(self.tile_height/2)) plot(volume[1], int(self.tile_height/2))
self.position += 1 self.position += 1
for i in range(ntiles): for i in range(ntiles):
tile = self.tiles[i] tile = self.tiles[i]