Add pillow-based screenshot_raw command
This commit is contained in:
parent
1582390031
commit
48eb88ef54
2 changed files with 17 additions and 0 deletions
|
|
@ -90,6 +90,12 @@ Advanced Usage
|
||||||
print('THERE IS NO ESCAPE')
|
print('THERE IS NO ESCAPE')
|
||||||
player.register_key_binding('q', my_q_binding)
|
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.play('https://youtu.be/DLzxrzFCyOs')
|
||||||
player.wait_for_playback()
|
player.wait_for_playback()
|
||||||
|
|
||||||
|
|
|
||||||
11
mpv.py
11
mpv.py
|
|
@ -659,6 +659,17 @@ class MPV(object):
|
||||||
""" Mapped mpv screenshot_to_file command, see man mpv(1). """
|
""" Mapped mpv screenshot_to_file command, see man mpv(1). """
|
||||||
self.command('screenshot_to_file', filename.encode(fs_enc), includes)
|
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'):
|
def playlist_next(self, mode='weak'):
|
||||||
""" Mapped mpv seek command, see man mpv(1). """
|
""" Mapped mpv seek command, see man mpv(1). """
|
||||||
self.command('playlist_next', mode)
|
self.command('playlist_next', mode)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue