You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Build and install FFmpeg with the Media Communications Mesh FFmpeg plugin
34
30
@@ -279,11 +275,6 @@ ffmpeg version n6.1.1-152-ge821e6c21d Copyright (c) 2000-2023 the FFmpeg develop
279
275
built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04)
280
276
```
281
277
282
-
While measuring latency, it is necessary to configure FFmpeg with additional parameters. If the error `No such filter: 'drawtext'` occurs, please reconfigure and rebuild FFmpeg:
# End To End Latency Measurement — Media Communications Mesh
1
+
# End-to-End Latency Measurement — Media Communications Mesh
2
+
3
+
This document describes a simple solution for measuring end-to-end latency in Media Communications Mesh.
4
+
5
+
## Overview
6
+
7
+
The solution is based on the FFmpeg ability to print current timestamps on the sender side (Tx) and the receiver side (Rx), and the use of Optical Character Recognition (OCR) to read the timestamps out of each received video frame and calculate the delta. The choice of OCR is determined by the fact that the text can be effectively recognized even if the picture is affected by any sort of a lossy video compression algorithm somewhere in the transmission path in the Mesh. To achieve proper accuracy of the measurement, both Tx and Rx host machines should be synchronized using Precision Time Protocol (PTP).
1. Tx side – The user starts FFmpeg with special configuration to stream video via the Mesh.
39
+
1. Rx side – The user starts FFmpeg with special configuration to receive the video stream from the Mesh.
40
+
1. Tx side – FFmpeg prints the current timestamp as a huge text at the top of each video frame and transmits it via the Mesh.
41
+
1. Rx side – FFmpeg prints the current timestamp as a huge text at the bottom of each video frame received from the Mesh and saves it on the disk.
42
+
1. After transmission is done, there is a resulting MPEG video file on the disk on the Rx side.
43
+
1. The user runs the solution script against the MPEG file that recognizes the Tx and Rx timestamps in each frame, and calculates the average latency based on the difference between the timestamps. Additionally, the script generates a latency diagram and stores it in JPEG format on the disk.
## Important notice on latency measurement results
2
50
3
-
Before reading this document, please read [FFmpeg Plugin](FFmpegPlugin.md) to familiarize yourself with FFmpeg usage, as this document provides an extension.
51
+
> Please note the calculated average latency is highly dependent on the hardware configuration and CPU background load, and cannot be treated as an absolute value. The provided solution can only be used for comparing the latency in different Mesh configurations and video streaming parameters, as well as latency stability checks.
4
52
5
-
**Note:** Currently, latency measurement is available only for video transport.
6
53
7
54
## Build and install steps
8
55
9
-
1. Please follow build and install steps from [FFmpeg Plugin](FFmpegPlugin.md). with one exception, FFmpeg configuration tool requires additional parameters.
56
+
> It is assumed that Media Communications Mesh is installed on the Tx and Rx host machines according to [Setup Guide](SetupGuid.md).
57
+
58
+
If [FFmpeg Plugin](FFmpegPlugin.md) was installed earlier, remove its directory before proceeding with the following.
59
+
60
+
1. Clone the FFmpeg 7.0 repository and apply patches.
> Make sure `network_interface_1` and `network_interface_2` are connected to the same network.
26
90
91
+
*__host-1 Controller clock__
92
+
```bash
93
+
sudo ptp4l -i <network_interface_1> -m 2
94
+
sudo phc2sys -a -r -r -m
95
+
```
27
96
28
-
## Example – Run video transmission between 2 FFmpeg instances on the same host
97
+
* __host-2 Worker clock__
98
+
```bash
99
+
sudo ptp4l -i <network_interface_2> -m 2 -s
100
+
sudo phc2sys -a -r
101
+
```
29
102
30
-
This example demonstrates sending a video file from the 1st FFmpeg instance to the 2nd FFmpeg instance via Media Communications Mesh on the same host, with timestamps to measure end-to-end latency using the `drawtext` feature in FFmpeg. The `drawtext` filter allows you to overlay timestamps directly onto the video stream, providing a visual representation of latency as the video is processed and transmitted between instances/hosts.
103
+
## Example – Measuring transmission latency between two FFmpeg instances on the same host
31
104
32
-
### Run Mesh Agent
105
+
This example demonstrates sending a video file from the 1st FFmpeg instance to the 2nd FFmpeg instance via Media Communications Mesh on the same host, and then calculation of transmission latency from the recorded video.
106
+
107
+
108
+
1. Run Mesh Agent
33
109
```bash
34
110
mesh-agent
35
111
```
36
112
37
-
###Run Media Proxy
113
+
1. Run Media Proxy
38
114
39
115
```bash
40
116
sudo media_proxy \
@@ -45,7 +121,7 @@ This example demonstrates sending a video file from the 1st FFmpeg instance to t
45
121
-t 8002
46
122
```
47
123
48
-
### Receiver side setup
124
+
1. Start the Receiver side FFmpeg instance
49
125
50
126
```bash
51
127
sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg \
@@ -56,17 +132,17 @@ This example demonstrates sending a video file from the 1st FFmpeg instance to t
@@ -76,38 +152,60 @@ This example demonstrates sending a video file from the 1st FFmpeg instance to t
76
152
-pixel_format yuv422p10le -
77
153
```
78
154
79
-
When sending a raw video file that lack metadata, you must explicitly provide FFmpeg
80
-
with the necessary video frame details. This includes specifying the format
81
-
`-f rawvideo`, pixel format `-pix_fmt`, and resolution `-s WxH`. Example:
155
+
When sending a raw video file, e.g. of the YUV format, you have to explicitly specify the file format `-f rawvideo`, the pixel format `-pix_fmt`, and the video resolution `-s WxH`:
Please note that `-readrate` value have to be calculated based on `-frame_rate` parameter, simple equation is as follow:
91
-
`readrate = frame_rate / 25`, for example:
166
+
167
+
The `-readrate` value is calculated from the `-frame_rate` parameter value using the following equation: $readrate=framerate\div25$. Use the pre-calculated values from the table below.
168
+
92
169
| frame_rate | readrate |
93
170
|------------|-------------------|
94
171
| 25 | 25 / 25 = 1 |
95
172
| 50 | 50 / 25 = 2 |
96
173
| 60 | 60 / 25 = 2.4 |
97
174
175
+
1. Run the script against the recorded MPEG file. The first argument is the input video file path. The second argument is the optional latency diagram JPEG file path to be generated.
File: recv.mp4 | Last modified: 2025-06-02 13:49:54 UTC
192
+
Resolution: 640x360 | FPS: 25.00
193
+
Average End-to-End Latency: 564.61 ms
194
+
```
195
+
196
+
See the [Sample latency diagram](#sample-latency-diagram).
197
+
98
198
99
-
## Example – Run video transmission between 2 FFmpeg instances on different hosts
199
+
## Example – Measuring transmission latency between two FFmpeg instances on different hosts
100
200
101
-
This example demonstrates sending a video file from the 1st FFmpeg instance to the 2nd FFmpeg instance via Media Communications Mesh, with timestamps to measure end-to-end latency using the `drawtext` feature in FFmpeg. The `drawtext` filter allows you to overlay timestamps directly onto the video stream, providing a visual representation of latency as the video is processed and transmitted between instances/hosts.
201
+
This example demonstrates sending a video file from the 1st FFmpeg instance to the 2nd FFmpeg instance via Media Communications Mesh on the same host, and then calculation of transmission latency from the recorded video.
102
202
103
-
###Run Mesh Agent
203
+
1. Run Mesh Agent
104
204
```bash
105
205
mesh-agent
106
206
```
107
207
108
-
### Receiver side setup
109
-
110
-
1. Start Media Proxy
208
+
1. Start Media Proxy on the Receiver host machine
111
209
112
210
```bash
113
211
sudo media_proxy \
@@ -118,7 +216,7 @@ This example demonstrates sending a video file from the 1st FFmpeg instance to t
118
216
-t 8002
119
217
```
120
218
121
-
1. Start FFmpeg to receive frames from Media Communications Mesh and save received data on hard drive
219
+
1. Start the Receiver side FFmpeg instance
122
220
123
221
```bash
124
222
sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg \
@@ -132,15 +230,13 @@ This example demonstrates sending a video file from the 1st FFmpeg instance to t
@@ -169,25 +265,28 @@ This example demonstrates sending a video file from the 1st FFmpeg instance to t
169
265
-pixel_format yuv422p10le -
170
266
```
171
267
172
-
## Stream postprocessing
173
-
The generated stream can be analyzed manually, but it is a long process. To accelerate it, there is a small sript written in Python that automatically extracts and plots latency.
268
+
1. Run the script against the recorded MPEG file. The first argument is the input video file path. The second argument is the optional latency diagram JPEG file path to be generated.
File: recv.mp4 | Last modified: 2025-06-02 13:49:54 UTC
285
+
Resolution: 640x360 | FPS: 25.00
286
+
Average End-to-End Latency: 564.61 ms
189
287
```
190
-
When preparing FFmpeg command if you change parameters of `drawtext` filter, especialy `fontsize`, `x`, `y` or `text`, you have to adjust script __text-detection.py__ too, please refer to function `extract_text_from_region(image, x, y, font_size, length)`
288
+
289
+
See the [Sample latency diagram](#sample-latency-diagram).
0 commit comments