Streaming Audio from a Raspberry Pi using FFmpeg
In this article, we will cover the process of setting up a Raspberry Pi as a streaming audio speaker using FFmpeg and a USB sound card. This setup will allow you to stream audio from various sources, such as a networked computer or a smartphone, to the Raspberry Pi over a local network using the Real-Time Streaming Protocol (RTSP).
Hardware Requirements
To follow this guide, you will need the following hardware:
- A Raspberry Pi (any model should work, but this guide was written using a Raspberry Pi 4)
- A USB sound card (such as the Seeed Studio 2-channel microphone amplifier hat)
- A set of speakers (with a 3.5mm audio jack) or a USB audio adapter (if your speakers don't have a 3.5mm jack)
Setting up the Raspberry Pi
First, you will need to install an operating system on your Raspberry Pi. For this guide, we will use the Raspberry Pi OS Lite image, which can be downloaded from the official Raspberry Pi website. Once you have the image, you can use a tool like Etcher to burn it to an SD card. After that, insert the SD card into your Raspberry Pi, connect the USB sound card, and power it on.
Next, you will need to connect to the Raspberry Pi using SSH. You can use a tool like PuTTY to do this. The default username and password for the Raspberry Pi OS Lite image are pi and raspberry, respectively.
Installing FFmpeg
Once you are logged in to the Raspberry Pi, you can install FFmpeg by running the following command:
sudo apt-get update && sudo apt-get install ffmpegSetting up the Audio Device
To check the available audio devices on your Raspberry Pi, you can run the following command:
arecord -lThis will list the available audio devices, along with their card and device numbers. For example, the Seeed Studio 2-channel microphone amplifier hat is listed as card 1: seeed2mic [seeed2mic], device 0: USB Audio [USB Audio].
To use this device as the default audio output, you can run the following command:
amixer cset numid=3 < 1Streaming Audio
Now that you have everything set up, you can start streaming audio to the Raspberry Pi using FFmpeg. For example, if you want to stream audio from a networked computer running VLC media player, you can use the following command:
ffmpeg -re -f pulse -i plughw:CARD=seeed2mic,DEV=0 -rtsp_transport tcp -c copy -f rtsp rtsp://ignacio@pi-satellite-bigbedroom:8554/streamThis command will capture audio from the USB sound card, encode it in real-time, and stream it over RTSP to the specified IP address and port. To play the stream on a device, you can use a media player like VLC or Kodi, and enter the RTSP URL in the "Open Network Stream" dialog.
- In this article, we covered the process of setting up a Raspberry Pi as a streaming audio speaker using FFmpeg and a USB sound card.
- We discussed the hardware requirements, and walked through the process of setting up the Raspberry Pi, installing FFmpeg, and configuring the audio device.
- Finally, we demonstrated how to stream audio to the Raspberry Pi using RTSP, and how to play the stream on a device using a media player like VLC or Kodi.