https://ffmpeg.org/ffserver.html#FFM
ffserver
receives prerecorded files or FFM streams from some
ffmpeg
instance as input, then streams them over RTP/RTSP/HTTP.
ffserver能读取本地文件或者
ffmpeg实例输出的FFM流
,然后把他们通过RTP/RTSP/HTTP的方式分发出去。
Input streams are called
feeds
, and each one is specified by a
<Feed>
section in the configuration file. 输入流被称作feed
For each feed you can have different output streams in various formats, each one specified by a
<Stream>
section in the configuration file.
每个feed输入可以有多个不同的输出,
由<Stream>标识输出
ffserver
acts as an HTTP server, accepting POST requests from
ffmpeg
to acquire the stream to publish, and serving RTSP clients or HTTP clients GET requests with the stream media content.
ffserver像一个HTTP服务器一样,它接收来自ffmpeg的POST请求,然后把多媒体数据分发给HTTP/RTSP客户端
每个feed的名字各不相同
ffmpeg通过
-f ffm http://
ffserver_ip_address
:
http_port
/
feed_name
-override_ffserver 来推送流
ffserver通过 配置
<Feed
feed_name
>
<File> /file/path/corresponding/to/feed/feed_name
</Feed>
来接收对应的流
Each feed is associated to a file which is stored on disk. This stored file is used to send pre-recorded data to a player as fast as possible when new content is added in real-time to the stream.
每个feed都和一个本地文件相关联
。
A "live-stream" or "stream" is a resource published by
ffserver
, and made accessible through the HTTP protocol to clients.
通过ffserver发布出去的流叫做
live-stream 或者 stream
A stream can be connected to a feed, or to a file. In the first case, the published stream is forwarded from the corresponding feed generated by a running instance of
ffmpeg
, in the second case the stream is read from a pre-recorded file.
一个流可以连接到一个feed上或者一个文件上。 feed是由ffmpeg产生的。
Each stream is identified by a unique name, corresponding to the name of the resource served by
ffserver
, and is configured by a dedicated
Stream
section in the configuration file.
一个流对应ffserver提供的一个资源,
由<Stream>标识
客户端
通过
http://ffserver_ip_address:http_port/stream_name[options]
来获取流内容
stream_name就是ffserver配置文件里的<Stream>字段
In case the stream is associated to a feed, the encoding parameters must be configured in the stream configuration.
They are sent to
ffmpeg
when setting up the encoding. This allows
ffserver
to define the encoding parameters used by the
ffmpeg
encoders.
如果stream(ffserver的输出)是和feed(ffmpeg的输入)关联的, 那么可以在配置文件中指定编码参数,
这些参数被ffserver发送给ffmpeg,ffmpeg使用这些编码参数进行编码
。
The
ffmpeg
override_ffserver
commandline option allows one to override the encoding parameters set by the server.
ffmpeg通过
override_ffserver
的命令行选项来忽略ffserver发过来的参数配置。
Multiple streams can be connected to the same feed.
ffserver可以为ffmpeg产生的同一路feed产生多路output streams
.
FFM and FFM2
are formats used by
ffserver
. They allow storing a wide variety of video and audio streams and encoding options, and can store a moving time segment of an infinite movie or a whole movie.
为了不同版本ffmpeg, ffserver的更好的兼容性,推荐使用FFM2
ffserver
supports an HTTP interface which exposes the current status of the server.
<Stream status.html>
</Stream>
status.html也是ffserver提供的一个stream
播放体验优化
* When you connect to a live stream, most players (WMP, RA, etc) want to buffer a certain number of seconds of material so that they can display the signal continuously.
However, ffserver (by default) starts sending data in realtime.
This means that there is a pause of a few seconds while the buffering is being done by the player.
很多播放器播放时会缓存,但ffserver是发送实时数据的。所以会造成延时。
两种解决办法:
URL后面追加?buffer=5 (针对指定请求)
ffserver配置文件中打开Prefoll 15配置(针对所有请求)
The good news is that this can be cured by adding a ’?buffer=5’ to the end of the URL. This means that the stream should start 5 seconds in the past – and so the first 5 seconds of the stream are sent as fast as the network will allow. It will then slow down to real time. This noticeably improves the startup experience. 意思是发送之前5秒的数据
You can also add a ’Preroll 15’ statement into the ffserver.conf that will add the 15 second prebuffering on all requests that do not otherwise specify a time. In addition, ffserver will skip frames until a key_frame is found. This further reduces the startup delay by not transferring data that will be discarded.
==========================================
<Feed feed1.ffm>
1. ffmpeg,负责媒体文件的编码和传输工作,把视频源转换成要发送出去的流媒体
2. ffserver,负责响应客户端的流媒体请求,把流媒体数据发送给客户端
3. ffserver.conf,ffserver启动时的配置文件,在这个文件中主要是对网络协议,缓存文件feed1.ffm(见下述)和要发送的流媒体文件的格式参数做具体的设定。
4. feed1.ffm,可以看成是一个流媒体数据的缓存文件,ffmpeg把转码好的数据发送给ffserver,
如果没有客户端连接请求,ffserver把数据缓存到该文件中
。
ffmpeg启动后会与 ffserver建立一个连接(短暂的连接),通过这第一次的连接,ffmpeg从ffserver那里获取输出流的配置,并把这些配置作为自己编码参数配置,然后ffmpeg断开了这次连接,再次与ffserver建立连接(长久的连接),利用这个连接ffmpeg会把编码后的数据发送给 ffserver
。
如果你观察ffserver端的输出就会发现这段时间会出现两次HTTP的200,这就是两次连接的过程。
ffserver收到ffmpeg的数据后,如果网络上没有播放的请求,就把数据写入feed1.ffm中缓存,写入时把数据加上些头信息然后分块,每块4096B(每块也有结构),当feed1.ffm的大 小到了ffserver.conf中规定的大小后,就会从文件开始(跳过头)写入,覆盖旧的数据。直到网络上有播放的请求,ffserver从 feed1.ffm中读取数据,发送给客户端
。