7 #FONT_DESC = "Andale Mono, 72"
10 SAMPLE_LENGTH_SECONDS = 4
13 VIDEO_BUFFERS = SAMPLE_LENGTH_SECONDS * VIDEO_FRAMERATE
15 AUDIO_SAMPLERATE = 48000
16 AUDIO_SAMPLESPERBUFFER = 1024
17 AUDIO_BUFFERS = round(SAMPLE_LENGTH_SECONDS * 48000 / 1024)
19 LIVE_PIPELINE_TEMPLATE = """
20 videotestsrc num-buffers=%d pattern=black ! video/x-raw,framerate=%d/1 ! \
21 textoverlay valignment=center halignment=center font-desc="%s" text="{0}" ! \
23 audiotestsrc num-buffers=%d samplesperbuffer=%d freq={1:f} ! audio/x-raw,rate=%d ! \
25 """ % (VIDEO_BUFFERS, VIDEO_FRAMERATE, FONT_DESC, AUDIO_BUFFERS,
26 AUDIO_SAMPLESPERBUFFER, AUDIO_SAMPLERATE)
28 FILE_PIPELINE_TEMPLATE = """
29 webmmux name=mux ! filesink location="{2}/sample_{0}.webm"
30 videotestsrc num-buffers=%d pattern=black ! video/x-raw,framerate=%d/1 ! \
31 textoverlay valignment=center halignment=center font-desc="%s" text="{0}" ! \
33 audiotestsrc num-buffers=%d samplesperbuffer=%d freq={1:f} ! audio/x-raw,rate=%d ! \
34 queue ! audioconvert ! vorbisenc quality=0.5 ! queue ! mux.
35 """ % (VIDEO_BUFFERS, VIDEO_FRAMERATE, FONT_DESC, AUDIO_BUFFERS,
36 AUDIO_SAMPLESPERBUFFER, AUDIO_SAMPLERATE)
39 def create_test_videofont(pipeline_template, notes_range, destination_dir=None):
41 pipeline_string = pipeline_template.format("rest", 0, destination_dir)
42 player = vidi.Player.from_pipeline_string(pipeline_string)
45 for i, note_number in enumerate(notes_range):
46 note = vidi.SpnNote(note_number)
48 print("%2d %s" % (i, note))
50 pipeline_string = pipeline_template.format(note.name, note.frequency, destination_dir)
52 player = vidi.Player.from_pipeline_string(pipeline_string)
59 print("usage: %s [<videofont_destination_dir>]" %
60 os.path.basename(sys.argv[0]))
64 if len(sys.argv) > 1 and sys.argv[1] in ["-h", "--help"]:
68 notes_range = vidi.PIANO_88_KEYS_RANGE
71 destination_dir = os.path.realpath(sys.argv[1])
72 if os.path.exists(destination_dir):
73 sys.stderr.write("The destination already exists '%s'!\n"
77 os.mkdir(destination_dir)
78 create_test_videofont(FILE_PIPELINE_TEMPLATE, notes_range,
81 create_test_videofont(LIVE_PIPELINE_TEMPLATE, notes_range)
84 if __name__ == "__main__":