protocols.texi 13 KB

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