FFmpeg CDN integration

Create a CDN Live service with Push Publishing

  1. Please refer to Creating a CDN Live service for more details.
  2. Let's assume that your CDN Live service has the following properties (please refer to Services/How-To).
    • FMS URL - rtmp://217921468.publishstream.cdnsun.net/P217921468
    • Username - P217921468
    • Password - Kmx7s14We

Enable CDN Live service in FFmpeg

Streaming a video file as if it were a live stream

Let's 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 CDN Live service as if it were an output from live encoder.

ffmpeg -re -i ./myvideo.mp4 -acodec copy -vcodec copy -f flv "rtmp://P217921468:Kmx7s14We@217921468.publishstream.cdnsun.net/P217921468/mystream live=1"

The above command will stream your video file myvideo.mp4 through your CDN Live service using mystream as a stream name. In particular the resulting live CDN stream will be accessible on the following CDN URLs.

  • RTMP - rtmp://217921468.r.cdnsun.net/mystream
  • HLS - http://217921468.r.cdnsun.net/mystream/playlist.m3u8

Please refer to Services/How-To for a full list of all supported protocols.

FFmpeg with authentication support

Please note that 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 Adobe Flash Media Live Encoder. 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.

Parsed protocol: 0
Parsed host    : P217921468
Parsed app     : P217921468
RTMP_Connect0, failed to connect socket. 111 (Connection refused)      

Please note that P217921468 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://P217921468:Kmx7s14We@217921468.publishstream.cdnsun.net/P217921468/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://P217921468:Kmx7s14We@217921468.publishstream.cdnsun.net/P217921468/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-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
--enable-libopencore-amrwb --enable-libtheora --enable-libvorbis \
--enable-libvpx --enable-libx264 --enable-nonfree --enable-version3

Please note that --enable-librtmp is missing in the above configure options.

Useful links

Contact Us

 _    _    __   __   _    _   
| |  | ||  \ \\/ // | || | || 
| |/\| ||   \ ` //  | || | || 
|  /\  ||    | ||   | \\_/ || 
|_// \_||    |_||    \____//  
`-`   `-`    `-`'     `---`