protocols.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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 @command{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 @command{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 @command{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
  113. multimedia 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 explicitly 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. @command{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}
  181. @end example
  182. The following options (set on the @command{ffmpeg}/@file{ffplay} command
  183. line, or set in code via @code{AVOption}s or in @code{avformat_open_input}),
  184. are supported:
  185. Flags for @code{rtsp_transport}:
  186. @table @option
  187. @item udp
  188. Use UDP as lower transport protocol.
  189. @item tcp
  190. Use TCP (interleaving within the RTSP control channel) as lower
  191. transport protocol.
  192. @item udp_multicast
  193. Use UDP multicast as lower transport protocol.
  194. @item http
  195. Use HTTP tunneling as lower transport protocol, which is useful for
  196. passing proxies.
  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. Flags for @code{rtsp_flags}:
  202. @table @option
  203. @item filter_src
  204. Accept packets only from negotiated peer address and port.
  205. @end table
  206. When receiving data over UDP, the demuxer tries to reorder received packets
  207. (since they may arrive out of order, or packets may get lost totally). In
  208. order for this to be enabled, a maximum delay must be specified in the
  209. @code{max_delay} field of AVFormatContext.
  210. When watching multi-bitrate Real-RTSP streams with @file{ffplay}, the
  211. streams to display can be chosen with @code{-vst} @var{n} and
  212. @code{-ast} @var{n} for video and audio respectively, and can be switched
  213. on the fly by pressing @code{v} and @code{a}.
  214. Example command lines:
  215. To watch a stream over UDP, with a max reordering delay of 0.5 seconds:
  216. @example
  217. ffplay -max_delay 500000 -rtsp_transport udp rtsp://server/video.mp4
  218. @end example
  219. To watch a stream tunneled over HTTP:
  220. @example
  221. ffplay -rtsp_transport http rtsp://server/video.mp4
  222. @end example
  223. To send a stream in realtime to a RTSP server, for others to watch:
  224. @example
  225. ffmpeg -re -i @var{input} -f rtsp -muxdelay 0.1 rtsp://server/live.sdp
  226. @end example
  227. @section sap
  228. Session Announcement Protocol (RFC 2974). This is not technically a
  229. protocol handler in libavformat, it is a muxer and demuxer.
  230. It is used for signalling of RTP streams, by announcing the SDP for the
  231. streams regularly on a separate port.
  232. @subsection Muxer
  233. The syntax for a SAP url given to the muxer is:
  234. @example
  235. sap://@var{destination}[:@var{port}][?@var{options}]
  236. @end example
  237. The RTP packets are sent to @var{destination} on port @var{port},
  238. or to port 5004 if no port is specified.
  239. @var{options} is a @code{&}-separated list. The following options
  240. are supported:
  241. @table @option
  242. @item announce_addr=@var{address}
  243. Specify the destination IP address for sending the announcements to.
  244. If omitted, the announcements are sent to the commonly used SAP
  245. announcement multicast address 224.2.127.254 (sap.mcast.net), or
  246. ff0e::2:7ffe if @var{destination} is an IPv6 address.
  247. @item announce_port=@var{port}
  248. Specify the port to send the announcements on, defaults to
  249. 9875 if not specified.
  250. @item ttl=@var{ttl}
  251. Specify the time to live value for the announcements and RTP packets,
  252. defaults to 255.
  253. @item same_port=@var{0|1}
  254. If set to 1, send all RTP streams on the same port pair. If zero (the
  255. default), all streams are sent on unique ports, with each stream on a
  256. port 2 numbers higher than the previous.
  257. VLC/Live555 requires this to be set to 1, to be able to receive the stream.
  258. The RTP stack in libavformat for receiving requires all streams to be sent
  259. on unique ports.
  260. @end table
  261. Example command lines follow.
  262. To broadcast a stream on the local subnet, for watching in VLC:
  263. @example
  264. ffmpeg -re -i @var{input} -f sap sap://224.0.0.255?same_port=1
  265. @end example
  266. Similarly, for watching in ffplay:
  267. @example
  268. ffmpeg -re -i @var{input} -f sap sap://224.0.0.255
  269. @end example
  270. And for watching in ffplay, over IPv6:
  271. @example
  272. ffmpeg -re -i @var{input} -f sap sap://[ff0e::1:2:3:4]
  273. @end example
  274. @subsection Demuxer
  275. The syntax for a SAP url given to the demuxer is:
  276. @example
  277. sap://[@var{address}][:@var{port}]
  278. @end example
  279. @var{address} is the multicast address to listen for announcements on,
  280. if omitted, the default 224.2.127.254 (sap.mcast.net) is used. @var{port}
  281. is the port that is listened on, 9875 if omitted.
  282. The demuxers listens for announcements on the given address and port.
  283. Once an announcement is received, it tries to receive that particular stream.
  284. Example command lines follow.
  285. To play back the first stream announced on the normal SAP multicast address:
  286. @example
  287. ffplay sap://
  288. @end example
  289. To play back the first stream announced on one the default IPv6 SAP multicast address:
  290. @example
  291. ffplay sap://[ff0e::2:7ffe]
  292. @end example
  293. @section tcp
  294. Trasmission Control Protocol.
  295. The required syntax for a TCP url is:
  296. @example
  297. tcp://@var{hostname}:@var{port}[?@var{options}]
  298. @end example
  299. @table @option
  300. @item listen
  301. Listen for an incoming connection
  302. @example
  303. ffmpeg -i @var{input} -f @var{format} tcp://@var{hostname}:@var{port}?listen
  304. ffplay tcp://@var{hostname}:@var{port}
  305. @end example
  306. @end table
  307. @section udp
  308. User Datagram Protocol.
  309. The required syntax for a UDP url is:
  310. @example
  311. udp://@var{hostname}:@var{port}[?@var{options}]
  312. @end example
  313. @var{options} contains a list of &-seperated options of the form @var{key}=@var{val}.
  314. Follow the list of supported options.
  315. @table @option
  316. @item buffer_size=@var{size}
  317. set the UDP buffer size in bytes
  318. @item localport=@var{port}
  319. override the local UDP port to bind with
  320. @item localaddr=@var{addr}
  321. Choose the local IP address. This is useful e.g. if sending multicast
  322. and the host has multiple interfaces, where the user can choose
  323. which interface to send on by specifying the IP address of that interface.
  324. @item pkt_size=@var{size}
  325. set the size in bytes of UDP packets
  326. @item reuse=@var{1|0}
  327. explicitly allow or disallow reusing UDP sockets
  328. @item ttl=@var{ttl}
  329. set the time to live value (for multicast only)
  330. @item connect=@var{1|0}
  331. Initialize the UDP socket with @code{connect()}. In this case, the
  332. destination address can't be changed with ff_udp_set_remote_url later.
  333. If the destination address isn't known at the start, this option can
  334. be specified in ff_udp_set_remote_url, too.
  335. This allows finding out the source address for the packets with getsockname,
  336. and makes writes return with AVERROR(ECONNREFUSED) if "destination
  337. unreachable" is received.
  338. For receiving, this gives the benefit of only receiving packets from
  339. the specified peer address/port.
  340. @end table
  341. Some usage examples of the udp protocol with @command{ffmpeg} follow.
  342. To stream over UDP to a remote endpoint:
  343. @example
  344. ffmpeg -i @var{input} -f @var{format} udp://@var{hostname}:@var{port}
  345. @end example
  346. To stream in mpegts format over UDP using 188 sized UDP packets, using a large input buffer:
  347. @example
  348. ffmpeg -i @var{input} -f mpegts udp://@var{hostname}:@var{port}?pkt_size=188&buffer_size=65535
  349. @end example
  350. To receive over UDP from a remote endpoint:
  351. @example
  352. ffmpeg -i udp://[@var{multicast-address}]:@var{port}
  353. @end example
  354. @c man end PROTOCOLS