Introduction
FFmpeg is a free, open-source multimedia framework used for recording, converting, and streaming audio and video. It supports a wide range of formats and codecs, making it a versatile tool for media processing. With its command-line interface, FFmpeg enables tasks such as video encoding, format conversion, and real-time streaming over various protocols, including RTMP, HLS, and MPEG-DASH.
Create a CDN service for live streaming
You have the following two options. Create a CDN HTTP Live service or create a CDN Live service.
Create a CDN HTTP Live service with RTMP Push Publishing Point
Assume that your CDN HTTP Live service has the following properties. Please refer to Services/How-To.
- Server URL - rtmp://push-1.cdnsun.com/p12345
Create a CDN Live service with Push Publishing
Assume that your CDN Live service has the following properties. Please refer to Services/How-To.
- Server URL - rtmp://12345.publishstream.cdnsun.net/P12345
- Username - P12345
- Password - Kmx7s14We
Publish video stream to the CDN using FFmpeg
Streaming a video file as if it were a live stream
Assume that you have a video file myvideo.mp4 encoded with H.264 video codec and AAC or MP3 audio codec (please refer to Services/How-To for all requirements). With FFmpeg you can stream the video file through the CDN as if it were an output from live encoder.
CDN HTTP Live service
ffmpeg -re -i ./myvideo.mp4 -acodec copy -vcodec copy -f flv "rtmp://push-1.cdnsun.com/p12345/mystream live=1"
CDN Live service
ffmpeg -re -i ./myvideo.mp4 -acodec copy -vcodec copy -f flv "rtmp://P12345:Kmx7s14We@12345.publishstream.cdnsun.net/P12345/mystream live=1"
Accessing your CDN video stream
The above command will stream your video file myvideo.mp4 through your CDN HTTP Live (resp. CDN Live) service using mystream as the stream name. The resulting CDN stream will be accessible via the following URLs, assuming cdn.mycompany.com is the Service Domain of your CDN service.
CDN HTTP Live service
- HLS - https://cdn.mycompany.com/mystream/playlist.m3u8
CDN Live service
- RTMP - rtmp://cdn.mycompany.com/mystream
- HLS - https://cdn.mycompany.com/12345/_definst_/mystream/playlist.m3u8
Enabling authentication support in FFmpeg for CDN Live service
Please note that in the case of CDN Live service it is required that your FFmpeg supports authentication. Notice the username and password in the above publishing RTMP URL. The same type of authentication is used by OBS. Please note that it is not possible to disable authentication on our CDN Live services.
How can I verify that my FFmpeg supports authentication?
Run the above command FFmpeg command but add -loglevel debug just after ffmpeg. If you will see similar output as below then your FFmpeg does not support authentication.
Parsing... Parsed protocol: 0 Parsed host : P12345 Parsed app : P12345 RTMP_Connect0, failed to connect socket. 111 (Connection refused)
Please note that P12345 above corresponds to the username of your CDN Live service. If your FFmpeg supports authentication then you will see output similar to the following.
Parsing a group of options: output file rtmp://P12345:Kmx7s14We@12345.publishstream.cdnsun.net/P12345/mystream live=1. Applying option acodec (force audio codec ('copy' to copy stream)) with argument copy. Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy. Applying option f (force format) with argument flv. Successfully parsed a group of options. Opening an output file: rtmp://P12345:Kmx7s14We@12345.publishstream.cdnsun.net/P12345/mystream live=1
How can I enable authentication support in FFmpeg?
You need to compile FFmpeg without librtmp.
git clone --depth 1 git://source.ffmpeg.org/ffmpeg cd ffmpeg ./configure --enable-gpl --enable-libmp3lame --enable-libopencore-amrnb \ --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis \ --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 make
Please note that --enable-librtmp is missing in the above configure options.
What next?
Read about the following topics.