| 1 | @chapter Demuxers |
| 2 | @c man begin DEMUXERS |
| 3 | |
| 4 | Demuxers are configured elements in FFmpeg that can read the |
| 5 | multimedia streams from a particular type of file. |
| 6 | |
| 7 | When you configure your FFmpeg build, all the supported demuxers |
| 8 | are enabled by default. You can list all available ones using the |
| 9 | configure option @code{--list-demuxers}. |
| 10 | |
| 11 | You can disable all the demuxers using the configure option |
| 12 | @code{--disable-demuxers}, and selectively enable a single demuxer with |
| 13 | the option @code{--enable-demuxer=@var{DEMUXER}}, or disable it |
| 14 | with the option @code{--disable-demuxer=@var{DEMUXER}}. |
| 15 | |
| 16 | The option @code{-formats} of the ff* tools will display the list of |
| 17 | enabled demuxers. |
| 18 | |
| 19 | The description of some of the currently available demuxers follows. |
| 20 | |
| 21 | @section applehttp |
| 22 | |
| 23 | Apple HTTP Live Streaming demuxer. |
| 24 | |
| 25 | This demuxer presents all AVStreams from all variant streams. |
| 26 | The id field is set to the bitrate variant index number. By setting |
| 27 | the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay), |
| 28 | the caller can decide which variant streams to actually receive. |
| 29 | The total bitrate of the variant that the stream belongs to is |
| 30 | available in a metadata key named "variant_bitrate". |
| 31 | |
| 32 | @section asf |
| 33 | |
| 34 | Advanced Systems Format demuxer. |
| 35 | |
| 36 | This demuxer is used to demux ASF files and MMS network streams. |
| 37 | |
| 38 | @table @option |
| 39 | @item -no_resync_search @var{bool} |
| 40 | Do not try to resynchronize by looking for a certain optional start code. |
| 41 | @end table |
| 42 | |
| 43 | @anchor{concat} |
| 44 | @section concat |
| 45 | |
| 46 | Virtual concatenation script demuxer. |
| 47 | |
| 48 | This demuxer reads a list of files and other directives from a text file and |
| 49 | demuxes them one after the other, as if all their packet had been muxed |
| 50 | together. |
| 51 | |
| 52 | The timestamps in the files are adjusted so that the first file starts at 0 |
| 53 | and each next file starts where the previous one finishes. Note that it is |
| 54 | done globally and may cause gaps if all streams do not have exactly the same |
| 55 | length. |
| 56 | |
| 57 | All files must have the same streams (same codecs, same time base, etc.). |
| 58 | |
| 59 | The duration of each file is used to adjust the timestamps of the next file: |
| 60 | if the duration is incorrect (because it was computed using the bit-rate or |
| 61 | because the file is truncated, for example), it can cause artifacts. The |
| 62 | @code{duration} directive can be used to override the duration stored in |
| 63 | each file. |
| 64 | |
| 65 | @subsection Syntax |
| 66 | |
| 67 | The script is a text file in extended-ASCII, with one directive per line. |
| 68 | Empty lines, leading spaces and lines starting with '#' are ignored. The |
| 69 | following directive is recognized: |
| 70 | |
| 71 | @table @option |
| 72 | |
| 73 | @item @code{file @var{path}} |
| 74 | Path to a file to read; special characters and spaces must be escaped with |
| 75 | backslash or single quotes. |
| 76 | |
| 77 | All subsequent file-related directives apply to that file. |
| 78 | |
| 79 | @item @code{ffconcat version 1.0} |
| 80 | Identify the script type and version. It also sets the @option{safe} option |
| 81 | to 1 if it was to its default -1. |
| 82 | |
| 83 | To make FFmpeg recognize the format automatically, this directive must |
| 84 | appears exactly as is (no extra space or byte-order-mark) on the very first |
| 85 | line of the script. |
| 86 | |
| 87 | @item @code{duration @var{dur}} |
| 88 | Duration of the file. This information can be specified from the file; |
| 89 | specifying it here may be more efficient or help if the information from the |
| 90 | file is not available or accurate. |
| 91 | |
| 92 | If the duration is set for all files, then it is possible to seek in the |
| 93 | whole concatenated video. |
| 94 | |
| 95 | @item @code{stream} |
| 96 | Introduce a stream in the virtual file. |
| 97 | All subsequent stream-related directives apply to the last introduced |
| 98 | stream. |
| 99 | Some streams properties must be set in order to allow identifying the |
| 100 | matching streams in the subfiles. |
| 101 | If no streams are defined in the script, the streams from the first file are |
| 102 | copied. |
| 103 | |
| 104 | @item @code{exact_stream_id @var{id}} |
| 105 | Set the id of the stream. |
| 106 | If this directive is given, the string with the corresponding id in the |
| 107 | subfiles will be used. |
| 108 | This is especially useful for MPEG-PS (VOB) files, where the order of the |
| 109 | streams is not reliable. |
| 110 | |
| 111 | @end table |
| 112 | |
| 113 | @subsection Options |
| 114 | |
| 115 | This demuxer accepts the following option: |
| 116 | |
| 117 | @table @option |
| 118 | |
| 119 | @item safe |
| 120 | If set to 1, reject unsafe file paths. A file path is considered safe if it |
| 121 | does not contain a protocol specification and is relative and all components |
| 122 | only contain characters from the portable character set (letters, digits, |
| 123 | period, underscore and hyphen) and have no period at the beginning of a |
| 124 | component. |
| 125 | |
| 126 | If set to 0, any file name is accepted. |
| 127 | |
| 128 | The default is -1, it is equivalent to 1 if the format was automatically |
| 129 | probed and 0 otherwise. |
| 130 | |
| 131 | @item auto_convert |
| 132 | If set to 1, try to perform automatic conversions on packet data to make the |
| 133 | streams concatenable. |
| 134 | |
| 135 | Currently, the only conversion is adding the h264_mp4toannexb bitstream |
| 136 | filter to H.264 streams in MP4 format. This is necessary in particular if |
| 137 | there are resolution changes. |
| 138 | |
| 139 | @end table |
| 140 | |
| 141 | @section flv |
| 142 | |
| 143 | Adobe Flash Video Format demuxer. |
| 144 | |
| 145 | This demuxer is used to demux FLV files and RTMP network streams. |
| 146 | |
| 147 | @table @option |
| 148 | @item -flv_metadata @var{bool} |
| 149 | Allocate the streams according to the onMetaData array content. |
| 150 | @end table |
| 151 | |
| 152 | @section libgme |
| 153 | |
| 154 | The Game Music Emu library is a collection of video game music file emulators. |
| 155 | |
| 156 | See @url{http://code.google.com/p/game-music-emu/} for more information. |
| 157 | |
| 158 | Some files have multiple tracks. The demuxer will pick the first track by |
| 159 | default. The @option{track_index} option can be used to select a different |
| 160 | track. Track indexes start at 0. The demuxer exports the number of tracks as |
| 161 | @var{tracks} meta data entry. |
| 162 | |
| 163 | For very large files, the @option{max_size} option may have to be adjusted. |
| 164 | |
| 165 | @section libquvi |
| 166 | |
| 167 | Play media from Internet services using the quvi project. |
| 168 | |
| 169 | The demuxer accepts a @option{format} option to request a specific quality. It |
| 170 | is by default set to @var{best}. |
| 171 | |
| 172 | See @url{http://quvi.sourceforge.net/} for more information. |
| 173 | |
| 174 | FFmpeg needs to be built with @code{--enable-libquvi} for this demuxer to be |
| 175 | enabled. |
| 176 | |
| 177 | @section gif |
| 178 | |
| 179 | Animated GIF demuxer. |
| 180 | |
| 181 | It accepts the following options: |
| 182 | |
| 183 | @table @option |
| 184 | @item min_delay |
| 185 | Set the minimum valid delay between frames in hundredths of seconds. |
| 186 | Range is 0 to 6000. Default value is 2. |
| 187 | |
| 188 | @item default_delay |
| 189 | Set the default delay between frames in hundredths of seconds. |
| 190 | Range is 0 to 6000. Default value is 10. |
| 191 | |
| 192 | @item ignore_loop |
| 193 | GIF files can contain information to loop a certain number of times (or |
| 194 | infinitely). If @option{ignore_loop} is set to 1, then the loop setting |
| 195 | from the input will be ignored and looping will not occur. If set to 0, |
| 196 | then looping will occur and will cycle the number of times according to |
| 197 | the GIF. Default value is 1. |
| 198 | @end table |
| 199 | |
| 200 | For example, with the overlay filter, place an infinitely looping GIF |
| 201 | over another video: |
| 202 | @example |
| 203 | ffmpeg -i input.mp4 -ignore_loop 0 -i input.gif -filter_complex overlay=shortest=1 out.mkv |
| 204 | @end example |
| 205 | |
| 206 | Note that in the above example the shortest option for overlay filter is |
| 207 | used to end the output video at the length of the shortest input file, |
| 208 | which in this case is @file{input.mp4} as the GIF in this example loops |
| 209 | infinitely. |
| 210 | |
| 211 | @section image2 |
| 212 | |
| 213 | Image file demuxer. |
| 214 | |
| 215 | This demuxer reads from a list of image files specified by a pattern. |
| 216 | The syntax and meaning of the pattern is specified by the |
| 217 | option @var{pattern_type}. |
| 218 | |
| 219 | The pattern may contain a suffix which is used to automatically |
| 220 | determine the format of the images contained in the files. |
| 221 | |
| 222 | The size, the pixel format, and the format of each image must be the |
| 223 | same for all the files in the sequence. |
| 224 | |
| 225 | This demuxer accepts the following options: |
| 226 | @table @option |
| 227 | @item framerate |
| 228 | Set the frame rate for the video stream. It defaults to 25. |
| 229 | @item loop |
| 230 | If set to 1, loop over the input. Default value is 0. |
| 231 | @item pattern_type |
| 232 | Select the pattern type used to interpret the provided filename. |
| 233 | |
| 234 | @var{pattern_type} accepts one of the following values. |
| 235 | @table @option |
| 236 | @item sequence |
| 237 | Select a sequence pattern type, used to specify a sequence of files |
| 238 | indexed by sequential numbers. |
| 239 | |
| 240 | A sequence pattern may contain the string "%d" or "%0@var{N}d", which |
| 241 | specifies the position of the characters representing a sequential |
| 242 | number in each filename matched by the pattern. If the form |
| 243 | "%d0@var{N}d" is used, the string representing the number in each |
| 244 | filename is 0-padded and @var{N} is the total number of 0-padded |
| 245 | digits representing the number. The literal character '%' can be |
| 246 | specified in the pattern with the string "%%". |
| 247 | |
| 248 | If the sequence pattern contains "%d" or "%0@var{N}d", the first filename of |
| 249 | the file list specified by the pattern must contain a number |
| 250 | inclusively contained between @var{start_number} and |
| 251 | @var{start_number}+@var{start_number_range}-1, and all the following |
| 252 | numbers must be sequential. |
| 253 | |
| 254 | For example the pattern "img-%03d.bmp" will match a sequence of |
| 255 | filenames of the form @file{img-001.bmp}, @file{img-002.bmp}, ..., |
| 256 | @file{img-010.bmp}, etc.; the pattern "i%%m%%g-%d.jpg" will match a |
| 257 | sequence of filenames of the form @file{i%m%g-1.jpg}, |
| 258 | @file{i%m%g-2.jpg}, ..., @file{i%m%g-10.jpg}, etc. |
| 259 | |
| 260 | Note that the pattern must not necessarily contain "%d" or |
| 261 | "%0@var{N}d", for example to convert a single image file |
| 262 | @file{img.jpeg} you can employ the command: |
| 263 | @example |
| 264 | ffmpeg -i img.jpeg img.png |
| 265 | @end example |
| 266 | |
| 267 | @item glob |
| 268 | Select a glob wildcard pattern type. |
| 269 | |
| 270 | The pattern is interpreted like a @code{glob()} pattern. This is only |
| 271 | selectable if libavformat was compiled with globbing support. |
| 272 | |
| 273 | @item glob_sequence @emph{(deprecated, will be removed)} |
| 274 | Select a mixed glob wildcard/sequence pattern. |
| 275 | |
| 276 | If your version of libavformat was compiled with globbing support, and |
| 277 | the provided pattern contains at least one glob meta character among |
| 278 | @code{%*?[]@{@}} that is preceded by an unescaped "%", the pattern is |
| 279 | interpreted like a @code{glob()} pattern, otherwise it is interpreted |
| 280 | like a sequence pattern. |
| 281 | |
| 282 | All glob special characters @code{%*?[]@{@}} must be prefixed |
| 283 | with "%". To escape a literal "%" you shall use "%%". |
| 284 | |
| 285 | For example the pattern @code{foo-%*.jpeg} will match all the |
| 286 | filenames prefixed by "foo-" and terminating with ".jpeg", and |
| 287 | @code{foo-%?%?%?.jpeg} will match all the filenames prefixed with |
| 288 | "foo-", followed by a sequence of three characters, and terminating |
| 289 | with ".jpeg". |
| 290 | |
| 291 | This pattern type is deprecated in favor of @var{glob} and |
| 292 | @var{sequence}. |
| 293 | @end table |
| 294 | |
| 295 | Default value is @var{glob_sequence}. |
| 296 | @item pixel_format |
| 297 | Set the pixel format of the images to read. If not specified the pixel |
| 298 | format is guessed from the first image file in the sequence. |
| 299 | @item start_number |
| 300 | Set the index of the file matched by the image file pattern to start |
| 301 | to read from. Default value is 0. |
| 302 | @item start_number_range |
| 303 | Set the index interval range to check when looking for the first image |
| 304 | file in the sequence, starting from @var{start_number}. Default value |
| 305 | is 5. |
| 306 | @item ts_from_file |
| 307 | If set to 1, will set frame timestamp to modification time of image file. Note |
| 308 | that monotonity of timestamps is not provided: images go in the same order as |
| 309 | without this option. Default value is 0. |
| 310 | If set to 2, will set frame timestamp to the modification time of the image file in |
| 311 | nanosecond precision. |
| 312 | @item video_size |
| 313 | Set the video size of the images to read. If not specified the video |
| 314 | size is guessed from the first image file in the sequence. |
| 315 | @end table |
| 316 | |
| 317 | @subsection Examples |
| 318 | |
| 319 | @itemize |
| 320 | @item |
| 321 | Use @command{ffmpeg} for creating a video from the images in the file |
| 322 | sequence @file{img-001.jpeg}, @file{img-002.jpeg}, ..., assuming an |
| 323 | input frame rate of 10 frames per second: |
| 324 | @example |
| 325 | ffmpeg -framerate 10 -i 'img-%03d.jpeg' out.mkv |
| 326 | @end example |
| 327 | |
| 328 | @item |
| 329 | As above, but start by reading from a file with index 100 in the sequence: |
| 330 | @example |
| 331 | ffmpeg -framerate 10 -start_number 100 -i 'img-%03d.jpeg' out.mkv |
| 332 | @end example |
| 333 | |
| 334 | @item |
| 335 | Read images matching the "*.png" glob pattern , that is all the files |
| 336 | terminating with the ".png" suffix: |
| 337 | @example |
| 338 | ffmpeg -framerate 10 -pattern_type glob -i "*.png" out.mkv |
| 339 | @end example |
| 340 | @end itemize |
| 341 | |
| 342 | @section mpegts |
| 343 | |
| 344 | MPEG-2 transport stream demuxer. |
| 345 | |
| 346 | @table @option |
| 347 | |
| 348 | @item fix_teletext_pts |
| 349 | Overrides teletext packet PTS and DTS values with the timestamps calculated |
| 350 | from the PCR of the first program which the teletext stream is part of and is |
| 351 | not discarded. Default value is 1, set this option to 0 if you want your |
| 352 | teletext packet PTS and DTS values untouched. |
| 353 | @end table |
| 354 | |
| 355 | @section rawvideo |
| 356 | |
| 357 | Raw video demuxer. |
| 358 | |
| 359 | This demuxer allows one to read raw video data. Since there is no header |
| 360 | specifying the assumed video parameters, the user must specify them |
| 361 | in order to be able to decode the data correctly. |
| 362 | |
| 363 | This demuxer accepts the following options: |
| 364 | @table @option |
| 365 | |
| 366 | @item framerate |
| 367 | Set input video frame rate. Default value is 25. |
| 368 | |
| 369 | @item pixel_format |
| 370 | Set the input video pixel format. Default value is @code{yuv420p}. |
| 371 | |
| 372 | @item video_size |
| 373 | Set the input video size. This value must be specified explicitly. |
| 374 | @end table |
| 375 | |
| 376 | For example to read a rawvideo file @file{input.raw} with |
| 377 | @command{ffplay}, assuming a pixel format of @code{rgb24}, a video |
| 378 | size of @code{320x240}, and a frame rate of 10 images per second, use |
| 379 | the command: |
| 380 | @example |
| 381 | ffplay -f rawvideo -pixel_format rgb24 -video_size 320x240 -framerate 10 input.raw |
| 382 | @end example |
| 383 | |
| 384 | @section sbg |
| 385 | |
| 386 | SBaGen script demuxer. |
| 387 | |
| 388 | This demuxer reads the script language used by SBaGen |
| 389 | @url{http://uazu.net/sbagen/} to generate binaural beats sessions. A SBG |
| 390 | script looks like that: |
| 391 | @example |
| 392 | -SE |
| 393 | a: 300-2.5/3 440+4.5/0 |
| 394 | b: 300-2.5/0 440+4.5/3 |
| 395 | off: - |
| 396 | NOW == a |
| 397 | +0:07:00 == b |
| 398 | +0:14:00 == a |
| 399 | +0:21:00 == b |
| 400 | +0:30:00 off |
| 401 | @end example |
| 402 | |
| 403 | A SBG script can mix absolute and relative timestamps. If the script uses |
| 404 | either only absolute timestamps (including the script start time) or only |
| 405 | relative ones, then its layout is fixed, and the conversion is |
| 406 | straightforward. On the other hand, if the script mixes both kind of |
| 407 | timestamps, then the @var{NOW} reference for relative timestamps will be |
| 408 | taken from the current time of day at the time the script is read, and the |
| 409 | script layout will be frozen according to that reference. That means that if |
| 410 | the script is directly played, the actual times will match the absolute |
| 411 | timestamps up to the sound controller's clock accuracy, but if the user |
| 412 | somehow pauses the playback or seeks, all times will be shifted accordingly. |
| 413 | |
| 414 | @section tedcaptions |
| 415 | |
| 416 | JSON captions used for @url{http://www.ted.com/, TED Talks}. |
| 417 | |
| 418 | TED does not provide links to the captions, but they can be guessed from the |
| 419 | page. The file @file{tools/bookmarklets.html} from the FFmpeg source tree |
| 420 | contains a bookmarklet to expose them. |
| 421 | |
| 422 | This demuxer accepts the following option: |
| 423 | @table @option |
| 424 | @item start_time |
| 425 | Set the start time of the TED talk, in milliseconds. The default is 15000 |
| 426 | (15s). It is used to sync the captions with the downloadable videos, because |
| 427 | they include a 15s intro. |
| 428 | @end table |
| 429 | |
| 430 | Example: convert the captions to a format most players understand: |
| 431 | @example |
| 432 | ffmpeg -i http://www.ted.com/talks/subtitles/id/1/lang/en talk1-en.srt |
| 433 | @end example |
| 434 | |
| 435 | @c man end DEMUXERS |