protocols.texi 16 KB

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