README: add video overlay example
This commit is contained in:
parent
759b9701c3
commit
47b5a27d2c
1 changed files with 40 additions and 1 deletions
41
README.rst
41
README.rst
|
|
@ -122,6 +122,45 @@ Logging, Properties, Python Key Bindings, Screenshots and youtube-dl
|
||||||
|
|
||||||
del player
|
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
|
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 = mpv.MPV()
|
||||||
player.play('test.webm')
|
player.play('test.webm')
|
||||||
player.wait_for_property('core-idle', lambda idle: not idle)
|
player.wait_until_playing()
|
||||||
player.sub_add('test.srt')
|
player.sub_add('test.srt')
|
||||||
player.wait_for_playback()
|
player.wait_for_playback()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue