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)
if opts.mode not in ('center', 'pixel'):
#oxtimeline.createTimelineMultiline(opts.prefix) #oxtimeline.createTimelineMultiline(opts.prefix)
oxtimeline.makeTiles(opts.prefix, 16, 3600) oxtimeline.makeTiles(opts.prefix, 16, 3600)
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=16) oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=16)
oxtimeline.makeTimelineOverview(opts.prefix, 1920, height=64) 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,6 +116,15 @@ class Timeline(Audio):
self.set_state(gst.STATE_PLAYING) self.set_state(gst.STATE_PLAYING)
self.mainloop.run() self.mainloop.run()
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]) normalize = 1/max([max(*v) for v in self.volume])
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))