Play with ffserver – a quick overview

ffmpegEverybody knows ffmpeg the command line encoding tool but do you know ffserver ? ffserver is a multimedia streaming server for live broadcasts. With it, you can stream over HTTP, RTP and RSTP.

Quick overview

The concept is to use ffmpeg to push content to one server. This server will transcode streams and deliver to the end-users.

FFServer map

Input streams are called feed and for each feed you can have multiple output stream.

We can manage ffserver via a configuration file. The syntax is close to the one used for Apache server. You can find a example here. And there are more informations in the ffserver wiki.

We will see two examples on how to deliver content via a ffserver. There will be a FLV and a WebM stream.

Stream FLV

In this example, we will have one input stream and two output : one in FLV and one WebM.

Here are the general configuration settings

Port 8090
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -

We define a status page.

<Stream stat.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>

This page will help us to monitor the server. This page is call with this url : http://localhost:8090/stat.html and you will get this page :

ffserver-status

Now we set up the feed : storage area, max size and allowed referrers. Remember, feeds are the input of the ffserver.

<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 1G
ACL allow 127.0.0.1
</Feed>

Ok, our configuration file have now a input feed. Now, we will add the first output : the FLV one. The video will be encoded in H264 for video and AAC for audio. This part is divided in 3 part :

  • general settings : which feed is used and output format
  • settings for video
  • settings for audio
<Stream live.flv>
Format flv
Feed feed1.ffm

VideoCodec libx264
VideoFrameRate 30
VideoBitRate 800
VideoSize 720x576
AVOptionVideo crf 23
AVOptionVideo preset medium
AVOptionVideo me_range 16
AVOptionVideo qdiff 4
AVOptionVideo qmin 10
AVOptionVideo qmax 51
AVOptionVideo flags +global_header

AudioCodec aac
Strict -2
AudioBitRate 128
AudioChannels 2
AudioSampleRate 44100
AVOptionAudio flags +global_header
</Stream>

The first part of our server is now configured and saved in a ffserver.conf file. We can test it. Launch the server with this command line :

ffserver -f ffserver.conf

You will have this output :

 ffserver version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Jun 24 2013 10:41:49 with Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libtheora --enable-libschroedinger --enable-libopenjpeg --enable-libmodplug --enable-libvpx --enable-libspeex --enable-libass --enable-libbluray --enable-gnutls --enable-libfreetype --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/clang --arch=x86_64 --enable-yasm --enable-gpl --enable-postproc --enable-libx264 --enable-libxvid --enable-nonfree --enable-libfaac
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Wed Jul 3 14:02:01 2013 FFserver started.

Your server is now up and running. We can push our first movie, in my case, I use the Sintel Movie trailer. The ffmpeg command line read the video and push it to the feed we configured above.
ffmpeg -i sintel.mp4 http://localhost:8090/feed1.ffm[/code]
Now you can launch your preferred player (in my case VLC) and try to stream the content : http://localhost:8090/live.flv 😉

Stream WebM

Ok we have now one FLV output stream. We will replace FLV stream by one new output : WebM (with Vorbis and VP6). We will re-used the ffserver.conf file and put this part :

<Stream live.webm>
Feed feed1.ffm
Format webm

AudioCodec vorbis
AudioBitRate 64

VideoCodec libvpx
VideoSize 720x576
VideoFrameRate 25
AVOptionVideo flags +global_header
AVOptionVideo cpu-used 0
AVOptionVideo qmin 10
AVOptionVideo qmax 42
AVOptionVideo quality good
AVOptionAudio flags +global_header
PreRoll 15
StartSendOnKey
VideoBitRate 400
</Stream>

Restart the server and push again the content. You can test the movie on Chrome or VLC with this url : http://localhost:8090/live.webm

Note: with WebM, you can create a kind of live stream if you loop on different ffmpeg command line.

To conclude, we know ffmpeg as one of the most useful free encoder. Now, ffserver is a very interesting tool and deserve more time to test the different possibility of it.
Have fun with it ! 😉

6 thoughts on “Play with ffserver – a quick overview

      1. zebeubeul

        Hi
        The link you gave is not related to ffserver ! I still was wondering if ffserver can archieve HLS. Did you experiment it deeper ?
        Thank you.
        Zbb

    1. Olivier Post author

      Hello,
      All depends the output format, but with Webm I think you can. Ffmpeg takes as input multiple input live format : RTMP, TS…
      Hope that helps you

      Reply
  1. Manish Gautam

    Hi,

    I am getting below mentioned error when trying to stream
    root@udoo-debian-hfp:/usr/sbin# webcam.sh
    ffserver version N-69146-g90c9899 Copyright (c) 2000-2015 the FFmpeg developers
    built on Jan 19 2015 08:10:57 with gcc 4.8 (Debian 4.8.2-16)
    configuration:
    libavutil 54. 17.100 / 54. 17.100
    libavcodec 56. 20.100 / 56. 20.100
    libavformat 56. 19.100 / 56. 19.100
    libavdevice 56. 4.100 / 56. 4.100
    libavfilter 5. 8.100 / 5. 8.100
    libswscale 3. 1.101 / 3. 1.101
    libswresample 1. 1.100 / 1. 1.100
    /etc/ffserver.conf:1: Port option is deprecated. Use HTTPPort instead.
    /etc/ffserver.conf:2: BindAddress option is deprecated. Use HTTPBindAddress instead.
    /etc/ffserver.conf:7: NoDaemon option has no effect. You should remove it.
    ffmpeg version N-69146-g90c9899 Copyright (c) 2000-2015 the FFmpeg developers
    built on Jan 19 2015 08:10:57 with gcc 4.8 (Debian 4.8.2-16)
    configuration:
    libavutil 54. 17.100 / 54. 17.100
    libavcodec 56. 20.100 / 56. 20.100
    libavformat 56. 19.100 / 56. 19.100
    libavdevice 56. 4.100 / 56. 4.100
    libavfilter 5. 8.100 / 5. 8.100
    libswscale 3. 1.101 / 3. 1.101
    libswresample 1. 1.100 / 1. 1.100
    /etc/ffserver.conf:25: Setting default value for video bit rate tolerance = 500000. Use NoDefaults to disable it.
    /etc/ffserver.conf:25: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
    /etc/ffserver.conf:25: Setting default value for video max rate = 4000000. Use NoDefaults to disable it.
    /etc/ffserver.conf:25: Setting default value for video buffer size = 4000000. Use NoDefaults to disable it.
    Thu Feb 12 09:54:58 2015 FFserver started.
    [video4linux2,v4l2 @ 0xeaa450] fd:3 capabilities:4000001
    Input #0, video4linux2,v4l2, from ‘/dev/video3’:
    Duration: N/A, start: 10148.497934, bitrate: 24576 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640×480, 24576 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc
    http://localhost:8090/webcam.ffm: Address family not supported by protocol

    Can you help we with this error?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.