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)
38 PNG_REST_SAMPLE_TEMPLATE = """
39 videotestsrc num-buffers=1 pattern=black ! \
40 textoverlay valignment=center halignment=center font-desc="%s" text="rest" ! \
41 pngenc ! filesink location="{0}/sample_rest.png"
45 def create_test_videofont(pipeline_template, notes_range, destination_dir=None):
47 pipeline_string = pipeline_template.format("rest", 0, destination_dir)
48 player = vidi.Player.from_pipeline_string(pipeline_string)
51 for i, note_number in enumerate(notes_range):
52 note = vidi.SpnNote(note_number)
54 print("%2d %s" % (i, note))
56 pipeline_string = pipeline_template.format(note.name, note.frequency, destination_dir)
58 player = vidi.Player.from_pipeline_string(pipeline_string)
65 print("usage: %s [<videofont_destination_dir>]" %
66 os.path.basename(sys.argv[0]))
70 if len(sys.argv) > 1 and sys.argv[1] in ["-h", "--help"]:
74 notes_range = vidi.PIANO_88_KEYS_RANGE
77 destination_dir = os.path.realpath(sys.argv[1])
78 if os.path.exists(destination_dir):
79 sys.stderr.write("The destination already exists '%s'!\n"
83 os.mkdir(destination_dir)
84 create_test_videofont(FILE_PIPELINE_TEMPLATE, notes_range,
87 pipeline_string = PNG_REST_SAMPLE_TEMPLATE.format(destination_dir)
88 player = vidi.Player.from_pipeline_string(pipeline_string)
91 create_test_videofont(LIVE_PIPELINE_TEMPLATE, notes_range)
94 if __name__ == "__main__":