Skip to content

Commit 2b6d66c

Browse files
FFmpeg + MTL classes info and mock
1 parent a344621 commit 2b6d66c

File tree

9 files changed

+249
-5
lines changed

9 files changed

+249
-5
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_common.h
7+
8+
class MtlCommonRx:
9+
def __init__(
10+
self,
11+
# MTL_RX_DEV_ARGS
12+
p_port: str = None,
13+
p_sip: str = None,
14+
dma_dev: str = None,
15+
rx_queues: int = -1,
16+
tx_queues: int = -1,
17+
# MTL_RX_PORT_ARGS
18+
p_rx_ip: str = None,
19+
udp_port: int = 20000,
20+
payload_type: int = 112,
21+
):
22+
self.p_port = p_port
23+
self.p_sip = p_sip
24+
self.dma_dev = dma_dev
25+
self.rx_queues = rx_queues
26+
self.tx_queues = tx_queues
27+
self.p_rx_ip = p_rx_ip
28+
self.udp_port = udp_port
29+
self.payload_type = payload_type
30+
31+
def get_items(self):
32+
response = {}
33+
for key, value in self.__dict__.items():
34+
if value:
35+
response[key] = value
36+
return response
37+
38+
39+
class MtlCommonTx:
40+
def __init__(
41+
self,
42+
# MTL_TX_DEV_ARGS
43+
p_port: str = None,
44+
p_sip: str = None,
45+
dma_dev: str = None,
46+
rx_queues: int = -1,
47+
tx_queues: int = -1,
48+
# MTL_TX_PORT_ARGS
49+
p_tx_ip: str = None,
50+
udp_port: int = 20000,
51+
payload_type: int = 112,
52+
):
53+
self.p_port = p_port
54+
self.p_sip = p_sip
55+
self.dma_dev = dma_dev
56+
self.rx_queues = rx_queues
57+
self.tx_queues = tx_queues
58+
self.p_tx_ip = p_tx_ip
59+
self.udp_port = udp_port
60+
self.payload_type = payload_type
61+
62+
def get_items(self):
63+
response = {}
64+
for key, value in self.__dict__.items():
65+
if value:
66+
response[key] = value
67+
return response
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on AVOption elements from
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c
7+
# each Rx has MTL_RX_DEV_ARGS and MTL_RX_PORT_ARGS + the options provided in AVOption elements
8+
9+
from mtl_common import MtlCommonRx
10+
11+
class MtlSt20pRx(MtlCommonRx):
12+
def __init__(
13+
self,
14+
video_size: str = "1920x1080",
15+
# pix_fmt: str = "", # duplicates with pixel_format, which is clearer
16+
pixel_format: str = "yuv422p10le",
17+
fps: float = 59.94,
18+
timeout_s: int = 0,
19+
init_retry: int = 5,
20+
fb_cnt: int = 3,
21+
gpu_direct: bool = False, # FIXME: this adds -nogpu_direct, which is unwanted
22+
gpu_driver: int = 0,
23+
gpu_device: int = 0,
24+
):
25+
self.video_size = video_size
26+
self.pixel_format = pixel_format
27+
self.fps = fps
28+
self.timeout_s = timeout_s
29+
self.init_retry = init_retry
30+
self.fb_cnt = fb_cnt
31+
self.gpu_direct = gpu_direct
32+
self.gpu_driver = gpu_driver
33+
self.gpu_device = gpu_device
34+
super().__init__()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on AVOption elements from
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c
7+
# each Tx has MTL_TX_DEV_ARGS and MTL_TX_PORT_ARGS + the options provided in AVOption elements
8+
9+
from mtl_common import MtlCommonTx
10+
11+
class MtlSt20pTx(MtlCommonTx):
12+
def __init__(
13+
self,
14+
fb_cnt: int = 3,
15+
):
16+
self.fb_cnt = fb_cnt
17+
super().__init__()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on AVOption elements from
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c
7+
# each Rx has MTL_RX_DEV_ARGS and MTL_RX_PORT_ARGS + the options provided in AVOption elements
8+
9+
from mtl_common import MtlCommonRx
10+
11+
class MtlSt22pRx(MtlCommonRx):
12+
def __init__(
13+
self,
14+
video_size: str = "1920x1080",
15+
# pix_fmt: str = "", # duplicates with pixel_format, which is clearer
16+
pixel_format: str = "yuv422p10le",
17+
fps: float = 59.94,
18+
timeout_s: int = 0,
19+
init_retry: int = 5,
20+
fb_cnt: int = 3,
21+
codec_thread_cnt: int = 0,
22+
st22_codec: str = None,
23+
):
24+
self.video_size = video_size
25+
self.pix_fmt = pix_fmt
26+
self.pixel_format = pixel_format
27+
self.fps = fps
28+
self.timeout_s = timeout_s
29+
self.init_retry = init_retry
30+
self.fb_cnt = fb_cnt
31+
self.codec_thread_cnt = codec_thread_cnt
32+
self.st22_codec = st22_codec
33+
super().__init__()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on AVOption elements from
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c
7+
# each Tx has MTL_TX_DEV_ARGS and MTL_TX_PORT_ARGS + the options provided in AVOption elements
8+
9+
from mtl_common import MtlCommonTx
10+
11+
class MtlSt22pTx(MtlCommonTx):
12+
def __init__(
13+
self,
14+
fb_cnt: int = 3,
15+
bpp: float = 3.0,
16+
codec_thread_cnt: int = 0,
17+
st22_codec: str = None,
18+
):
19+
self.fb_cnt = fb_cnt
20+
self.bpp = bpp
21+
self.codec_thread_cnt = codec_thread_cnt
22+
self.st22_codec = st22_codec
23+
super().__init__()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on AVOption elements from
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c
7+
# each Rx has MTL_RX_DEV_ARGS and MTL_RX_PORT_ARGS + the options provided in AVOption elements
8+
9+
from mtl_common import MtlCommonRx
10+
11+
# TODO: Think about Enums for sample rate, channels, pcm_fmt and ptime
12+
13+
class MtlSt30pRx(MtlCommonRx):
14+
def __init__(
15+
self,
16+
fb_cnt: int = 3,
17+
timeout_s: int = 0,
18+
init_retry: int = 5,
19+
sample_rate: int = 48000,
20+
channels: int = 2,
21+
pcm_fmt: str = None,
22+
ptime: str = None,
23+
):
24+
self.fb_cnt = fb_cnt
25+
self.timeout_s = timeout_s
26+
self.init_retry = init_retry
27+
self.sample_rate = sample_rate
28+
self.channels = channels
29+
self.pcm_fmt = pcm_fmt
30+
self.ptime = ptime
31+
super().__init__()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright 2025 Intel Corporation
3+
# Media Communications Mesh
4+
5+
# generates typed-ffmpeg's extra_options for Media Transport Library based on AVOption elements from
6+
# https://github.com/OpenVisualCloud/Media-Transport-Library/blob/main/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c
7+
# each Tx has MTL_TX_DEV_ARGS and MTL_TX_PORT_ARGS + the options provided in AVOption elements
8+
9+
from mtl_common import MtlCommonTx
10+
11+
class MtlSt30pTx(MtlCommonTx):
12+
def __init__(
13+
self,
14+
fb_cnt: int = 3,
15+
ptime: str = None,
16+
):
17+
self.fb_cnt = fb_cnt
18+
self.ptime = ptime
19+
super().__init__()

