parser.add_option('-f', '--fps', action="store", dest="fps", type='int', help="Resulting video FPS", default=10) parser.add_option('--font', action="store", dest="font", help="Font file") if __name__ == '__main__': sys.stderr = codecs.getwriter(sys.stderr.encoding or 'UTF-8')(sys.stderr, errors='replace') options, args = parser.parse_args() if options.source: options.size = options.source.size options.wmove = max(1.0, options.wmove) # загружаем данные wav = WaveFile(options.wav) harmony = SongReader(options.xml) labels = harmony.getStructureAs(label.Structure) beats = harmony.getStructureAs(beats.Structure) # сравним размер wav файла и рекомендуемый размер в XML #noinspection PyTypeChecker if abs(wav.length - harmony.declaredLength) > 1.0 / options.fps: print >>sys.stderr, "WAV file length doesn't match one specified in song file" sys.exit(10) # генерируем звуковую волну картинкой wW = int(options.wmove * options.size[0]) waveWriter = wav.writeWave(wW, options.size[1] / settings.WAVE_FORM_PART) # итоговое кол-во кадров в видео W, H, wH = options.size[0], options.size[1], options.size[1] / settings.WAVE_FORM_PART
# -*- coding: utf-8 -*- from optparse import OptionParser import settings from options import DOption from song.reader import SongReader from song.structure import scheme parser = OptionParser(usage="usage: %prog options", option_class=DOption) parser.add_option('-x', "--song", action="store", dest="xml", help="XML Song file") parser.add_option('-s', "--size", action="store", type='dimension', dest="size", help="Output size", default=(640, 480)) if __name__ == '__main__': options, args = parser.parse_args() harmony = SongReader(options.xml) structure = harmony.getStructureAs(scheme.Structure) W, H = options.size wH = H / settings.WAVE_FORM_PART imStructure = structure.drawStructure(W, (H-wH) * 2, W/2) structureFilename = options.xml.rsplit('.', 1)[0] + '.structure.png' f = open(structureFilename, 'wb') imStructure.save(f, 'PNG') del imStructure f.close()
parser = OptionParser(usage="usage: %prog options", option_class=DOption) parser.add_option('-b', "--background", action="store", type="opacity", dest="background", help="Additional background opacity", default=0) parser.add_option('-x', "--song", action="store", dest="xml", help="XML Song file") parser.add_option('-w', "--wav", action="store", dest="wav", help="Input WAV file") parser.add_option('-s', "--size", action="store", type='dimension', dest="size", help="Output size", default=(640, 480)) parser.add_option('-o', "--offset", action="store", type='float', dest="offset", help="Offset in seconds for video", default=0) parser.add_option('--font', action="store", dest="font", help="Font file") if __name__ == '__main__': sys.stderr = codecs.getwriter(sys.stderr.encoding or 'UTF-8')(sys.stderr, errors='replace') options, args = parser.parse_args() # загружаем данные wav = WaveFile(options.wav) harmony = SongReader(options.xml) labels = harmony.getStructureAs(label.Structure) beats = harmony.getStructureAs(beats.Structure) # сравним размер wav файла и рекомендуемый размер в XML #noinspection PyTypeChecker if abs(wav.length - harmony.declaredLength) > .04: print >>sys.stderr, "WAV file length doesn't match one specified in song file" sys.exit(10) # генерируем звуковую волну картинкой waveWriter = wav.writeWave(options.size[0], options.size[1] / settings.WAVE_FORM_PART) # итоговое кол-во кадров в видео W, H, wH = options.size[0], options.size[1], options.size[1] / settings.WAVE_FORM_PART