FFMPEG Sources
When using ffmpeg, be sure to use the zerolatency option to get real-time output. This is not set automatically. Without the zerolatency setting the encoder will introduce 0.5 seconds of end-to-end latency out of the gate. Please refer to the ffmpeg documentation for details.
An example ffmpeg command to create test content is:
ffmpeg -re -f lavfi -i testsrc=size=1280x720:rate=30 -f lavfi -i aevalsrc="0.1*sin(2*PI*(360-2.5/2)*t) | 0.1*sin(2*PI*(360+2.5/2)*t)" -pix_fmt yuv420p -vcodec libx264 -profile:v baseline -deblock 1:0 -bitrate 500k -tune zerolatency -flags low_delay -fflags '+nobuffer+flush_packets' -max_delay 0 -muxdelay 0 -x264opts keyint=30 -acodec aac -ar 48000 -ac 2 -b:a 128k -f flv rtmp://ingest.phenixrts.com:80/ingest/96characterStreamKey;capabilities=hd,multi-bitrate,mpegts-unicast-ingest;tags=my-awesome-stream-id
Where 96characterStreamKey
is the stream key to be used when publishing, which can be found in the Customer Portal under the Properties tab for a Channel or Room.
On MacOS and Linux, you may need to add quotation marks around the second argument in order to not lose information after the semicolon:
"rtmp://ingest.phenixrts.com:80/ingest/96characterStreamKey;capabilities=hd,multi-bitrate,mpegts-unicast-ingest;tags=my-awesome-stream-id"
To measure latency, add a timestamp overlay:
ffmpeg -re -f lavfi -i testsrc=size=1280x720:rate=30 -f lavfi -i aevalsrc="0.1*sin(2*PI*(360-2.5/2)*t) | 0.1*sin(2*PI*(360+2.5/2)*t)" -pix_fmt yuv420p
-vf "drawtext=text='timestamp: %{pts \: hms}': x=20: y=20: fontsize=72:fontcolor=white@0.9: box=1: boxcolor=black@0.6"
-vcodec libx264 -profile:v baseline -deblock 1:0 -bitrate 500k -tune zerolatency -flags low_delay -fflags '+nobuffer+flush_packets' -max_delay 0 -muxdelay 0 -x264opts keyint=30 -acodec aac -ar 48000 -ac 2 -b:a 128k -f flv rtmp://ingest.phenixrts.com:80/ingest/96characterStreamKey;capabilities=hd,multi-bitrate,mpegts-unicast-ingest;tags=my-awesome-stream-id
Where 96characterStreamKey
is the stream key to be used when publishing, which can be found in the Customer Portal under the Properties tab for a Channel or Room.
An example of the resulting video stream in the Portal's Details page is shown below.
Optimization
FFmpeg commands may need to be optimized for real-time streaming at different levels depending on the use case:
- input protocol and device
- output protocol and device
- muxing / demuxing
- encoding
General
In general, when using FFMPEG with Phenix, always:
- Include these flags:
flags low_delay
fflags '+nobuffer+flush_packets'
- Encode for real-time: 1s GoP interval, or at least less than 2s.
- Enforce the lowest muxing and demuxing delays, as a result, packets at the end of the chain
are better ordered for real-time, e.g., V V A V V V A V V A ...
instead of V V V V V V V A A A V V V V V ... which reduces the playout delay. To do this, use:
max_delay 0
muxdelay 0
Input-Specific
Depending on the input, reduce the probing overhead. e.g.,
fpsprobesize 1
analyzeduration 0
Encoder-Specific
Apply optimization specific to the encoder. For example, optimizations and configurations differ between libx264 and h264_nvenc. Contact Phenix for details.
Ingest and Output Protocols
Additional optimizations depend on the input and output protocols.
For example, when using an RTSP input, the arguments -reorder_queue_size 1
and
-buffer_size 0
can be included.