Initial import
[vidi-player.git] / create_test_videofont.py
1 #!/usr/bin/env python3
2
3 import sys
4 import os
5 import vidi
6
7
8 LIVE_PIPELINE_TEMPLATE = """
9   videotestsrc num-buffers=1 pattern=black ! \
10           textoverlay valignment=center halignment=center font-desc="Sans, 72" text="{0}" ! \
11           autovideosink \
12   audiotestsrc num-buffers=100 freq={1:f} ! \
13           autoaudiosink
14 """
15
16 #FONT_DESC = "Andale Mono, 72"
17 FONT_DESC = "Mono, 72"
18
19 FILE_PIPELINE_TEMPLATE = """
20   matroskamux name=mux ! filesink location="{2}/sample_{0}.mkv"
21   videotestsrc num-buffers=1 pattern=black ! \
22           textoverlay valignment=center halignment=center font-desc="%s" text="{0}" ! \
23           queue ! schroenc rate-control=3 ! mux.
24   audiotestsrc num-buffers=100 freq={1:f} ! \
25           queue ! audioconvert ! vorbisenc quality=0.5 ! queue ! mux.
26 """ % FONT_DESC
27
28
29 def create_test_videofont(pipeline_template, notes_range, destination_dir=None):
30     for i, note_number in enumerate(notes_range):
31         note = vidi.SpnNote(note_number)
32
33         print("%2d %s" % (i, note))
34
35         pipeline_string = pipeline_template.format(note.name, note.frequency, destination_dir)
36
37         player = vidi.Player.from_pipeline_string(pipeline_string)
38         error = player.play()
39         if error:
40             break
41
42
43 def usage():
44     print("usage: %s [<videofont_destination_dir>]" %
45           os.path.basename(sys.argv[0]))
46
47
48 def main():
49     if len(sys.argv) > 1 and sys.argv[1] in ["-h", "--help"]:
50         usage()
51         return 0
52
53     notes_range = vidi.PIANO_88_KEYS_RANGE
54
55     if len(sys.argv) > 1:
56         destination_dir = os.path.realpath(sys.argv[1])
57         if os.path.exists(destination_dir):
58             sys.stderr.write("The destination already exists '%s'!\n"
59                              % destination_dir)
60             return 1
61
62         os.mkdir(destination_dir)
63         create_test_videofont(FILE_PIPELINE_TEMPLATE, notes_range,
64                               destination_dir)
65     else:
66         create_test_videofont(LIVE_PIPELINE_TEMPLATE, notes_range)
67
68
69 if __name__ == "__main__":
70     sys.exit(main())