| | 148 | == Streaming a ZMQ audio stream from FFmpeg == |
| | 149 | |
| | 150 | FFmpeg can stream using the [https://en.wikipedia.org/wiki/ZeroMQ] if compiled with the `--enable-libzmq` flag at build time. The streaming should also be done utilizing the -re option, for real-time streaming (i.e. it slows it down to simulate a live streaming [http://ffmpeg.org/ffmpeg.html source]. ZMQ is primarily TCP as in this example but other streaming options are possible. |
| | 151 | |
| | 152 | For example the following command will generate a signal, and will stream it to the port 5555 on localhost: |
| | 153 | {{{ |
| | 154 | ffmpeg -re -hide_banner -f s16le -ar 48000 -ac 2 -i - -f mpegts -acodec libopus -b:a 128k zmq:tcp://127.0.0.1:${streamPort} |
| | 155 | }}} |
| | 156 | |
| | 157 | To play the stream with ffplay, run the command: |
| | 158 | {{{ |
| | 159 | ffplay -autoexit -nodisp zmq:tcp://${serverAddress}:${streamPort} |
| | 160 | }}} |
| | 161 | |
| | 162 | A secure stream can be accessed with the above ffplay command from a remote client by connecting to the server via an ssh tunnel: |
| | 163 | {{{ |
| | 164 | autossh -fvN -M0 -L${streamPort}:localhost:${streamPort} ${serverAddress} -p${sshPort}" |
| | 165 | }}} |
| | 166 | Where {{{streamPort}}} is the port for the stream (also the ssh tunnel port); {{{serverAddress}}} and {{{sshPort}}} are the server url/ip address and port, respectively. (Adding {{{-R${returnPort}:localhost:22}}} allows access from the server back to the client if desirable. {{{ssh}}} can be used in place of autossh for a simpler connection if less reliable connection; a VPN tunnel would also suffice.) |
| | 167 | |