Example
Parsing Audio From RTMP Streams
If you want to parse audio from RTMP for a production application, you would import libraries such as FFMPEG and perform the parsing, remuxing, and file writing directly from your programming language.
However, in the interest of keeping this guide concise, I’ll demonstrate how you can parse audio from an RTMP stream via the terminal. In the future, we’ll release a sample application that goes into more detail.
Prerequisites
- Download and install FFMPEG
Listen for RTMP traffic
The following command will listen for RTMP traffic sent to your local machine. It then copies the data and only writes the audio to an output file. The same could be done with video.
ffmpeg -listen 1 -i rtmp://localhost/live/STREAM_NAME -vn -acodec copy output-audio.aac
Stream to FFMPEG
Now that we have a server running, open a new terminal window. In the new window, provide the command that you used earlier to stream a video to your server:
ffmpeg -re -i ~/Downloads/sample-mp4-file.mp4 -c copy -f flv rtmp://localhost/live/STREAM_NAME
When the stream is complete, you can open output-audio.aac and listen to the audio from the stream.