1@chapter Protocols 2@c man begin PROTOCOLS 3 4Protocols are configured elements in Libav which allow to access 5resources which require the use of a particular protocol. 6 7When you configure your Libav build, all the supported protocols are 8enabled by default. You can list all available ones using the 9configure option "--list-protocols". 10 11You can disable all the protocols using the configure option 12"--disable-protocols", and selectively enable a protocol using the 13option "--enable-protocol=@var{PROTOCOL}", or you can disable a 14particular protocol using the option 15"--disable-protocol=@var{PROTOCOL}". 16 17The option "-protocols" of the av* tools will display the list of 18supported protocols. 19 20A description of the currently available protocols follows. 21 22@section applehttp 23 24Read Apple HTTP Live Streaming compliant segmented stream as 25a uniform one. The M3U8 playlists describing the segments can be 26remote HTTP resources or local files, accessed using the standard 27file protocol. 28HTTP is default, specific protocol can be declared by specifying 29"+@var{proto}" after the applehttp URI scheme name, where @var{proto} 30is either "file" or "http". 31 32@example 33applehttp://host/path/to/remote/resource.m3u8 34applehttp+http://host/path/to/remote/resource.m3u8 35applehttp+file://path/to/local/resource.m3u8 36@end example 37 38@section concat 39 40Physical concatenation protocol. 41 42Allow to read and seek from many resource in sequence as if they were 43a unique resource. 44 45A URL accepted by this protocol has the syntax: 46@example 47concat:@var{URL1}|@var{URL2}|...|@var{URLN} 48@end example 49 50where @var{URL1}, @var{URL2}, ..., @var{URLN} are the urls of the 51resource to be concatenated, each one possibly specifying a distinct 52protocol. 53 54For example to read a sequence of files @file{split1.mpeg}, 55@file{split2.mpeg}, @file{split3.mpeg} with @file{avplay} use the 56command: 57@example 58avplay concat:split1.mpeg\|split2.mpeg\|split3.mpeg 59@end example 60 61Note that you may need to escape the character "|" which is special for 62many shells. 63 64@section file 65 66File access protocol. 67 68Allow to read from or read to a file. 69 70For example to read from a file @file{input.mpeg} with @command{avconv} 71use the command: 72@example 73avconv -i file:input.mpeg output.mpeg 74@end example 75 76The av* tools default to the file protocol, that is a resource 77specified with the name "FILE.mpeg" is interpreted as the URL 78"file:FILE.mpeg". 79 80@section gopher 81 82Gopher protocol. 83 84@section http 85 86HTTP (Hyper Text Transfer Protocol). 87 88@section mmst 89 90MMS (Microsoft Media Server) protocol over TCP. 91 92@section mmsh 93 94MMS (Microsoft Media Server) protocol over HTTP. 95 96The required syntax is: 97@example 98mmsh://@var{server}[:@var{port}][/@var{app}][/@var{playpath}] 99@end example 100 101@section md5 102 103MD5 output protocol. 104 105Computes the MD5 hash of the data to be written, and on close writes 106this to the designated output or stdout if none is specified. It can 107be used to test muxers without writing an actual file. 108 109Some examples follow. 110@example 111# Write the MD5 hash of the encoded AVI file to the file output.avi.md5. 112avconv -i input.flv -f avi -y md5:output.avi.md5 113 114# Write the MD5 hash of the encoded AVI file to stdout. 115avconv -i input.flv -f avi -y md5: 116@end example 117 118Note that some formats (typically MOV) require the output protocol to 119be seekable, so they will fail with the MD5 output protocol. 120 121@section pipe 122 123UNIX pipe access protocol. 124 125Allow to read and write from UNIX pipes. 126 127The accepted syntax is: 128@example 129pipe:[@var{number}] 130@end example 131 132@var{number} is the number corresponding to the file descriptor of the 133pipe (e.g. 0 for stdin, 1 for stdout, 2 for stderr). If @var{number} 134is not specified, by default the stdout file descriptor will be used 135for writing, stdin for reading. 136 137For example to read from stdin with @command{avconv}: 138@example 139cat test.wav | avconv -i pipe:0 140# ...this is the same as... 141cat test.wav | avconv -i pipe: 142@end example 143 144For writing to stdout with @command{avconv}: 145@example 146avconv -i test.wav -f avi pipe:1 | cat > test.avi 147# ...this is the same as... 148avconv -i test.wav -f avi pipe: | cat > test.avi 149@end example 150 151Note that some formats (typically MOV), require the output protocol to 152be seekable, so they will fail with the pipe output protocol. 153 154@section rtmp 155 156Real-Time Messaging Protocol. 157 158The Real-Time Messaging Protocol (RTMP) is used for streaming multimedia 159content across a TCP/IP network. 160 161The required syntax is: 162@example 163rtmp://@var{server}[:@var{port}][/@var{app}][/@var{playpath}] 164@end example 165 166The accepted parameters are: 167@table @option 168 169@item server 170The address of the RTMP server. 171 172@item port 173The number of the TCP port to use (by default is 1935). 174 175@item app 176It is the name of the application to access. It usually corresponds to 177the path where the application is installed on the RTMP server 178(e.g. @file{/ondemand/}, @file{/flash/live/}, etc.). 179 180@item playpath 181It is the path or name of the resource to play with reference to the 182application specified in @var{app}, may be prefixed by "mp4:". 183 184@end table 185 186For example to read with @file{avplay} a multimedia resource named 187"sample" from the application "vod" from an RTMP server "myserver": 188@example 189avplay rtmp://myserver/vod/sample 190@end example 191 192@section rtmp, rtmpe, rtmps, rtmpt, rtmpte 193 194Real-Time Messaging Protocol and its variants supported through 195librtmp. 196 197Requires the presence of the librtmp headers and library during 198configuration. You need to explicitly configure the build with 199"--enable-librtmp". If enabled this will replace the native RTMP 200protocol. 201 202This protocol provides most client functions and a few server 203functions needed to support RTMP, RTMP tunneled in HTTP (RTMPT), 204encrypted RTMP (RTMPE), RTMP over SSL/TLS (RTMPS) and tunneled 205variants of these encrypted types (RTMPTE, RTMPTS). 206 207The required syntax is: 208@example 209@var{rtmp_proto}://@var{server}[:@var{port}][/@var{app}][/@var{playpath}] @var{options} 210@end example 211 212where @var{rtmp_proto} is one of the strings "rtmp", "rtmpt", "rtmpe", 213"rtmps", "rtmpte", "rtmpts" corresponding to each RTMP variant, and 214@var{server}, @var{port}, @var{app} and @var{playpath} have the same 215meaning as specified for the RTMP native protocol. 216@var{options} contains a list of space-separated options of the form 217@var{key}=@var{val}. 218 219See the librtmp manual page (man 3 librtmp) for more information. 220 221For example, to stream a file in real-time to an RTMP server using 222@command{avconv}: 223@example 224avconv -re -i myfile -f flv rtmp://myserver/live/mystream 225@end example 226 227To play the same stream using @file{avplay}: 228@example 229avplay "rtmp://myserver/live/mystream live=1" 230@end example 231 232@section rtp 233 234Real-Time Protocol. 235 236@section rtsp 237 238RTSP is not technically a protocol handler in libavformat, it is a demuxer 239and muxer. The demuxer supports both normal RTSP (with data transferred 240over RTP; this is used by e.g. Apple and Microsoft) and Real-RTSP (with 241data transferred over RDT). 242 243The muxer can be used to send a stream using RTSP ANNOUNCE to a server 244supporting it (currently Darwin Streaming Server and Mischa Spiegelmock's 245@uref{http://github.com/revmischa/rtsp-server, RTSP server}). 246 247The required syntax for a RTSP url is: 248@example 249rtsp://@var{hostname}[:@var{port}]/@var{path} 250@end example 251 252The following options (set on the @command{avconv}/@file{avplay} command 253line, or set in code via @code{AVOption}s or in @code{avformat_open_input}), 254are supported: 255 256Flags for @code{rtsp_transport}: 257 258@table @option 259 260@item udp 261Use UDP as lower transport protocol. 262 263@item tcp 264Use TCP (interleaving within the RTSP control channel) as lower 265transport protocol. 266 267@item udp_multicast 268Use UDP multicast as lower transport protocol. 269 270@item http 271Use HTTP tunneling as lower transport protocol, which is useful for 272passing proxies. 273@end table 274 275Multiple lower transport protocols may be specified, in that case they are 276tried one at a time (if the setup of one fails, the next one is tried). 277For the muxer, only the @code{tcp} and @code{udp} options are supported. 278 279Flags for @code{rtsp_flags}: 280 281@table @option 282@item filter_src 283Accept packets only from negotiated peer address and port. 284@end table 285 286When receiving data over UDP, the demuxer tries to reorder received packets 287(since they may arrive out of order, or packets may get lost totally). In 288order for this to be enabled, a maximum delay must be specified in the 289@code{max_delay} field of AVFormatContext. 290 291When watching multi-bitrate Real-RTSP streams with @file{avplay}, the 292streams to display can be chosen with @code{-vst} @var{n} and 293@code{-ast} @var{n} for video and audio respectively, and can be switched 294on the fly by pressing @code{v} and @code{a}. 295 296Example command lines: 297 298To watch a stream over UDP, with a max reordering delay of 0.5 seconds: 299 300@example 301avplay -max_delay 500000 -rtsp_transport udp rtsp://server/video.mp4 302@end example 303 304To watch a stream tunneled over HTTP: 305 306@example 307avplay -rtsp_transport http rtsp://server/video.mp4 308@end example 309 310To send a stream in realtime to a RTSP server, for others to watch: 311 312@example 313avconv -re -i @var{input} -f rtsp -muxdelay 0.1 rtsp://server/live.sdp 314@end example 315 316@section sap 317 318Session Announcement Protocol (RFC 2974). This is not technically a 319protocol handler in libavformat, it is a muxer and demuxer. 320It is used for signalling of RTP streams, by announcing the SDP for the 321streams regularly on a separate port. 322 323@subsection Muxer 324 325The syntax for a SAP url given to the muxer is: 326@example 327sap://@var{destination}[:@var{port}][?@var{options}] 328@end example 329 330The RTP packets are sent to @var{destination} on port @var{port}, 331or to port 5004 if no port is specified. 332@var{options} is a @code{&}-separated list. The following options 333are supported: 334 335@table @option 336 337@item announce_addr=@var{address} 338Specify the destination IP address for sending the announcements to. 339If omitted, the announcements are sent to the commonly used SAP 340announcement multicast address 224.2.127.254 (sap.mcast.net), or 341ff0e::2:7ffe if @var{destination} is an IPv6 address. 342 343@item announce_port=@var{port} 344Specify the port to send the announcements on, defaults to 3459875 if not specified. 346 347@item ttl=@var{ttl} 348Specify the time to live value for the announcements and RTP packets, 349defaults to 255. 350 351@item same_port=@var{0|1} 352If set to 1, send all RTP streams on the same port pair. If zero (the 353default), all streams are sent on unique ports, with each stream on a 354port 2 numbers higher than the previous. 355VLC/Live555 requires this to be set to 1, to be able to receive the stream. 356The RTP stack in libavformat for receiving requires all streams to be sent 357on unique ports. 358@end table 359 360Example command lines follow. 361 362To broadcast a stream on the local subnet, for watching in VLC: 363 364@example 365avconv -re -i @var{input} -f sap sap://224.0.0.255?same_port=1 366@end example 367 368Similarly, for watching in avplay: 369 370@example 371avconv -re -i @var{input} -f sap sap://224.0.0.255 372@end example 373 374And for watching in avplay, over IPv6: 375 376@example 377avconv -re -i @var{input} -f sap sap://[ff0e::1:2:3:4] 378@end example 379 380@subsection Demuxer 381 382The syntax for a SAP url given to the demuxer is: 383@example 384sap://[@var{address}][:@var{port}] 385@end example 386 387@var{address} is the multicast address to listen for announcements on, 388if omitted, the default 224.2.127.254 (sap.mcast.net) is used. @var{port} 389is the port that is listened on, 9875 if omitted. 390 391The demuxers listens for announcements on the given address and port. 392Once an announcement is received, it tries to receive that particular stream. 393 394Example command lines follow. 395 396To play back the first stream announced on the normal SAP multicast address: 397 398@example 399avplay sap:// 400@end example 401 402To play back the first stream announced on one the default IPv6 SAP multicast address: 403 404@example 405avplay sap://[ff0e::2:7ffe] 406@end example 407 408@section tcp 409 410Trasmission Control Protocol. 411 412The required syntax for a TCP url is: 413@example 414tcp://@var{hostname}:@var{port}[?@var{options}] 415@end example 416 417@table @option 418 419@item listen 420Listen for an incoming connection 421 422@example 423avconv -i @var{input} -f @var{format} tcp://@var{hostname}:@var{port}?listen 424avplay tcp://@var{hostname}:@var{port} 425@end example 426 427@end table 428 429@section udp 430 431User Datagram Protocol. 432 433The required syntax for a UDP url is: 434@example 435udp://@var{hostname}:@var{port}[?@var{options}] 436@end example 437 438@var{options} contains a list of &-seperated options of the form @var{key}=@var{val}. 439Follow the list of supported options. 440 441@table @option 442 443@item buffer_size=@var{size} 444set the UDP buffer size in bytes 445 446@item localport=@var{port} 447override the local UDP port to bind with 448 449@item localaddr=@var{addr} 450Choose the local IP address. This is useful e.g. if sending multicast 451and the host has multiple interfaces, where the user can choose 452which interface to send on by specifying the IP address of that interface. 453 454@item pkt_size=@var{size} 455set the size in bytes of UDP packets 456 457@item reuse=@var{1|0} 458explicitly allow or disallow reusing UDP sockets 459 460@item ttl=@var{ttl} 461set the time to live value (for multicast only) 462 463@item connect=@var{1|0} 464Initialize the UDP socket with @code{connect()}. In this case, the 465destination address can't be changed with ff_udp_set_remote_url later. 466If the destination address isn't known at the start, this option can 467be specified in ff_udp_set_remote_url, too. 468This allows finding out the source address for the packets with getsockname, 469and makes writes return with AVERROR(ECONNREFUSED) if "destination 470unreachable" is received. 471For receiving, this gives the benefit of only receiving packets from 472the specified peer address/port. 473@end table 474 475Some usage examples of the udp protocol with @command{avconv} follow. 476 477To stream over UDP to a remote endpoint: 478@example 479avconv -i @var{input} -f @var{format} udp://@var{hostname}:@var{port} 480@end example 481 482To stream in mpegts format over UDP using 188 sized UDP packets, using a large input buffer: 483@example 484avconv -i @var{input} -f mpegts udp://@var{hostname}:@var{port}?pkt_size=188&buffer_size=65535 485@end example 486 487To receive over UDP from a remote endpoint: 488@example 489avconv -i udp://[@var{multicast-address}]:@var{port} 490@end example 491 492@c man end PROTOCOLS 493