protocols.texi 13.8 KB
Newer Older
Stefano Sabatini's avatar
Stefano Sabatini committed
1 2 3
@chapter Protocols
@c man begin PROTOCOLS

4
Protocols are configured elements in FFmpeg which allow to access
Stefano Sabatini's avatar
Stefano Sabatini committed
5 6
resources which require the use of a particular protocol.

7
When you configure your FFmpeg build, all the supported protocols are
8 9
enabled by default. You can list all available ones using the
configure option "--list-protocols".
Stefano Sabatini's avatar
Stefano Sabatini committed
10 11 12 13 14 15 16 17

You can disable all the protocols using the configure option
"--disable-protocols", and selectively enable a protocol using the
option "--enable-protocol=@var{PROTOCOL}", or you can disable a
particular protocol using the option
"--disable-protocol=@var{PROTOCOL}".

The option "-protocols" of the ff* tools will display the list of
18
supported protocols.
Stefano Sabatini's avatar
Stefano Sabatini committed
19 20 21

A description of the currently available protocols follows.

22 23 24 25 26 27
@section applehttp

Read Apple HTTP Live Streaming compliant segmented stream as
a uniform one. The M3U8 playlists describing the segments can be
remote HTTP resources or local files, accessed using the standard
file protocol.
28 29 30
HTTP is default, specific protocol can be declared by specifying
"+@var{proto}" after the applehttp URI scheme name, where @var{proto}
is either "file" or "http".
31 32 33 34 35 36 37

@example
applehttp://host/path/to/remote/resource.m3u8
applehttp+http://host/path/to/remote/resource.m3u8
applehttp+file://path/to/local/resource.m3u8
@end example

Stefano Sabatini's avatar
Stefano Sabatini committed
38 39 40 41
@section concat

Physical concatenation protocol.

42 43
Allow to read and seek from many resource in sequence as if they were
a unique resource.
Stefano Sabatini's avatar
Stefano Sabatini committed
44

45
A URL accepted by this protocol has the syntax:
Stefano Sabatini's avatar
Stefano Sabatini committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
@example
concat:@var{URL1}|@var{URL2}|...|@var{URLN}
@end example

where @var{URL1}, @var{URL2}, ..., @var{URLN} are the urls of the
resource to be concatenated, each one possibly specifying a distinct
protocol.

For example to read a sequence of files @file{split1.mpeg},
@file{split2.mpeg}, @file{split3.mpeg} with @file{ffplay} use the
command:
@example
ffplay concat:split1.mpeg\|split2.mpeg\|split3.mpeg
@end example

Note that you may need to escape the character "|" which is special for
many shells.

@section file

File access protocol.

Allow to read from or read to a file.

70
For example to read from a file @file{input.mpeg} with @command{ffmpeg}
Stefano Sabatini's avatar
Stefano Sabatini committed
71 72 73 74 75
use the command:
@example
ffmpeg -i file:input.mpeg output.mpeg
@end example

76 77 78
The ff* tools default to the file protocol, that is a resource
specified with the name "FILE.mpeg" is interpreted as the URL
"file:FILE.mpeg".
Stefano Sabatini's avatar
Stefano Sabatini committed
79 80 81 82 83 84 85

@section gopher

Gopher protocol.

@section http

86
HTTP (Hyper Text Transfer Protocol).
Stefano Sabatini's avatar
Stefano Sabatini committed
87 88 89 90 91

@section mmst

MMS (Microsoft Media Server) protocol over TCP.

92 93 94 95 96 97 98 99 100
@section mmsh

MMS (Microsoft Media Server) protocol over HTTP.

The required syntax is:
@example
mmsh://@var{server}[:@var{port}][/@var{app}][/@var{playpath}]
@end example

Stefano Sabatini's avatar
Stefano Sabatini committed
101 102 103 104
@section md5

MD5 output protocol.

105 106 107
Computes the MD5 hash of the data to be written, and on close writes
this to the designated output or stdout if none is specified. It can
be used to test muxers without writing an actual file.
Stefano Sabatini's avatar
Stefano Sabatini committed
108 109 110

Some examples follow.
@example
111
# Write the MD5 hash of the encoded AVI file to the file output.avi.md5.
Stefano Sabatini's avatar
Stefano Sabatini committed
112 113
ffmpeg -i input.flv -f avi -y md5:output.avi.md5

114
# Write the MD5 hash of the encoded AVI file to stdout.
Stefano Sabatini's avatar
Stefano Sabatini committed
115 116 117
ffmpeg -i input.flv -f avi -y md5:
@end example

118
Note that some formats (typically MOV) require the output protocol to
Stefano Sabatini's avatar
Stefano Sabatini committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132
be seekable, so they will fail with the MD5 output protocol.

@section pipe

UNIX pipe access protocol.

Allow to read and write from UNIX pipes.

The accepted syntax is:
@example
pipe:[@var{number}]
@end example

@var{number} is the number corresponding to the file descriptor of the
133 134 135
pipe (e.g. 0 for stdin, 1 for stdout, 2 for stderr).  If @var{number}
is not specified, by default the stdout file descriptor will be used
for writing, stdin for reading.
Stefano Sabatini's avatar
Stefano Sabatini committed
136

137
For example to read from stdin with @command{ffmpeg}:
Stefano Sabatini's avatar
Stefano Sabatini committed
138 139
@example
cat test.wav | ffmpeg -i pipe:0
140
# ...this is the same as...
Stefano Sabatini's avatar
Stefano Sabatini committed
141 142 143
cat test.wav | ffmpeg -i pipe:
@end example

144
For writing to stdout with @command{ffmpeg}:
Stefano Sabatini's avatar
Stefano Sabatini committed
145 146
@example
ffmpeg -i test.wav -f avi pipe:1 | cat > test.avi
147
# ...this is the same as...
Stefano Sabatini's avatar
Stefano Sabatini committed
148 149 150
ffmpeg -i test.wav -f avi pipe: | cat > test.avi
@end example

151
Note that some formats (typically MOV), require the output protocol to
Stefano Sabatini's avatar
Stefano Sabatini committed
152 153 154 155 156 157
be seekable, so they will fail with the pipe output protocol.

@section rtmp

Real-Time Messaging Protocol.

158 159
The Real-Time Messaging Protocol (RTMP) is used for streaming multimedia
content across a TCP/IP network.
Stefano Sabatini's avatar
Stefano Sabatini committed
160 161 162 163 164 165

The required syntax is:
@example
rtmp://@var{server}[:@var{port}][/@var{app}][/@var{playpath}]
@end example

166
The accepted parameters are:
Stefano Sabatini's avatar
Stefano Sabatini committed
167 168 169
@table @option

@item server
170
The address of the RTMP server.
Stefano Sabatini's avatar
Stefano Sabatini committed
171 172

@item port
173
The number of the TCP port to use (by default is 1935).
Stefano Sabatini's avatar
Stefano Sabatini committed
174 175

@item app
176 177
It is the name of the application to access. It usually corresponds to
the path where the application is installed on the RTMP server
Stefano Sabatini's avatar
Stefano Sabatini committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
(e.g. @file{/ondemand/}, @file{/flash/live/}, etc.).

@item playpath
It is the path or name of the resource to play with reference to the
application specified in @var{app}, may be prefixed by "mp4:".

@end table

For example to read with @file{ffplay} a multimedia resource named
"sample" from the application "vod" from an RTMP server "myserver":
@example
ffplay rtmp://myserver/vod/sample
@end example

@section rtmp, rtmpe, rtmps, rtmpt, rtmpte

Real-Time Messaging Protocol and its variants supported through
librtmp.

197
Requires the presence of the librtmp headers and library during
198
configuration. You need to explicitly configure the build with
Stefano Sabatini's avatar
Stefano Sabatini committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
"--enable-librtmp". If enabled this will replace the native RTMP
protocol.

This protocol provides most client functions and a few server
functions needed to support RTMP, RTMP tunneled in HTTP (RTMPT),
encrypted RTMP (RTMPE), RTMP over SSL/TLS (RTMPS) and tunneled
variants of these encrypted types (RTMPTE, RTMPTS).

The required syntax is:
@example
@var{rtmp_proto}://@var{server}[:@var{port}][/@var{app}][/@var{playpath}] @var{options}
@end example

where @var{rtmp_proto} is one of the strings "rtmp", "rtmpt", "rtmpe",
"rtmps", "rtmpte", "rtmpts" corresponding to each RTMP variant, and
@var{server}, @var{port}, @var{app} and @var{playpath} have the same
215
meaning as specified for the RTMP native protocol.
Stefano Sabatini's avatar
Stefano Sabatini committed
216 217 218
@var{options} contains a list of space-separated options of the form
@var{key}=@var{val}.

219
See the librtmp manual page (man 3 librtmp) for more information.
Stefano Sabatini's avatar
Stefano Sabatini committed
220 221