tests/validation/Engine/ffmpeg_wrapper.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,31 @@
22
# Copyright 2025 Intel Corporation
33
# Media Communications Mesh
44

5-
# TODO: consider how we can use https://github.com/kkroening/ffmpeg-python
6-
# TODO: maybe we can write ffmpeg wrapper like scapy? e.g. every protocol is different class and it looks like this:
7-
# Ether()/IP()/TCP() so maybe: ffmpeg_cmd = Input()/Transport()/Output() etc.
5+
# MTL extra_options usage:
6+
# >>> import ffmpeg # (typed-ffmpeg library)
7+
# fi = ffmpeg.input(filename="-", extra_options={"ptime": "1ms"}) # extra_options to be used as a mean of adding the parameters
8+
# fo = (fi.output(filename="xyz"))
9+
# fo.compile()
10+
# ['ffmpeg', '-ptime', '1ms', '-i', '-', 'xyz']
11+
12+
# >>> import ffmpeg
13+
# >>> import mtl_st20p_rx
14+
# >>> st20p_rx = mtl_st20p_rx.MtlSt20pRx(video_size="3840x2160", timeout_s=4)
15+
# >>> st20p_rx.get_items()
16+
# {'video_size': '3840x2160', 'fps': 59.94, 'timeout_s': 4, 'init_retry': 5, 'fb_cnt': 3, 'gpu_direct': False, 'gpu_driver': 0, 'gpu_device': 0, 'rx_queues': -1, 'tx_queues': -1, 'udp_port': 20000, 'payload_type': 112}
17+
18+
# >>> fi = ffmpeg.input(filename="xyz", extra_options=st20p_rx.get_items())
19+
# >>> fo = fi.output(filename="abc")
20+
# >>> fo.compile()
21+
# ['ffmpeg', '-video_size', '3840x2160', '-fps', '59.94', '-timeout_s', '4', '-init_retry', '5', '-fb_cnt', '3', '-nogpu_direct', '-gpu_driver', '0', '-gpu_device', '0', '-rx_queues', '-1', '-tx_queues', '-1', '-udp_port', '20000', '-payload_type', '112', '-i', 'xyz', 'abc']
22+
# >>> ' '.join(fo.compile())
23+
# 'ffmpeg -video_size 3840x2160 -fps 59.94 -timeout_s 4 -init_retry 5 -fb_cnt 3 -nogpu_direct -gpu_driver 0 -gpu_device 0 -rx_queues -1 -tx_queues -1 -udp_port 20000 -payload_type 112 -i xyz abc'
24+
25+
# TODO: Continue adding above to below functions
826

927
class FFmpeg:
1028
"""
11-
FFMPEG wrapper with MCM plugin
29+
FFmpeg wrapper with MCM plugin
1230
"""
1331
def __init__(self, connection):
1432
self.conn = connection
@@ -19,4 +37,5 @@ def start_ffmpeg(self, cmd):
1937
self._processes.append(ffmpeg)
2038

2139
def prepare_st20_tx_cmd(self):
40+
# from extra_options import mcm_st20p_tx
2241
pass

tests/validation/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ pytest==8.3.2
1313
pytest-check==2.3.1
1414
tomli==2.0.1
1515
pytest-json-report==1.5.0
16-
pytest-metadata==3.1.1
16+
pytest-metadata==3.1.1
17+
typed-ffmpeg==2.6.4

0 commit comments

Comments
 (0)