Skip to content

Instantly share code, notes, and snippets.

@TuxSeb
Last active June 3, 2023 18:43
Show Gist options
  • Save TuxSeb/700abfd23e855b07158519f0fbfc9775 to your computer and use it in GitHub Desktop.
Save TuxSeb/700abfd23e855b07158519f0fbfc9775 to your computer and use it in GitHub Desktop.

Compile and install FFMPEG and SRT on your Raspberry Pi

You'll need to do thoses steps on both of your device (video Transmitter and video Receiver) to make it work.

Open your terminal.

first, do : export LDFLAGS='-latomic'

then

sudo apt update && sudo apt upgrade -y 
sudo apt -y install autoconf automake build-essential cmake doxygen git yasm libssl-dev libv4l-dev libx264-dev pkg-config python3-dev python3-pip texinfo wget librtmp-dev pkg-config tclsh

Install SRT

mkdir ~/ffmpeg-libraries

git clone https://github.com/Haivision/srt ~/ffmpeg-libraries/srt \
  && cd ~/ffmpeg-libraries/srt \
  && ./configure \
  && make -j$(nproc) \
  && sudo make install

Install FFMPEG

You'll need to compile FFMPEG on your device to get it to work with SRT

git clone --depth 1 https://github.com/FFmpeg/FFmpeg.git ~/FFmpeg \
  && cd ~/FFmpeg \
  && ./configure \
    --extra-cflags="-I/usr/local/include" \
    --extra-ldflags="-L/usr/local/lib" \
    --extra-libs="-lpthread -lm -latomic" \
    --enable-gpl \
    --enable-libx264 \
    --enable-libsrt \
    --enable-nonfree \
    --enable-version3 \
    --target-os=linux \
    --enable-pthreads \
    --enable-openssl \
    --enable-hardcoded-tables \
    --enable-librtmp \
    --arch=armel \
  && make -j$(nproc) \
  && sudo make install

If you want to compile FFMPEG with SRT on a non arm-based device, just remove the line --arch=armel or else you're going to have a compilation error.

You can also remove the -enable-librtmp but this protocol is an alternative to SRT if you want to compare the perfomances of both.

Usage

You can now (normally) transmit your video stream for the Transmitter (Tx) to the Receiver (Rx).

Transmitter

ffmpeg -input_format <format> -i <input_video> -video_size <resolution> -framerate <framerate> -c:v copy <codec> -f mpegts "srt://0.0.0.0:7000?pkt_size=1316&mode=listener"

input_video: generaly /dev/video0

format: v4l2 (with raspberry pi official camera)

codec: h264

Receiver

We're going to use UDP protocol to watch the video, of course you can use something else like HLS or DASH like a real streaming platform (youtube, twitch...) .

ffmpeg -re -i srt://<ip adress of your transmitter>:7000?pkt_size=1316 -vcodec copy -strict -2 -y -f mpegts "udp://<ip of the device you're going to watch the stream on>:7000?mode=client"

I greatly advise to play with settings (quality of video, framerate, encoding, packet size...) following your needs of Quality/Latency.

Player

you can play the stream on VLC: media > open a network stream > paste "udp://<ip of the device you're going to watch the stream on>:7000?mode=client"

OR

if you're on linux (you'll may need to install ffplay, sudo apt update && sudo apt install ffplay), open terminal and

ffplay udp://<ip of the device you're going to watch the stream on>:7000?mode=client

Notes

Do not hesitate to contact me to update this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment