Document how to create a more interesting VideoFont
[vidi-player.git] / create_test_videofont.py
index d113875..92f17b5 100755 (executable)
@@ -4,29 +4,50 @@ import sys
 import os
 import vidi
 
 import os
 import vidi
 
+#FONT_DESC = "Andale Mono, 72"
+FONT_DESC = "Mono, 72"
+
+SAMPLE_LENGTH_SECONDS = 4
+
+VIDEO_FRAMERATE = 25
+VIDEO_BUFFERS = SAMPLE_LENGTH_SECONDS * VIDEO_FRAMERATE
+
+AUDIO_SAMPLERATE = 48000
+AUDIO_SAMPLESPERBUFFER = 1024
+AUDIO_BUFFERS = round(SAMPLE_LENGTH_SECONDS * 48000 / 1024)
 
 LIVE_PIPELINE_TEMPLATE = """
 
 LIVE_PIPELINE_TEMPLATE = """
-  videotestsrc num-buffers=1 pattern=black ! \
-          textoverlay valignment=center halignment=center font-desc="Sans, 72" text="{0}" ! \
+  videotestsrc num-buffers=%d pattern=black ! video/x-raw,framerate=%d/1 ! \
+          textoverlay valignment=center halignment=center font-desc="%s" text="{0}" ! \
           autovideosink \
           autovideosink \
-  audiotestsrc num-buffers=100 freq={1:f} ! \
+  audiotestsrc num-buffers=%d samplesperbuffer=%d freq={1:f} ! audio/x-raw,rate=%d ! \
           autoaudiosink
           autoaudiosink
-"""
-
-#FONT_DESC = "Andale Mono, 72"
-FONT_DESC = "Mono, 72"
+""" % (VIDEO_BUFFERS, VIDEO_FRAMERATE, FONT_DESC, AUDIO_BUFFERS,
+       AUDIO_SAMPLESPERBUFFER, AUDIO_SAMPLERATE)
 
 FILE_PIPELINE_TEMPLATE = """
 
 FILE_PIPELINE_TEMPLATE = """
-  matroskamux name=mux ! filesink location="{2}/sample_{0}.mkv"
-  videotestsrc num-buffers=1 pattern=black ! \
+  webmmux name=mux ! filesink location="{2}/sample_{0}.webm"
+  videotestsrc num-buffers=%d pattern=black ! video/x-raw,framerate=%d/1 ! \
           textoverlay valignment=center halignment=center font-desc="%s" text="{0}" ! \
           textoverlay valignment=center halignment=center font-desc="%s" text="{0}" ! \
-          queue ! schroenc rate-control=3 ! mux.
-  audiotestsrc num-buffers=100 freq={1:f} ! \
+          queue ! vp9enc ! mux.
+  audiotestsrc num-buffers=%d samplesperbuffer=%d freq={1:f} ! audio/x-raw,rate=%d ! \
           queue ! audioconvert ! vorbisenc quality=0.5 ! queue ! mux.
           queue ! audioconvert ! vorbisenc quality=0.5 ! queue ! mux.
+""" % (VIDEO_BUFFERS, VIDEO_FRAMERATE, FONT_DESC, AUDIO_BUFFERS,
+       AUDIO_SAMPLESPERBUFFER, AUDIO_SAMPLERATE)
+
+PNG_REST_SAMPLE_TEMPLATE = """
+  videotestsrc num-buffers=1 pattern=black ! \
+          textoverlay valignment=center halignment=center font-desc="%s" text="rest" ! \
+          pngenc ! filesink location="{0}/sample_rest.png"
 """ % FONT_DESC
 
 
 def create_test_videofont(pipeline_template, notes_range, destination_dir=None):
 """ % FONT_DESC
 
 
 def create_test_videofont(pipeline_template, notes_range, destination_dir=None):
+    print("Silence")
+    pipeline_string = pipeline_template.format("rest", 0, destination_dir)
+    player = vidi.Player.from_pipeline_string(pipeline_string)
+    player.play()
+
     for i, note_number in enumerate(notes_range):
         note = vidi.SpnNote(note_number)
 
     for i, note_number in enumerate(notes_range):
         note = vidi.SpnNote(note_number)
 
@@ -62,6 +83,10 @@ def main():
         os.mkdir(destination_dir)
         create_test_videofont(FILE_PIPELINE_TEMPLATE, notes_range,
                               destination_dir)
         os.mkdir(destination_dir)
         create_test_videofont(FILE_PIPELINE_TEMPLATE, notes_range,
                               destination_dir)
+
+        pipeline_string = PNG_REST_SAMPLE_TEMPLATE.format(destination_dir)
+        player = vidi.Player.from_pipeline_string(pipeline_string)
+        player.play()
     else:
         create_test_videofont(LIVE_PIPELINE_TEMPLATE, notes_range)
 
     else:
         create_test_videofont(LIVE_PIPELINE_TEMPLATE, notes_range)