Follow this guide to configure FFmpeg as a live video encoder and stream directly to your Primcast video server over RTMP. All configuration is done via command line.
Each step explains one part of the FFmpeg command. All values shown in UPPERCASE must be replaced with the correct details from your Primcast account.
This is the complete example command. Copy it and replace the placeholders with your account details. The sections below explain each flag.
ffmpeg -i 'FILE or LINK' \ -crf 30 -preset ultrafast \ -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k \ -vcodec libx264 -r 25 -b:v 300k \ -f flv \ 'rtmp://USERNAME:PASSWORD@STREAMING_ADDRESS:1935/APPLICATION_NAME/livestream'
-i)The -i flag tells FFmpeg where to pull the input stream from. It can be a file, a capture device, or another stream:
-i video="screen-capture-recorder":audio="Stereo Mix (IDT High Definition)"-i '/home/user/sample.mp4'-i 'udp://127.0.0.0:1000/'These flags control how the video is encoded:
-crf 30 - Sets the Constant Rate Factor. Keeps reasonably consistent video quality while varying bitrate during complex scenes. A value of 30 allows somewhat lower quality and bitrate.-preset ultrafast - Provides the fastest possible encoding speed.-vcodec libx264 - Sets the video codec to H.264.-r 25 - Sets the frame rate to 25 fps.-b:v 300k - Sets the video bitrate to 300 kbps.These flags control how the audio is encoded:
-acodec aac - Sets the audio codec to AAC (internal AAC encoder).-strict experimental - Allows use of experimental codecs. Required because the internal AAC encoder is experimental.-ar 44100 - Sets the audio sample rate to 44,100 Hz.-ac 2 - Specifies two channels of audio (stereo).-b:a 96k - Sets the audio bitrate to 96 kbps.-f flv wraps the output stream in an FLV container, which is required for RTMP.
The final argument is the RTMP destination URL. Replace each placeholder with your account details:
rtmp://USERNAME:PASSWORD@STREAMING_ADDRESS:1935/APPLICATION_NAME/livestream
USERNAME and PASSWORD with the credentials from your Primcast account.STREAMING_ADDRESS with the streaming address from your account dashboard (e.g. test.primcast.com).APPLICATION_NAME with the application name shown on your dashboard.Once streaming, you can view the output via the HLS link in a player like VLC, or embed it using the Generate Player link in your dashboard.
Common questions about using FFmpeg for live video streaming with Primcast.