From 47b5a27d2c1627554b99894f94639084ee9d9df7 Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 16 Jul 2020 19:28:53 +0200 Subject: README: add video overlay example --- README.rst | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'README.rst') 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() -- cgit