summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2020-07-16 19:28:53 +0200
committerjaseg <code@jaseg.net>2020-07-16 19:28:53 +0200
commit47b5a27d2c1627554b99894f94639084ee9d9df7 (patch)
tree335bbcf676db4434a21fa8708f6414891ff068b6
parent759b9701c379997cc37d1c128a83302863e7df4f (diff)
downloadpython-mpv-47b5a27d2c1627554b99894f94639084ee9d9df7.tar.gz
python-mpv-47b5a27d2c1627554b99894f94639084ee9d9df7.tar.bz2
python-mpv-47b5a27d2c1627554b99894f94639084ee9d9df7.zip
README: add video overlay example
-rw-r--r--README.rst41
1 files changed, 40 insertions, 1 deletions
diff --git a/README.rst b/README.rst
index a156814..19e1269 100644
--- a/README.rst
+++ b/README.rst
@@ -122,6 +122,45 @@ Logging, Properties, Python Key Bindings, Screenshots and youtube-dl
del player
+Video overlays
+..............
+
+.. code:: python
+
+ #!/usr/bin/env python3
+ import time
+ from PIL import Image, ImageDraw, ImageFont
+ import mpv
+
+ player = mpv.MPV()
+
+ player.loop = True
+ player.play('test.webm')
+ player.wait_until_playing()
+
+ font = ImageFont.truetype('DejaVuSans.ttf', 40)
+
+ while not player.core_idle:
+
+ time.sleep(0.5)
+ overlay = player.create_image_overlay()
+
+ for pos in range(0, 500, 5):
+ ts = player.time_pos
+ if ts is None:
+ break
+
+ img = Image.new('RGBA', (400, 150), (255, 255, 255, 0))
+ d = ImageDraw.Draw(img)
+ d.text((10, 10), 'Hello World', font=font, fill=(0, 255, 255, 128))
+ d.text((10, 60), f't={ts:.3f}', font=font, fill=(255, 0, 255, 255))
+
+ overlay.update(img, pos=(2*pos, pos))
+ time.sleep(0.05)
+
+ overlay.remove()
+
+
Playlist handling
.................
@@ -187,7 +226,7 @@ called once the player is done loading the file and starts playing. An easy way
player = mpv.MPV()
player.play('test.webm')
- player.wait_for_property('core-idle', lambda idle: not idle)
+ player.wait_until_playing()
player.sub_add('test.srt')
player.wait_for_playback()