Skip to content

Instantly share code, notes, and snippets.

@francisuk1989
Last active March 19, 2023 21:18
Show Gist options
  • Save francisuk1989/fa7fb6aea56135279e2151c7afff19b3 to your computer and use it in GitHub Desktop.
Save francisuk1989/fa7fb6aea56135279e2151c7afff19b3 to your computer and use it in GitHub Desktop.
FFmpeg to RTMP
Nvidia GPU to ffmpeg for RTMP with nginx 1.22.0 + Ubuntu MATE 22.04.2
# https://www.elpamsoft.com/?p=Plex-Hardware-Transcoding
### Build
Install NVIDIA CUDA Toolkit here for Linux/Ubuntu however Debain will use the same commands.
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64
Compile ffmpeg for CUDA
https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/index.html#compiling-for-linux
cd to NGINX source directory & run this:
sudo apt-get update -qq && sudo apt-get -y install git openssl
git clone https://github.com/arut/nginx-rtmp-module
git clone https://github.com/arut/nginx-ts-module
./configure --add-module=nginx-rtmp-module --nginx-ts-module --with-http_ssl_module
make
make install
### Steam
Stream your file via RTMP with you NVIDA GPU and leave the CPU to do only Audio (AAC) what is VERY little CPU used.
`ffmpeg -re -i INPUT -c:v h264_nvenc -c:a aac -b:a 96k -tune zerolatency -f flv rtmp://SERVERIP/live/ARBITRARY_NAME`
Limit speed by 10Mb per sec (9904 Kb for Video / 96 Kb for Audio = 10000 Kb (https://www.gbmb.org/mb-to-kb ffmpeg reads them in in decimal
`ffmpeg -re -i INPUT -c:a aac -b:a 96k -c:v h264_nvenc -b:v 9904k -tune zerolatency -f flv rtmp://SERVERIP/live/ARBITRARY_NAME`
ffmpeg_dash.sh
`ffmpeg -re -i INPUT -c:v h264_nvenc -tune zerolatency -f dash ARBITRARY_NAME.mpd`
}
# RTMP configuration
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935;
chunk_size 4000;
application live {
# enable live streaming
live on;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment