protocols.texi 12 KB

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