An nginx-rtmp container for encoding streams with ffmpeg, and pushing to other streaming servers
7.9K
An nginx-rtmp container for encoding streams with ffmpeg, and pushing to other streaming servers, e.g. twitch.tv
This is useful if you would like to offload the CPU cost of expensive video compression, allowing you to stream relatively uncompressed video at high bitrates on a fast, local network, and have a different PC encode and publish the stream to the remote server.
STREAM_KEY: the stream key required by your streaming service, e.g. live_x01234567890123456789xBITRATE: the bitrate, in Kbps, to output (ensure your internet upstream can handle this value), default 2500BUFSIZE: the bufsize, in Kbps, default BITRATE / 3RESOLUTION the resolution to output, default 1280x720PRESET the x264 preset to encode with, default veryfastPROFILE the x264 profile to use, default highFRAMERATE the framerate to output, default 30BFRAMES the number of B-Frames to use, default 3THREADS the number of CPU threads to use for encoding, default 0 for autoSCALER the x264 scaler to use, default lanczosRC_LOOKAHEAD the number of frames to lookahead for rate control, default FRAMERATE / 3INGEST the streaming service ingest server, default rtmp://live-jfk.twitch.tv/appSTREAM_KEY_2: the stream key for a second streaming serviceINGEST_2 a second streaming service ingest server, default noneThe variables you set will be assembled into the following ffmpeg arguments:
-s ${RESOLUTION} -c:v libx264 -preset ${PRESET} -profile:v ${PROFILE} -r ${FRAMERATE} -g ${FRAMERATE_2X} \
-x264-params \"bitrate=${BITRATE}:vbv_maxrate=${BITRATE}:vbv_bufsize=${BUFSIZE}:threads=${THREADS}:bframes=${BFRAMES}:rc_lookahead=${RC_LOOKAHEAD}:keyint=${FRAMERATE_2X}:min-keyint=${FRAMERATE_2X}:nal_hrd=cbr:scenecut=0:rc=cbr:force-cfr=1\" -sws_flags ${SCALER} -pix_fmt yuv420p -c:a copy -f flv -strict normal
If you prefer to customize the ffmpeg arguments, you can instead set the FFMPEG_ARGS environment variable, in which case none of the other optional environment variables will be used.
You can see a list of Twitch suggested settings and ingest endpoints at stream.twitch.tv, and you can validate your configuration is proper and stable at inspector.twitch.tv.
When selecting your options, be aware that presets from veryfast and above noticeably lower picture quality. For more information about stream quality, read https://streamquality.report.
simplified:
docker run --rm -it -p 1935:1935 -e STREAM_KEY=live_x01234567890123456789x \
shamelesscookie/nginx-rtmp-ffmpeg:latest
customized:
docker run --rm -it -p 1935:1935 -e STREAM_KEY=live_x01234567890123456789x -e THREADS=0 \
-e BITRATE=2500 -e RESOLUTION=1280x720 -e PRESET=veryfast -e FRAMERATE=30 -e PROFILE=high \
-e BFRAMES=3 -e INGEST=rtmp://live-jfk.twitch.tv/app shamelesscookie/nginx-rtmp-ffmpeg:latest
version: '2'
services:
nginx-rtmp-ffmpeg:
container_name: nginx-rtmp-ffmpeg
image: shamelesscookie/nginx-rtmp-ffmpeg:latest
network_mode: host
ports:
- 1935
restart: always
environment:
- STREAM_KEY=live_x01234567890123456789x
- BITRATE=2500
- BUFSIZE=833
- RESOLUTION=1280x720
- PRESET=veryfast
- FRAMERATE=30
- PROFILE=high
- THREADS=0
- BFRAMES=3
- SCALER=area
- RC_LOOKAHEAD=10
- INGEST=rtmp://live-jfk.twitch.tv/app
Configure your streaming software to output to rtmp://<docker-server>:1935/livein
Make sure you include your stream key in your streaming software as well, e.g. for OBS:
Custom Streaming Serverrtmp://<docker-server>:1935/livein, e.g. rtmp://mydockerbox:1935/livein<your-stream-key>Then use video settings that are very high in quality and low in overhead, e.g. for nVidia video cards:
NVENC H.264CBR50000 or 100000 or 150000 (depending on your local network)2High Qualityhigh0Content type
Image
Digest
Size
36.1 MB
Last updated
over 4 years ago
docker pull shamelesscookie/nginx-rtmp-ffmpeg