For example, to stream a file in real-time to an RTMP server using
222
@command{ffmpeg}:
Stefano Sabatini's avatar
Stefano Sabatini committed
223 224 225 226 227 228 229 230 231 232 233 234 235
@example
ffmpeg -re -i myfile -f flv rtmp://myserver/live/mystream
@end example

To play the same stream using @file{ffplay}:
@example
ffplay "rtmp://myserver/live/mystream live=1"
@end example

@section rtp

Real-Time Protocol.

236 237 238 239 240 241 242 243 244
@section rtsp

RTSP is not technically a protocol handler in libavformat, it is a demuxer
and muxer. The demuxer supports both normal RTSP (with data transferred
over RTP; this is used by e.g. Apple and Microsoft) and Real-RTSP (with
data transferred over RDT).

The muxer can be used to send a stream using RTSP ANNOUNCE to a server
supporting it (currently Darwin Streaming Server and Mischa Spiegelmock's
245
@uref{http://github.com/revmischa/rtsp-server, RTSP server}).
246 247 248

The required syntax for a RTSP url is:
@example
249
rtsp://@var{hostname}[:@var{port}]/@var{path}
250 251
@end example

252
The following options (set on the @command{ffmpeg}/@file{ffplay} command
253
line, or set in code via @code{AVOption}s or in @code{avformat_open_input}),
254 255
are supported:

256 257
Flags for @code{rtsp_transport}:

258 259 260 261 262 263 264 265 266
@table @option

@item udp
Use UDP as lower transport protocol.

@item tcp
Use TCP (interleaving within the RTSP control channel) as lower
transport protocol.

267
@item udp_multicast
268 269 270 271 272 273 274 275 276 277 278
Use UDP multicast as lower transport protocol.

@item http
Use HTTP tunneling as lower transport protocol, which is useful for
passing proxies.
@end table

Multiple lower transport protocols may be specified, in that case they are
tried one at a time (if the setup of one fails, the next one is tried).
For the muxer, only the @code{tcp} and @code{udp} options are supported.

279 280 281 282 283 284 285
Flags for @code{rtsp_flags}:

@table @option
@item filter_src
Accept packets only from negotiated peer address and port.
@end table

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
When receiving data over UDP, the demuxer tries to reorder received packets
(since they may arrive out of order, or packets may get lost totally). In
order for this to be enabled, a maximum delay must be specified in the
@code{max_delay} field of AVFormatContext.

When watching multi-bitrate Real-RTSP streams with @file{ffplay}, the
streams to display can be chosen with @code{-vst} @var{n} and
@code{-ast} @var{n} for video and audio respectively, and can be switched
on the fly by pressing @code{v} and @code{a}.

Example command lines:

To watch a stream over UDP, with a max reordering delay of 0.5 seconds:

@example
301
ffplay -max_delay 500000 -rtsp_transport udp rtsp://server/video.mp4
302 303 304 305 306
@end example

To watch a stream tunneled over HTTP:

@example
307
ffplay -rtsp_transport http rtsp://server/video.mp4
308 309 310 311 312 313 314 315
@end example

To send a stream in realtime to a RTSP server, for others to watch:

@example
ffmpeg -re -i @var{input} -f rtsp -muxdelay 0.1 rtsp://server/live.sdp
@end example

Martin Storsjö's avatar
Martin Storsjö committed
316 317 318
@section sap

Session Announcement Protocol (RFC 2974). This is not technically a
Martin Storsjö's avatar
Martin Storsjö committed
319
protocol handler in libavformat, it is a muxer and demuxer.
Martin Storsjö's avatar
Martin Storsjö committed
320 321 322
It is used for signalling of RTP streams, by announcing the SDP for the
streams regularly on a separate port.

Martin Storsjö's avatar
Martin Storsjö committed
323 324
@subsection Muxer

Martin Storsjö's avatar
Martin Storsjö committed
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
The syntax for a SAP url given to the muxer is:
@example
sap://@var{destination}[:@var{port}][?@var{options}]
@end example

The RTP packets are sent to @var{destination} on port @var{port},
or to port 5004 if no port is specified.
@var{options} is a @code{&}-separated list. The following options
are supported:

@table @option

@item announce_addr=@var{address}
Specify the destination IP address for sending the announcements to.
If omitted, the announcements are sent to the commonly used SAP
announcement multicast address 224.2.127.254 (sap.mcast.net), or
ff0e::2:7ffe if @var{destination} is an IPv6 address.

@item announce_port=@var{port}
Specify the port to send the announcements on, defaults to
9875 if not specified.

@item ttl=@var{ttl}
Specify the time to live value for the announcements and RTP packets,
defaults to 255.

@item same_port=@var{0|1}
If set to 1, send all RTP streams on the same port pair. If zero (the
default), all streams are sent on unique ports, with each stream on a
port 2 numbers higher than the previous.
VLC/Live555 requires this to be set to 1, to be able to receive the stream.
Martin Storsjö's avatar
Martin Storsjö committed
356 357
The RTP stack in libavformat for receiving requires all streams to be sent
on unique ports.
Martin Storsjö's avatar
Martin Storsjö committed
358 359 360 361 362 363 364 365 366 367
@end table

Example command lines follow.

To broadcast a stream on the local subnet, for watching in VLC:

@example
ffmpeg -re -i @var{input} -f sap sap://224.0.0.255?same_port=1
@end example

Martin Storsjö's avatar
Martin Storsjö committed
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
Similarly, for watching in ffplay:

@example
ffmpeg -re -i @var{input} -f sap sap://224.0.0.255
@end example

And for watching in ffplay, over IPv6:

@example
ffmpeg -re -i @var{input} -f sap sap://[ff0e::1:2:3:4]
@end example

@subsection Demuxer

The syntax for a SAP url given to the demuxer is:
@example
sap://[@var{address}][:@var{port}]
@end example

@var{address} is the multicast address to listen for announcements on,
if omitted, the default 224.2.127.254 (sap.mcast.net) is used. @var{port}
is the port that is listened on, 9875 if omitted.

The demuxers listens for announcements on the given address and port.
Once an announcement is received, it tries to receive that particular stream.

Example command lines follow.

To play back the first stream announced on the normal SAP multicast address:

@example
ffplay sap://
@end example

To play back the first stream announced on one the default IPv6 SAP multicast address:

@example
ffplay sap://[ff0e::2:7ffe]
@end example

Stefano Sabatini's avatar
Stefano Sabatini committed
408 409 410 411
@section tcp

Trasmission Control Protocol.

412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
The required syntax for a TCP url is:
@example
tcp://@var{hostname}:@var{port}[?@var{options}]
@end example

@table @option

@item listen
Listen for an incoming connection

@example
ffmpeg -i @var{input} -f @var{format} tcp://@var{hostname}:@var{port}?listen
ffplay tcp://@var{hostname}:@var{port}
@end example

@end table

Stefano Sabatini's avatar
Stefano Sabatini committed
429 430 431 432
@section udp

User Datagram Protocol.

433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
The required syntax for a UDP url is:
@example
udp://@var{hostname}:@var{port}[?@var{options}]
@end example

@var{options} contains a list of &-seperated options of the form @var{key}=@var{val}.
Follow the list of supported options.

@table @option

@item buffer_size=@var{size}
set the UDP buffer size in bytes

@item localport=@var{port}
override the local UDP port to bind with

449 450 451 452 453
@item localaddr=@var{addr}
Choose the local IP address. This is useful e.g. if sending multicast
and the host has multiple interfaces, where the user can choose
which interface to send on by specifying the IP address of that interface.

454 455 456 457 458 459 460 461
@item pkt_size=@var{size}
set the size in bytes of UDP packets

@item reuse=@var{1|0}
explicitly allow or disallow reusing UDP sockets

@item ttl=@var{ttl}
set the time to live value (for multicast only)
462 463 464

@item connect=@var{1|0}
Initialize the UDP socket with @code{connect()}. In this case, the
465
destination address can't be changed with ff_udp_set_remote_url later.
466
If the destination address isn't known at the start, this option can
467
be specified in ff_udp_set_remote_url, too.
468 469 470
This allows finding out the source address for the packets with getsockname,
and makes writes return with AVERROR(ECONNREFUSED) if "destination
unreachable" is received.
471 472
For receiving, this gives the benefit of only receiving packets from
the specified peer address/port.
473 474
@end table

475
Some usage examples of the udp protocol with @command{ffmpeg} follow.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491

To stream over UDP to a remote endpoint:
@example
ffmpeg -i @var{input} -f @var{format} udp://@var{hostname}:@var{port}
@end example

To stream in mpegts format over UDP using 188 sized UDP packets, using a large input buffer:
@example
ffmpeg -i @var{input} -f mpegts udp://@var{hostname}:@var{port}?pkt_size=188&buffer_size=65535
@end example

To receive over UDP from a remote endpoint:
@example
ffmpeg -i udp://[@var{multicast-address}]:@var{port}
@end example

Stefano Sabatini's avatar
Stefano Sabatini committed
492
@c man end PROTOCOLS