summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2017-08-03 12:37:55 +0200
committerjaseg <code@jaseg.net>2017-08-03 12:39:44 +0200
commit48eb88ef549002c66b59ba96418f77fb9515222e (patch)
treedafa2b17238b5655e3bbf86a646e85ccfd4b3080
parent1582390031e4891d88424ea1b958aeb67a075385 (diff)
downloadpython-mpv-48eb88ef549002c66b59ba96418f77fb9515222e.tar.gz
python-mpv-48eb88ef549002c66b59ba96418f77fb9515222e.tar.bz2
python-mpv-48eb88ef549002c66b59ba96418f77fb9515222e.zip
Add pillow-based screenshot_raw command
-rw-r--r--README.rst6
-rw-r--r--mpv.py11
2 files changed, 17 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index a06509a..a1f0987 100644
--- a/README.rst
+++ b/README.rst
@@ -90,6 +90,12 @@ Advanced Usage
print('THERE IS NO ESCAPE')
player.register_key_binding('q', my_q_binding)
+ def my_s_binding(state, key):
+ if state[0] == 'd':
+ pillow_img = player.screenshot_raw()
+ pillow_img.save('screenshot.png')
+ player.register_key_binding('s', my_s_binding)
+
player.play('https://youtu.be/DLzxrzFCyOs')
player.wait_for_playback()
diff --git a/mpv.py b/mpv.py
index 27af879..5348d8f 100644
--- a/mpv.py
+++ b/mpv.py
@@ -659,6 +659,17 @@ class MPV(object):
""" Mapped mpv screenshot_to_file command, see man mpv(1). """
self.command('screenshot_to_file', filename.encode(fs_enc), includes)
+ def screenshot_raw(self, includes='subtitles'):
+ """ Mapped mpv screenshot_raw command, see man mpv(1). Returns a pillow Image object."""
+ from PIL import Image
+ res = self.node_command('screenshot-raw', includes)
+ if res['format'] != 'bgr0':
+ raise ValueError('Screenshot in unknown format "{}". Currently, only bgr0 is supported.'
+ .format(res['format']))
+ img = Image.frombytes('RGBA', (res['w'], res['h']), res['data'])
+ b,g,r,a = img.split()
+ return Image.merge('RGB', (r,g,b))
+
def playlist_next(self, mode='weak'):
""" Mapped mpv seek command, see man mpv(1). """
self.command('playlist_next', mode)