|
| 1 | +# FFmpeg Plugin — Media Communications Mesh |
| 2 | + |
| 3 | +FFmpeg plugin is the software extension of [FFmpeg](https://ffmpeg.org), |
| 4 | +a free and open-source software project consisting of a suite of libraries and programs |
| 5 | +for handling video, audio, and other multimedia files and streams. |
| 6 | + |
| 7 | +The plugin adds video and audio muxers and demuxers that support sending and receiving |
| 8 | +media streams via Media Communications Mesh. It uses SDK API to establish and |
| 9 | +manage connections to the Mesh. |
| 10 | + |
| 11 | +## Build and install steps |
| 12 | + |
| 13 | +1. Install Media Communications Mesh. See [Setup Guide](SetupGuide.md) for detailed process. |
| 14 | + |
| 15 | +1. Clone the FFmpeg repository and apply patches. |
| 16 | + |
| 17 | + By default, FFmpeg Release 7.0 is installed. For FFmpeg Release 6.1, |
| 18 | +replace `7.0` with `6.1` in the following script. |
| 19 | + |
| 20 | + ```bash |
| 21 | + ./clone-and-patch-ffmpeg.sh |
| 22 | + ``` |
| 23 | +1. Run the FFmpeg configuration tool |
| 24 | + |
| 25 | + ```bash |
| 26 | + ./configure-ffmpeg.sh |
| 27 | + ``` |
| 28 | + |
| 29 | +1. Build and install FFmpeg with the Media Communications Mesh FFmpeg plugin |
| 30 | + |
| 31 | + ```bash |
| 32 | + ./build-ffmpeg.sh |
| 33 | + ``` |
| 34 | + |
| 35 | +Executable file name: `ffmpeg` |
| 36 | + |
| 37 | +FFmpeg with the plugin should be running in privileged mode. |
| 38 | + |
| 39 | +## Muxers and Demuxers |
| 40 | + |
| 41 | +* **Video stream Muxer/Demuxer** `-f mcm` |
| 42 | + * Command line arguments |
| 43 | + * [General parameters](#general-parameters) |
| 44 | + * [SMPTE ST 2110 connection parameters](#smpte-st-2110-connection-parameters--conn_type-st2110) |
| 45 | + * [Multipoint Group connection parameters](#multipoint-group-connection-parameters--conn_type-multipoint-group) |
| 46 | + * [Video payload parameters](#video-payload-parameters) |
| 47 | + |
| 48 | +* **Audio stream Muxer/Demuxer** `-f mcm_audio_pcm16` |
| 49 | + * Audio format PCM 16-bit |
| 50 | + * Command line arguments |
| 51 | + * [General parameters](#general-parameters) |
| 52 | + * [SMPTE ST 2110 connection parameters](#smpte-st-2110-connection-parameters--conn_type-st2110) |
| 53 | + * [Multipoint Group connection parameters](#multipoint-group-connection-parameters--conn_type-multipoint-group) |
| 54 | + * [Audio payload parameters](#audio-payload-parameters) |
| 55 | + |
| 56 | +* **Audio stream Muxer/Demuxer** `-f mcm_audio_pcm24` |
| 57 | + * Audio format PCM 24-bit |
| 58 | + * Command line arguments |
| 59 | + * [General parameters](#general-parameters) |
| 60 | + * [SMPTE ST 2110 connection parameters](#smpte-st-2110-connection-parameters--conn_type-st2110) |
| 61 | + * [Multipoint Group connection parameters](#multipoint-group-connection-parameters--conn_type-multipoint-group) |
| 62 | + * [Audio payload parameters](#audio-payload-parameters) |
| 63 | + |
| 64 | +## Media Proxy SDK API address configuration |
| 65 | + |
| 66 | +Refer to the [SDK API Definition](SDK_API_Definition.md) for the options of configuring the Media Proxy SDK API address. |
| 67 | + |
| 68 | + |
| 69 | +## Command line arguments |
| 70 | + |
| 71 | +### General parameters |
| 72 | + |
| 73 | +| Argument | Description | Example | |
| 74 | +|------------------| ----------------------------------------------------------------------------------------|---------------------| |
| 75 | +| `-conn_type` | Connection type, `"st2110"` or `"multipoint-group"`. Default "multipoint-group". | `-conn_type st2110` | |
| 76 | +| `-conn_delay` | Connection creation delay in milliseconds, 0..10000. Default 0. | `-conn_delay 100` | |
| 77 | +| `-buf_queue_cap` | Buffer queue capacity, 2, 4, 8, 16, 32, 64, or 128. Default: 8 for video, 16 for audio. | `-buf_queue_cap 64` | |
| 78 | + |
| 79 | +### SMPTE ST 2110 connection parameters (`-conn_type st2110`) |
| 80 | + |
| 81 | +| Argument | Description | Example | |
| 82 | +|---------------------------|-------------------------------------------------------------------------------------------------------|--------------------------------------------| |
| 83 | +| `-ip_addr` | Remote device/host IP address, default "192.168.96.1". | `-ip_addr 224.0.0.1` | |
| 84 | +| `-port` | **Tx connection**: remote device/host port number.<br>**Rx connection**: local host port number. | `-port 9001` | |
| 85 | +| `-transport` | **Only for Video Muxer/Demuxer**: SMPTE ST 2110-2x transport type, `"st2110-20"` or `"st2110-22"`. Default "st2110-20".<br>**In Audio Muxers/Demuxers** this argument is not available. The SMPTE ST 2110 transport type is set internally to "st2110-30". | `-transport st2110-20` | |
| 86 | +| `-payload_type` | SMPTE ST 2110 payload type, typically between 96..127.<br>Default 112 for video, 111 for audio. | `-payload_type 112` | |
| 87 | +| `-transport_pixel_format` | Required only for the `"st2110-20"` transport type, default "yuv422p10rfc4175" | `-transport_pixel_format yuv422p10rfc4175` | |
| 88 | + |
| 89 | +### Multipoint Group connection parameters (`-conn_type multipoint-group`) |
| 90 | + |
| 91 | +| Argument | Description | Example | |
| 92 | +|----------|------------------------------------------------------------------------|---------------------| |
| 93 | +| `-urn` | Multipoint group Uniform Resource Name, or URN. Default "192.168.97.1" | `-urn 192.168.97.1` | |
| 94 | + |
| 95 | +### Video payload parameters |
| 96 | + |
| 97 | +| Argument | Description | Example | |
| 98 | +|-----------------|------------------------------------------------------------------------------------------------|-----------------------------| |
| 99 | +| `-video_size` | Video frame size, `"640x480"`, `"hd720"`, etc. Default "1920x1080". | `-video_size 1920x1080` | |
| 100 | +| `-pixel_format` | Video pixel format, `"yuv422p10le"`, `"v210"`, or `"yuv422p10rfc4175"`. Default "yuv422p10le". | `-pixel_format yuv422p10le` | |
| 101 | +| `-frame_rate` | Video frame rate, 25, 50, 59.94, 60, etc. Default 25. | `-frame_rate 60` | |
| 102 | + |
| 103 | +### Audio payload parameters |
| 104 | + |
| 105 | +| Argument | Description | Example | |
| 106 | +|----------------|-----------------------------------------------------------------|----------------------| |
| 107 | +| `-channels` | Number of audio channels, 1, 2, etc. Default: 2. | `-channels 2` | |
| 108 | +| `-sample_rate` | Audio sample rate, 48000 or 96000. Default 48000. | `-sample_rate 48000` | |
| 109 | +| `-ptime` | Audio packet time according to SMPTE ST 2110-30. Default "1ms". | `-ptime 1ms` | |
| 110 | + |
| 111 | + |
| 112 | +## Example – Run video transmission |
| 113 | + |
| 114 | +This example demonstrates sending a video file from the 1st FFmpeg instance to the 2nd FFmpeg instance via Media Communications Mesh, then streaming it to a remote machine via UDP. |
| 115 | + |
| 116 | +### Run Mesh Agent |
| 117 | + ```bash |
| 118 | + mesh-agent |
| 119 | + ``` |
| 120 | + |
| 121 | +### Receiver side setup |
| 122 | + |
| 123 | +1. Start Media Proxy |
| 124 | + |
| 125 | + ```bash |
| 126 | + sudo media_proxy \ |
| 127 | + -d 0000:32:01.1 \ |
| 128 | + -i 192.168.96.11 \ |
| 129 | + -r 192.168.97.11 \ |
| 130 | + -p 9200-9299 \ |
| 131 | + -t 8002 |
| 132 | + ``` |
| 133 | + |
| 134 | +1. Start FFmpeg to receive frames from Media Communications Mesh and stream them to a remote machine via UDP |
| 135 | + |
| 136 | + ```bash |
| 137 | + sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg -f mcm \ |
| 138 | + -conn_type st2110 \ |
| 139 | + -transport st2110-20 \ |
| 140 | + -ip_addr 192.168.96.10 \ |
| 141 | + -port 9001 \ |
| 142 | + -frame_rate 60 \ |
| 143 | + -video_size 1920x1080 \ |
| 144 | + -pixel_format yuv422p10le \ |
| 145 | + -i - -vcodec mpeg4 -f mpegts udp://<remote-ip>:<remote-port> |
| 146 | + ``` |
| 147 | + |
| 148 | +### Sender side setup |
| 149 | + |
| 150 | +1. Start Media Proxy |
| 151 | + |
| 152 | + ```bash |
| 153 | + sudo media_proxy \ |
| 154 | + -d 0000:32:01.0 \ |
| 155 | + -i 192.168.96.10 \ |
| 156 | + -r 192.168.97.10 \ |
| 157 | + -p 9100-9199 \ |
| 158 | + -t 8001 |
| 159 | + ``` |
| 160 | + |
| 161 | +2. Start FFmpeg to stream a video file to the receiver via Media Communications Mesh |
| 162 | + |
| 163 | + ```bash |
| 164 | + sudo MCM_MEDIA_PROXY_PORT=8001 ffmpeg -i <video-file-path> -f mcm \ |
| 165 | + -conn_type st2110 \ |
| 166 | + -transport st2110-20 \ |
| 167 | + -ip_addr 192.168.96.11 \ |
| 168 | + -port 9001 \ |
| 169 | + -frame_rate 60 \ |
| 170 | + -video_size 1920x1080 \ |
| 171 | + -pixel_format yuv422p10le - |
| 172 | + ``` |
| 173 | + |
| 174 | + When sending a raw video file that lack metadata, you must explicitly provide FFmpeg |
| 175 | + with the necessary video frame details. This includes specifying the format |
| 176 | + `-f rawvideo`, pixel format `-pix_fmt`, and resolution `-s WxH`. Example: |
| 177 | + |
| 178 | + ```bash |
| 179 | + ffmpeg -f rawvideo -pix_fmt yuv422p10le -s 1920x1080 -i <video-file-path> ... |
| 180 | + ``` |
| 181 | + |
| 182 | +### VLC player setup |
| 183 | + |
| 184 | +On the remote machine start the VLC player and open a network stream from the following URL: |
| 185 | +```text |
| 186 | +udp://@:1234 |
| 187 | +``` |
| 188 | + |
| 189 | + |
| 190 | +## Example – Run audio transmission, PCM 24-bit |
| 191 | + |
| 192 | +This example demonstrates sending a PCM 24-bit encoded audio file from the 1st FFmpeg instance to the 2nd FFmpeg instance via Media Communications Mesh. |
| 193 | + |
| 194 | +### Run Mesh Agent |
| 195 | + ```bash |
| 196 | + mesh-agent |
| 197 | + ``` |
| 198 | + |
| 199 | +### Receiver side setup |
| 200 | + |
| 201 | +1. Start Media Proxy |
| 202 | + |
| 203 | + ```bash |
| 204 | + sudo media_proxy \ |
| 205 | + -d 0000:32:01.1 \ |
| 206 | + -i 192.168.96.11 \ |
| 207 | + -r 192.168.97.11 \ |
| 208 | + -p 9200-9299 \ |
| 209 | + -t 8002 |
| 210 | + ``` |
| 211 | + |
| 212 | +2. Start FFmpeg to receive packets from Media Communications Mesh and store on the disk |
| 213 | + |
| 214 | + ```bash |
| 215 | + sudo MCM_MEDIA_PROXY_PORT=8002 ffmpeg -f mcm_audio_pcm24 \ |
| 216 | + -conn_type st2110 \ |
| 217 | + -ip_addr 192.168.96.10 \ |
| 218 | + -port 9001 \ |
| 219 | + -channels 2 \ |
| 220 | + -sample_rate 48000 \ |
| 221 | + -ptime 1ms \ |
| 222 | + -i - output.wav |
| 223 | + ``` |
| 224 | + |
| 225 | +### Sender side setup |
| 226 | + |
| 227 | +1. Start Media Proxy |
| 228 | + |
| 229 | + ```bash |
| 230 | + sudo media_proxy \ |
| 231 | + -d 0000:32:01.0 \ |
| 232 | + -i 192.168.96.10 \ |
| 233 | + -r 192.168.97.10 \ |
| 234 | + -p 9100-9199 \ |
| 235 | + -t 8001 |
| 236 | + ``` |
| 237 | + |
| 238 | +2. Start FFmpeg to stream an audio file to the receiver via Media Communications Mesh |
| 239 | + |
| 240 | + ```bash |
| 241 | + sudo MCM_MEDIA_PROXY_PORT=8001 ffmpeg -i <audio-file-path> -f mcm_audio_pcm24 \ |
| 242 | + -conn_type st2110 \ |
| 243 | + -ip_addr 192.168.96.11 \ |
| 244 | + -port 9001 \ |
| 245 | + -channels 2 \ |
| 246 | + -sample_rate 48000 \ |
| 247 | + -ptime 1ms - |
| 248 | + ``` |
| 249 | + |
| 250 | +## Troubleshooting |
| 251 | + |
| 252 | +### Shared libraries error |
| 253 | +While the FFmpeg plugin build was successful, an attempt to run `ffmpeg` results in the shared libraries error: |
| 254 | +```text |
| 255 | +root@my-machine:~# ffmpeg |
| 256 | +
|
| 257 | +ffmpeg: error while loading shared libraries: libavfilter.so.9: cannot open shared object file: No such file or directory |
| 258 | +``` |
| 259 | + |
| 260 | +**Resolution:** |
| 261 | +Export the `LD_LIBRARY_PATH` directory path in your shell session by pointing to `/usr/local/lib`. Examples: |
| 262 | +```text |
| 263 | +root@my-machine:~# LD_LIBRARY_PATH=/usr/local/lib ffmpeg |
| 264 | +
|
| 265 | +ffmpeg version n6.1.1-152-ge821e6c21d Copyright (c) 2000-2023 the FFmpeg developers |
| 266 | + built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04) |
| 267 | +``` |
| 268 | +Using export: |
| 269 | +```text |
| 270 | +root@my-machine:~# export LD_LIBRARY_PATH=/usr/local/lib |
| 271 | +root@my-machine:~# ffmpeg |
| 272 | +
|
| 273 | +ffmpeg version n6.1.1-152-ge821e6c21d Copyright (c) 2000-2023 the FFmpeg developers |
| 274 | + built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04) |
| 275 | +``` |
| 276 | + |
| 277 | +<!-- References --> |
| 278 | +[license-img]: https://img.shields.io/badge/License-BSD_3--Clause-blue.svg |
| 279 | +[license]: https://opensource.org/license/bsd-3-clause |
0 commit comments