Changes between Version 4 and Version 5 of ffserver


Ignore:
Timestamp:
Oct 11, 2012, 4:07:33 PM (7 years ago)
Author:
burek
Comment:

Multiple changes, difficult to summarize in one line

Legend:

Unmodified
Added
Removed
Modified
  • ffserver

    v4 v5  
    11= Introduction =
    22
    3 If you need to [http://en.wikipedia.org/wiki/Streaming_media stream your audio/video content over the internet], you'll usually need [http://en.wikipedia.org/wiki/List_of_streaming_media_systems#Servers a streaming (broadcasting) server], one of which is '''[http://ffmpeg.org/ffserver.html ffserver]'''. It is able to collect multiple input sources ('''feeds''') and transcode/remux/broadcast each of them using multiple outputs ('''streams'''). To better describe its possibilities, consider the following image:
     3If you need to [http://en.wikipedia.org/wiki/Streaming_media stream your audio/video content over the internet], you'll usually need [http://en.wikipedia.org/wiki/List_of_streaming_media_systems#Servers a streaming (broadcasting) server], one of which is '''[http://ffmpeg.org/ffserver.html ffserver]'''. It is able to collect multiple input sources (usually ffmpeg applications) and transcode/remux/broadcast each of them using multiple output streams. The simple diagram is shown on the image below:
     4
     5[[Image(ffserver_map.png)]]
     6
     7Various input sources (ffmpeg applications) can be used to "feed" the broadcasting server (ffserver) with multimedia content that will be distributed to multiple clients for viewing. The purpose of the above image is to visually show the ability to separate parts of your streaming system into pieces that can be deployed around the world, allowing you to broadcast various live events without the need to change the structure of your streaming media system.
     8
     9Let's take a closer look of ffserver, to better describe its possibilities. Consider the following image:
    410
    511[[Image(ffserver.png)]]
     
    1521These elements are not part of internal structure of ffserver tool, but rather represent external applications (usually ffmpeg), which can send audio/video streams to ffserver that will be distributed (broadcast) to all the viewers (media players). Since ffmpeg is mostly used as an input source, we'll describe it here in this document.
    1622
    17 Input sources will connect to ffserver and connect with one or more feeds if those feeds are not connected with some other input source at that moment. On the image you can see that input source I1 is connected to only one feed F1, but input source I2 is connected with two feeds (F2 and F3) sending streams to both of them.
     23Input sources will connect to ffserver and bind themselves with one or more feeds if those feeds are not bound with some other input source at that moment. Binding one input source to multiple feeds is possible and makes sense only if the input source can produce different stream input for each feed it is bound to. It's useless for the input source to provide the same stream input to several feeds, since ffserver already has got a way of associating a single feed to multiple output streams.
    1824
    1925=== Feeds ===
    2026
    21 Feed element is an internal part of ffserver which has a purpose to connect one input source with one or more output streams. The possibility to connect a feed with more output streams is useful when you want to stream one input source (for example, your webcam with audio) using several different output formats (for example, streaming a full HD video and a small-size preview video for mobile phones) at the same time. Shortly speaking, each feed element logically represents each of your input sources. It can be considered as an "input jack" of ffserver, to which you connect your audio/video sources.
     27Feed element is an internal part of ffserver which has a purpose to associate one input source with one or more output streams. The possibility to associate a feed with more output streams is useful when you want to stream one input source (for example, your webcam with audio) using several different output formats (for example, streaming a full HD video and a small-size preview video for mobile phones) at the same time. Shortly speaking, each feed element logically represents each of your input sources. It can be considered as an "input jack" of ffserver, to which you connect your audio/video sources.
    2228
    2329=== Streams ===
    2430
    25 A stream element is internal part of ffserver and represents a connection point for all your viewers who wish to get a specific stream. For example, if you want to stream one full HD video and a small-size preview video for mobile phones, you will create two stream elements with different frame size and possibly different encoding and/or output format. Each stream element can handle multiple connecting clients, just like one web server can handle multiple web clients. It can be considered as an "output jack" of ffserver, to which your viewers can connect to view your audio/video stream. The obvious difference between a feed element and a stream element is that a single stream element can handle multiple connections with viewers, while a single feed element is always connected to only one input source.
     31A stream element is internal part of ffserver and represents a connection point for all your viewers who wish to get a specific stream. For example, if you want to stream one full HD video and a small-size preview video for mobile phones, you will create one feed element (to connect your input to) and associate it with two stream elements (which will define different frame size, encoding type and/or output format). Each stream element can handle multiple connecting clients, just like one web server can handle multiple web clients. It can be considered as an "output jack" of ffserver, to which your viewers (media players) can connect to view your audio/video stream. The obvious difference between a feed element and a stream element (between input/output jack) is that a single stream element can handle multiple connections with viewers, while a single feed element is always connected to only one input source.
    2632
    2733=== Media players ===
    2834
    29 Media player elements are not internal part of ffserver. They represent your viewers from the "outside world" that are connecting to the stream elements to view your multimedia content. Some of the popular media players are: [http://ffmpeg.org/ffplay.html ffplay], [http://www.videolan.org/vlc/index.html VLC] or [http://windows.microsoft.com/en-US/windows/products/windows-media-player Windows Media Player].
     35Media player elements are not internal part of ffserver. They just represent your viewers from the "outside world" that are connecting to the various stream elements to view your multimedia content. Some of the popular media players are: [http://ffmpeg.org/ffplay.html ffplay], [http://www.videolan.org/vlc/index.html VLC], [http://www.winamp.com Winamp], [http://windows.microsoft.com/en-US/windows/products/windows-media-player Windows Media Player], etc.
    3036
    3137= Running ffserver =
    3238
    33 To be able to successfully start ffserver, you'll need the valid [http://ffmpeg.org/sample.html configuration file] first. Once you create a config file, you can start ffserver simply by running the following command:
     39To be able to successfully start ffserver, you'll need a valid [http://ffmpeg.org/sample.html configuration file] first. Once you create a valid config file, you can start ffserver simply by running the following command:
    3440{{{
    3541ffserver -f /etc/ffserver.conf
    3642}}}
    3743
    38 Depending on your configuration file, your ffserver will start or not :) But more often it will not start until you debug all the issues that usually occur, including syntax errors, so you'll most probably want to run your ffserver in debug mode with "-d" option, like this:
     44Depending on your configuration file, your ffserver will start or not :) But more often it will not start until you debug all the issues that usually occur, including syntax errors, so you'll most probably want to run your ffserver in debug mode with "-d" option, until you sort out everything, like this:
    3945{{{
    4046ffserver -d -f /etc/ffserver.conf
     
    4652}}}
    4753
    48 When you finally build a valid configuration file, you'll want to run your ffserver in the background (as a daemon), which can be accomplished using either a trailing ampersand character in a shell command or more conveniently you can comment out "`NoDaemon`" directive inside your config file (works on Windows too).
     54When you finally build a valid configuration file, you'll want to run your ffserver in the background (as a daemon), which can be accomplished using either a trailing ampersand character (&) in a shell command or more conveniently you can comment out "`NoDaemon`" directive inside your config file (works on Windows too).
    4955
    5056= Connecting your input sources =
    5157
    52 Once your ffserver is up and running, it's time to connect input sources to it. Without input sources, your ffserver is not going to broadcast anything to the outside world and will be perfectly useless. So, let's see how we can connect a couple of input sources to ffserver.
    53 
    54 The simplest way is to use ffmpeg tool. Let's assume that we want to stream our webcam video together with audio to our friends. We will simply run an ffmpeg command line that will capture our webcam video and audio input and forward it to ffserver. The command will look something like this:
     58Once your ffserver is up and running, it's time to connect input sources to it. Without input sources, your ffserver is not going to broadcast anything to the outside world and will be pretty much useless. So, let's see how we can connect input sources to ffserver. The simplest way is to use the ffmpeg tool and the general syntax for such command is:
     59{{{
     60ffmpeg <inputs> <feed URL>
     61}}}
     62
     63Of course, if you want to use one input source (ffmpeg) and bind it to multiple feeds (if you like to have only one application started), you might use:
     64{{{
     65ffmpeg <inputs> <feed URL> <more inputs> <another feed URL> <even more inputs> <yet another feed URL>
     66}}}
     67but, keep in mind that, if that input source crashes, all its bound feeds will become unavailable. So it's a good practice to use one input source (ffmpeg) pear each feed (1-1).
     68
     69The parameter "{{{<feed URL>}}}" has got the following form:
     70{{{
     71http://<ffserver_ip_address_or_host_name>:<ffserver_port>/<feed_name>
     72}}}
     73
     74All these things are defined in your ffserver configuration file:
     75- '''{{{<ffserver_ip_address_or_host_name>}}}''' - using the "{{{BindAddress}}}" directive
     76- '''{{{<ffserver_port>}}}''' - using the "{{{Port}}}" directive
     77- '''{{{<feed_name>}}}''' - using the "{{{<Feed>}}}" block
     78
     79Let's assume that we want to stream our webcam video + audio to our friends. We will simply run an ffmpeg command line that will capture our webcam video and audio input and forward it to ffserver. The command line will look something like this:
    5580{{{
    5681ffmpeg \
     
    6590but it looks better and makes it more clear to understand each part of the command line.
    6691
    67 The first part "'''{{{-f v4l2 -s 320x240 -r 25 -i /dev/video0}}}'''" captures our webcam input. For more info, you can read more about [[How to capture a webcam input]].
    68 The second part "'''{{{-f alsa -ac 1 -i hw:0}}}'''" captures our audio input, depending on our audio configuration. For more info, you can read more about [[Capturing audio with FFmpeg and ALSA]].
    69 The last, but not the least important, part is "'''{{{http://localhost:8090/feed1.ffm}}}'''", which tells ffmpeg to connect to the ffserver and send the audio+video streams to be broadcast. Make sure that your feed ends with ".ffm" and if it's not the case, then prepend "-f ffm" before your url, to manually specify the output format (because ffmpeg won't be able to figure it out automatically any more), like this "'''{{{-f ffm http://localhost:8090/blah.bleh}}}'''".
    70 
    71 As soon as you type that command, you should see ffmpeg displaying some statistics about your input streams and counting output frames, which is a pretty good sign that everything works (so far).
     92* The first part "'''{{{-f v4l2 -s 320x240 -r 25 -i /dev/video0}}}'''" represents the first input for ffmpeg and captures our webcam video. For more info, you can read more about [[How to capture a webcam input]].
     93* The second part "'''{{{-f alsa -ac 1 -i hw:0}}}'''" represents the second input for ffmpeg and captures our audio, depending on our system audio configuration. For more info, you can read more about [[Capturing audio with FFmpeg and ALSA]].
     94* The last, but not the least important, part "'''{{{http://localhost:8090/feed1.ffm}}}'''" represents the feed URL, which tells ffmpeg to connect to ffserver and send it the audio + video streams for broadcast. Make sure that your feed ends with "{{{.ffm}}}" and if it's not the case, then add "{{{-f ffm}}}" before your feed URL, to manually specify the output format (because ffmpeg won't be able to figure it out automatically any more), like this "'''{{{-f ffm http://localhost:8090/blah.bleh}}}'''".
     95
     96As soon as you type the command above, you should see ffmpeg displaying some statistics about your input streams and counting output frames, which is a pretty good sign that everything works (so far).
     97
     98For this example, you would need at least the following things defined in your config file (three dots "..." represent the other data that is irrelevant for this topic):
     99{{{
     100Port 8090
     101BindAddress 0.0.0.0
     102
     103...
     104
     105<Feed feed1.ffm>
     106
     107        ...
     108
     109</Feed>
     110
     111...
     112
     113}}}
    72114
    73115= Viewing your streams =
    74116
    75 If you've done all the steps so far without errors, you're now ready to view your streams. The simplest way to do so is to use ffplay to connect to ffserver and view a specific stream, for example, like this:
     117If you've done all the steps so far without errors, you're now ready to view your streams. The simplest way to do so is to use ffplay to connect to ffserver and view a specific stream. The general syntax for such command is:
     118{{{
     119ffplay <stream URL>
     120}}}
     121
     122The parameter "{{{<stream URL>}}}" has got the following form:
     123{{{
     124http://<ffserver_ip_address_or_host_name>:<ffserver_port>/<stream_name>
     125}}}
     126
     127All these things are defined in your ffserver configuration file:
     128- '''{{{<ffserver_ip_address_or_host_name>}}}''' - using the "{{{BindAddress}}}" directive
     129- '''{{{<ffserver_port>}}}''' - using the "{{{Port}}}" directive
     130- '''{{{<stream_name>}}}''' - using the "{{{<Stream>}}}" block
     131
     132For example if you have appropriate stream element defined in your ffserver configuration file, you could type:
    76133{{{
    77134ffplay http://localhost:8090/test1.mpg
    78135}}}
    79 
    80 Your stream should appear (depending on the encoding used and caching enforced) relatively shortly in a matter of seconds.
     136and your stream should appear (depending on the encoding used and caching enforced) relatively shortly in a matter of seconds.
     137
     138For this example, you would need at least the following things defined in your config file (three dots "..." represent the other data that is irrelevant for this topic):
     139{{{
     140Port 8090
     141BindAddress 0.0.0.0
     142
     143...
     144
     145<Stream test1.mpg>
     146
     147        ...
     148
     149</Stream>
     150
     151...
     152
     153}}}
     154
    81155
    82156= Creating the configuration file =