Skip to content

Commit aa4e455

Browse files
committed
added using()
1 parent 3e39921 commit aa4e455

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/ffmpegio/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
logger.warning(str(e))
4747

4848
use = plugins.use
49+
using = plugins.using
4950

5051
def __getattr__(name):
5152
if name == "ffmpeg_ver":
@@ -70,7 +71,7 @@ def __getattr__(name):
7071
# fmt:off
7172
__all__ = ["ffmpeg_info", "get_path", "set_path", "is_ready", "ffmpeg", "ffprobe",
7273
"transcode", "caps", "probe", "audio", "image", "video", "media", "devices",
73-
"open", "ffmpegprocess", "FFmpegError", "FilterGraph", "FFConcat", "use"]
74+
"open", "ffmpegprocess", "FFmpegError", "FilterGraph", "FFConcat", "use", "using"]
7475
# fmt:on
7576

7677
__version__ = "0.11.1"

src/ffmpegio/plugins/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ def use(name: Literal["read_numpy", "read_bytes"] | str):
100100
pm.register(plugin)
101101

102102

103+
def using(
104+
media_type: Literal["video", "audio"],
105+
) -> Literal["read_numpy", "read_bytes"] | str:
106+
"""Returns current rawdata primary read mode
107+
108+
:para media_type: Specifies the target media stream type
109+
110+
"""
111+
112+
name = "bytes_to_audio" if media_type == "audio" else "bytes_to_video"
113+
read_plugin = pm.subset_hook_caller(name, ()).get_hookimpls()[-1].plugin_name
114+
115+
return {
116+
"ffmpegio.plugins.rawdata_numpy": "read_numpy",
117+
"ffmpegio.plugins.rawdata_bytes": "read_bytes",
118+
}.get(read_plugin, read_plugin)
119+
120+
103121
def initialize():
104122
"""initilaize manager and load builtin plugins"""
105123

tests/test_plugins.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import logging
2+
13
from ffmpegio.utils import prod
24
from ffmpegio import plugins
35

6+
logging.basicConfig(level=logging.INFO)
47

58
def test_rawdata_bytes():
69
hook = plugins.get_hook()
@@ -32,6 +35,8 @@ def test_use():
3235
import numpy as np
3336

3437
plugins.use("read_numpy")
38+
assert plugins.using('video')=='read_numpy'
39+
assert plugins.using('audio')=='read_numpy'
3540

3641
dtype = "|u1"
3742
shape = (2, 2, 3)
@@ -42,6 +47,9 @@ def test_use():
4247
assert isinstance(data, np.ndarray)
4348

4449
plugins.use("read_bytes")
50+
assert plugins.using('video')=='read_bytes'
51+
assert plugins.using('audio')=='read_bytes'
52+
4553
hook = plugins.get_hook()
4654
data = hook.bytes_to_video(b=b, dtype=dtype, shape=shape, squeeze=False)
4755
assert isinstance(data, dict)

0 commit comments

Comments
 (0)