-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrawdata_mpl.py
More file actions
43 lines (33 loc) · 1.05 KB
/
rawdata_mpl.py
File metadata and controls
43 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""ffmpegio plugin to use `numpy.ndarray` objects for media data I/O"""
import matplotlib as Figure
from pluggy import HookimplMarker
from typing import Tuple
import io
hookimpl = HookimplMarker("ffmpegio")
@hookimpl
def video_info(obj: Figure) -> Tuple[Tuple[int, int, int], str]:
"""get video frame info
:param obj: matplotlib Figure object
:type obj: Figure
:return: shape (height,width,4) and data type "|u1" (rgba)
:rtype: Tuple[Tuple[int, int, int], str]
"""
try:
return (int(obj.bbox.bounds[3]), int(obj.bbox.bounds[2]), 4), "|u1"
except:
return None
@hookimpl
def video_bytes(obj: Figure) -> memoryview:
"""return bytes-like object of rawvideo NumPy array
:param obj: video frame data with arbitrary number of frames
:type obj: Figure
:return: memoryview of video frames
:rtype: memoryview
"""
try:
with io.BytesIO() as io_buf:
obj.savefig(io_buf, format="raw")
io_buf.seek(0)
return io_buf.getvalue()
except:
None