1 /* 2 * copyright (c) 2001 Fabrice Bellard 3 * 4 * This file is part of FFmpeg. 5 * 6 * FFmpeg is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * FFmpeg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with FFmpeg; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 module ffmpeg.libavformat.avformat; 21 22 import ffmpeg.libavformat.avio; 23 import ffmpeg.libavcodec; 24 import ffmpeg.libavutil; 25 import ffmpeg.libavdevice; 26 27 import core.stdc.stdio; 28 29 extern (C) @nogc nothrow: 30 31 /** 32 * @file 33 * @ingroup libavf 34 * Main libavformat public API header 35 */ 36 37 /** 38 * @defgroup libavf libavformat 39 * I/O and Muxing/Demuxing Library 40 * 41 * Libavformat (lavf) is a library for dealing with various media container 42 * formats. Its main two purposes are demuxing - i.e. splitting a media file 43 * into component streams, and the reverse process of muxing - writing supplied 44 * data in a specified container format. It also has an @ref lavf_io 45 * "I/O module" which supports a number of protocols for accessing the data (e.g. 46 * file, tcp, http and others). 47 * Unless you are absolutely sure you won't use libavformat's network 48 * capabilities, you should also call avformat_network_init(). 49 * 50 * A supported input format is described by an AVInputFormat struct, conversely 51 * an output format is described by AVOutputFormat. You can iterate over all 52 * input/output formats using the av_demuxer_iterate / av_muxer_iterate() functions. 53 * The protocols layer is not part of the public API, so you can only get the names 54 * of supported protocols with the avio_enum_protocols() function. 55 * 56 * Main lavf structure used for both muxing and demuxing is AVFormatContext, 57 * which exports all information about the file being read or written. As with 58 * most Libavformat structures, its size is not part of public ABI, so it cannot be 59 * allocated on stack or directly with av_malloc(). To create an 60 * AVFormatContext, use avformat_alloc_context() (some functions, like 61 * avformat_open_input() might do that for you). 62 * 63 * Most importantly an AVFormatContext contains: 64 * @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat 65 * "output" format. It is either autodetected or set by user for input; 66 * always set by user for output. 67 * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all 68 * elementary streams stored in the file. AVStreams are typically referred to 69 * using their index in this array. 70 * @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or 71 * set by user for input, always set by user for output (unless you are dealing 72 * with an AVFMT_NOFILE format). 73 * 74 * @section lavf_options Passing options to (de)muxers 75 * It is possible to configure lavf muxers and demuxers using the @ref avoptions 76 * mechanism. Generic (format-independent) libavformat options are provided by 77 * AVFormatContext, they can be examined from a user program by calling 78 * av_opt_next() / av_opt_find() on an allocated AVFormatContext (or its AVClass 79 * from avformat_get_class()). Private (format-specific) options are provided by 80 * AVFormatContext.priv_data if and only if AVInputFormat.priv_class / 81 * AVOutputFormat.priv_class of the corresponding format struct is non-NULL. 82 * Further options may be provided by the @ref AVFormatContext.pb "I/O context", 83 * if its AVClass is non-NULL, and the protocols layer. See the discussion on 84 * nesting in @ref avoptions documentation to learn how to access those. 85 * 86 * @section urls 87 * URL strings in libavformat are made of a scheme/protocol, a ':', and a 88 * scheme specific string. URLs without a scheme and ':' used for local files 89 * are supported but deprecated. "file:" should be used for local files. 90 * 91 * It is important that the scheme string is not taken from untrusted 92 * sources without checks. 93 * 94 * Note that some schemes/protocols are quite powerful, allowing access to 95 * both local and remote files, parts of them, concatenations of them, local 96 * audio and video devices and so on. 97 * 98 * @{ 99 * 100 * @defgroup lavf_decoding Demuxing 101 * @{ 102 * Demuxers read a media file and split it into chunks of data (@em packets). A 103 * @ref AVPacket "packet" contains one or more encoded frames which belongs to a 104 * single elementary stream. In the lavf API this process is represented by the 105 * avformat_open_input() function for opening a file, av_read_frame() for 106 * reading a single packet and finally avformat_close_input(), which does the 107 * cleanup. 108 * 109 * @section lavf_decoding_open Opening a media file 110 * The minimum information required to open a file is its URL, which 111 * is passed to avformat_open_input(), as in the following code: 112 * @code 113 * const char *url = "file:in.mp3"; 114 * AVFormatContext *s = NULL; 115 * int ret = avformat_open_input(&s, url, NULL, NULL); 116 * if (ret < 0) 117 * abort(); 118 * @endcode 119 * The above code attempts to allocate an AVFormatContext, open the 120 * specified file (autodetecting the format) and read the header, exporting the 121 * information stored there into s. Some formats do not have a header or do not 122 * store enough information there, so it is recommended that you call the 123 * avformat_find_stream_info() function which tries to read and decode a few 124 * frames to find missing information. 125 * 126 * In some cases you might want to preallocate an AVFormatContext yourself with 127 * avformat_alloc_context() and do some tweaking on it before passing it to 128 * avformat_open_input(). One such case is when you want to use custom functions 129 * for reading input data instead of lavf internal I/O layer. 130 * To do that, create your own AVIOContext with avio_alloc_context(), passing 131 * your reading callbacks to it. Then set the @em pb field of your 132 * AVFormatContext to newly created AVIOContext. 133 * 134 * Since the format of the opened file is in general not known until after 135 * avformat_open_input() has returned, it is not possible to set demuxer private 136 * options on a preallocated context. Instead, the options should be passed to 137 * avformat_open_input() wrapped in an AVDictionary: 138 * @code 139 * AVDictionary *options = NULL; 140 * av_dict_set(&options, "video_size", "640x480", 0); 141 * av_dict_set(&options, "pixel_format", "rgb24", 0); 142 * 143 * if (avformat_open_input(&s, url, NULL, &options) < 0) 144 * abort(); 145 * av_dict_free(&options); 146 * @endcode 147 * This code passes the private options 'video_size' and 'pixel_format' to the 148 * demuxer. They would be necessary for e.g. the rawvideo demuxer, since it 149 * cannot know how to interpret raw video data otherwise. If the format turns 150 * out to be something different than raw video, those options will not be 151 * recognized by the demuxer and therefore will not be applied. Such unrecognized 152 * options are then returned in the options dictionary (recognized options are 153 * consumed). The calling program can handle such unrecognized options as it 154 * wishes, e.g. 155 * @code 156 * AVDictionaryEntry *e; 157 * if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) { 158 * fprintf(stderr, "Option %s not recognized by the demuxer.\n", e->key); 159 * abort(); 160 * } 161 * @endcode 162 * 163 * After you have finished reading the file, you must close it with 164 * avformat_close_input(). It will free everything associated with the file. 165 * 166 * @section lavf_decoding_read Reading from an opened file 167 * Reading data from an opened AVFormatContext is done by repeatedly calling 168 * av_read_frame() on it. Each call, if successful, will return an AVPacket 169 * containing encoded data for one AVStream, identified by 170 * AVPacket.stream_index. This packet may be passed straight into the libavcodec 171 * decoding functions avcodec_send_packet() or avcodec_decode_subtitle2() if the 172 * caller wishes to decode the data. 173 * 174 * AVPacket.pts, AVPacket.dts and AVPacket.duration timing information will be 175 * set if known. They may also be unset (i.e. AV_NOPTS_VALUE for 176 * pts/dts, 0 for duration) if the stream does not provide them. The timing 177 * information will be in AVStream.time_base units, i.e. it has to be 178 * multiplied by the timebase to convert them to seconds. 179 * 180 * A packet returned by av_read_frame() is always reference-counted, 181 * i.e. AVPacket.buf is set and the user may keep it indefinitely. 182 * The packet must be freed with av_packet_unref() when it is no 183 * longer needed. 184 * 185 * @section lavf_decoding_seek Seeking 186 * @} 187 * 188 * @defgroup lavf_encoding Muxing 189 * @{ 190 * Muxers take encoded data in the form of @ref AVPacket "AVPackets" and write 191 * it into files or other output bytestreams in the specified container format. 192 * 193 * The main API functions for muxing are avformat_write_header() for writing the 194 * file header, av_write_frame() / av_interleaved_write_frame() for writing the 195 * packets and av_write_trailer() for finalizing the file. 196 * 197 * At the beginning of the muxing process, the caller must first call 198 * avformat_alloc_context() to create a muxing context. The caller then sets up 199 * the muxer by filling the various fields in this context: 200 * 201 * - The @ref AVFormatContext.oformat "oformat" field must be set to select the 202 * muxer that will be used. 203 * - Unless the format is of the AVFMT_NOFILE type, the @ref AVFormatContext.pb 204 * "pb" field must be set to an opened IO context, either returned from 205 * avio_open2() or a custom one. 206 * - Unless the format is of the AVFMT_NOSTREAMS type, at least one stream must 207 * be created with the avformat_new_stream() function. The caller should fill 208 * the @ref AVStream.codecpar "stream codec parameters" information, such as the 209 * codec @ref AVCodecParameters.codec_type "type", @ref AVCodecParameters.codec_id 210 * "id" and other parameters (e.g. width / height, the pixel or sample format, 211 * etc.) as known. The @ref AVStream.time_base "stream timebase" should 212 * be set to the timebase that the caller desires to use for this stream (note 213 * that the timebase actually used by the muxer can be different, as will be 214 * described later). 215 * - It is advised to manually initialize only the relevant fields in 216 * AVCodecParameters, rather than using @ref avcodec_parameters_copy() during 217 * remuxing: there is no guarantee that the codec context values remain valid 218 * for both input and output format contexts. 219 * - The caller may fill in additional information, such as @ref 220 * AVFormatContext.metadata "global" or @ref AVStream.metadata "per-stream" 221 * metadata, @ref AVFormatContext.chapters "chapters", @ref 222 * AVFormatContext.programs "programs", etc. as described in the 223 * AVFormatContext documentation. Whether such information will actually be 224 * stored in the output depends on what the container format and the muxer 225 * support. 226 * 227 * When the muxing context is fully set up, the caller must call 228 * avformat_write_header() to initialize the muxer internals and write the file 229 * header. Whether anything actually is written to the IO context at this step 230 * depends on the muxer, but this function must always be called. Any muxer 231 * private options must be passed in the options parameter to this function. 232 * 233 * The data is then sent to the muxer by repeatedly calling av_write_frame() or 234 * av_interleaved_write_frame() (consult those functions' documentation for 235 * discussion on the difference between them; only one of them may be used with 236 * a single muxing context, they should not be mixed). Do note that the timing 237 * information on the packets sent to the muxer must be in the corresponding 238 * AVStream's timebase. That timebase is set by the muxer (in the 239 * avformat_write_header() step) and may be different from the timebase 240 * requested by the caller. 241 * 242 * Once all the data has been written, the caller must call av_write_trailer() 243 * to flush any buffered packets and finalize the output file, then close the IO 244 * context (if any) and finally free the muxing context with 245 * avformat_free_context(). 246 * @} 247 * 248 * @defgroup lavf_io I/O Read/Write 249 * @{ 250 * @section lavf_io_dirlist Directory listing 251 * The directory listing API makes it possible to list files on remote servers. 252 * 253 * Some of possible use cases: 254 * - an "open file" dialog to choose files from a remote location, 255 * - a recursive media finder providing a player with an ability to play all 256 * files from a given directory. 257 * 258 * @subsection lavf_io_dirlist_open Opening a directory 259 * At first, a directory needs to be opened by calling avio_open_dir() 260 * supplied with a URL and, optionally, ::AVDictionary containing 261 * protocol-specific parameters. The function returns zero or positive 262 * integer and allocates AVIODirContext on success. 263 * 264 * @code 265 * AVIODirContext *ctx = NULL; 266 * if (avio_open_dir(&ctx, "smb://example.com/some_dir", NULL) < 0) { 267 * fprintf(stderr, "Cannot open directory.\n"); 268 * abort(); 269 * } 270 * @endcode 271 * 272 * This code tries to open a sample directory using smb protocol without 273 * any additional parameters. 274 * 275 * @subsection lavf_io_dirlist_read Reading entries 276 * Each directory's entry (i.e. file, another directory, anything else 277 * within ::AVIODirEntryType) is represented by AVIODirEntry. 278 * Reading consecutive entries from an opened AVIODirContext is done by 279 * repeatedly calling avio_read_dir() on it. Each call returns zero or 280 * positive integer if successful. Reading can be stopped right after the 281 * NULL entry has been read -- it means there are no entries left to be 282 * read. The following code reads all entries from a directory associated 283 * with ctx and prints their names to standard output. 284 * @code 285 * AVIODirEntry *entry = NULL; 286 * for (;;) { 287 * if (avio_read_dir(ctx, &entry) < 0) { 288 * fprintf(stderr, "Cannot list directory.\n"); 289 * abort(); 290 * } 291 * if (!entry) 292 * break; 293 * printf("%s\n", entry->name); 294 * avio_free_directory_entry(&entry); 295 * } 296 * @endcode 297 * @} 298 * 299 * @defgroup lavf_codec Demuxers 300 * @{ 301 * @defgroup lavf_codec_native Native Demuxers 302 * @{ 303 * @} 304 * @defgroup lavf_codec_wrappers External library wrappers 305 * @{ 306 * @} 307 * @} 308 * @defgroup lavf_protos I/O Protocols 309 * @{ 310 * @} 311 * @defgroup lavf_internal Internal 312 * @{ 313 * @} 314 * @} 315 */ 316 317 /* FILE */ 318 319 /** 320 * @defgroup metadata_api Public Metadata API 321 * @{ 322 * @ingroup libavf 323 * The metadata API allows libavformat to export metadata tags to a client 324 * application when demuxing. Conversely it allows a client application to 325 * set metadata when muxing. 326 * 327 * Metadata is exported or set as pairs of key/value strings in the 'metadata' 328 * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs 329 * using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg, 330 * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata 331 * exported by demuxers isn't checked to be valid UTF-8 in most cases. 332 * 333 * Important concepts to keep in mind: 334 * - Keys are unique; there can never be 2 tags with the same key. This is 335 * also meant semantically, i.e., a demuxer should not knowingly produce 336 * several keys that are literally different but semantically identical. 337 * E.g., key=Author5, key=Author6. In this example, all authors must be 338 * placed in the same tag. 339 * - Metadata is flat, not hierarchical; there are no subtags. If you 340 * want to store, e.g., the email address of the child of producer Alice 341 * and actor Bob, that could have key=alice_and_bobs_childs_email_address. 342 * - Several modifiers can be applied to the tag name. This is done by 343 * appending a dash character ('-') and the modifier name in the order 344 * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng. 345 * - language -- a tag whose value is localized for a particular language 346 * is appended with the ISO 639-2/B 3-letter language code. 347 * For example: Author-ger=Michael, Author-eng=Mike 348 * The original/default language is in the unqualified "Author" tag. 349 * A demuxer should set a default if it sets any translated tag. 350 * - sorting -- a modified version of a tag that should be used for 351 * sorting will have '-sort' appended. E.g. artist="The Beatles", 352 * artist-sort="Beatles, The". 353 * - Some protocols and demuxers support metadata updates. After a successful 354 * call to av_read_frame(), AVFormatContext.event_flags or AVStream.event_flags 355 * will be updated to indicate if metadata changed. In order to detect metadata 356 * changes on a stream, you need to loop through all streams in the AVFormatContext 357 * and check their individual event_flags. 358 * 359 * - Demuxers attempt to export metadata in a generic format, however tags 360 * with no generic equivalents are left as they are stored in the container. 361 * Follows a list of generic tag names: 362 * 363 @verbatim 364 album -- name of the set this work belongs to 365 album_artist -- main creator of the set/album, if different from artist. 366 e.g. "Various Artists" for compilation albums. 367 artist -- main creator of the work 368 comment -- any additional description of the file. 369 composer -- who composed the work, if different from artist. 370 copyright -- name of copyright holder. 371 creation_time-- date when the file was created, preferably in ISO 8601. 372 date -- date when the work was created, preferably in ISO 8601. 373 disc -- number of a subset, e.g. disc in a multi-disc collection. 374 encoder -- name/settings of the software/hardware that produced the file. 375 encoded_by -- person/group who created the file. 376 filename -- original name of the file. 377 genre -- <self-evident>. 378 language -- main language in which the work is performed, preferably 379 in ISO 639-2 format. Multiple languages can be specified by 380 separating them with commas. 381 performer -- artist who performed the work, if different from artist. 382 E.g for "Also sprach Zarathustra", artist would be "Richard 383 Strauss" and performer "London Philharmonic Orchestra". 384 publisher -- name of the label/publisher. 385 service_name -- name of the service in broadcasting (channel name). 386 service_provider -- name of the service provider in broadcasting. 387 title -- name of the work. 388 track -- number of this work in the set, can be in form current/total. 389 variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of 390 @endverbatim 391 * 392 * Look in the examples section for an application example how to use the Metadata API. 393 * 394 * @} 395 */ 396 397 /* packet functions */ 398 399 /** 400 * Allocate and read the payload of a packet and initialize its 401 * fields with default values. 402 * 403 * @param s associated IO context 404 * @param pkt packet 405 * @param size desired payload size 406 * @return >0 (read size) if OK, AVERROR_xxx otherwise 407 */ 408 int av_get_packet (AVIOContext* s, AVPacket* pkt, int size); 409 410 /** 411 * Read data and append it to the current content of the AVPacket. 412 * If pkt->size is 0 this is identical to av_get_packet. 413 * Note that this uses av_grow_packet and thus involves a realloc 414 * which is inefficient. Thus this function should only be used 415 * when there is no reasonable way to know (an upper bound of) 416 * the final size. 417 * 418 * @param s associated IO context 419 * @param pkt packet 420 * @param size amount of data to read 421 * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data 422 * will not be lost even if an error occurs. 423 */ 424 int av_append_packet (AVIOContext* s, AVPacket* pkt, int size); 425 426 /*************************************************/ 427 /* input/output formats */ 428 429 struct AVCodecTag; 430 431 /** 432 * This structure contains the data a format has to probe a file. 433 */ 434 struct AVProbeData 435 { 436 const(char)* filename; 437 ubyte* buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */ 438 int buf_size; /**< Size of buf except extra allocated bytes */ 439 const(char)* mime_type; /**< mime_type, when known. */ 440 } 441 442 enum AVPROBE_SCORE_RETRY = AVPROBE_SCORE_MAX / 4; 443 enum AVPROBE_SCORE_STREAM_RETRY = AVPROBE_SCORE_MAX / 4 - 1; 444 445 enum AVPROBE_SCORE_EXTENSION = 50; ///< score for file extension 446 enum AVPROBE_SCORE_MIME = 75; ///< score for file mime type 447 enum AVPROBE_SCORE_MAX = 100; ///< maximum score 448 449 enum AVPROBE_PADDING_SIZE = 32; ///< extra allocated bytes at the end of the probe buffer 450 451 /// Demuxer will use avio_open, no opened file should be provided by the caller. 452 enum AVFMT_NOFILE = 0x0001; 453 enum AVFMT_NEEDNUMBER = 0x0002; /**< Needs '%d' in filename. */ 454 enum AVFMT_SHOW_IDS = 0x0008; /**< Show format stream IDs numbers. */ 455 enum AVFMT_GLOBALHEADER = 0x0040; /**< Format wants global header. */ 456 enum AVFMT_NOTIMESTAMPS = 0x0080; /**< Format does not need / have any timestamps. */ 457 enum AVFMT_GENERIC_INDEX = 0x0100; /**< Use generic index building code. */ 458 enum AVFMT_TS_DISCONT = 0x0200; /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */ 459 enum AVFMT_VARIABLE_FPS = 0x0400; /**< Format allows variable fps. */ 460 enum AVFMT_NODIMENSIONS = 0x0800; /**< Format does not need width/height */ 461 enum AVFMT_NOSTREAMS = 0x1000; /**< Format does not require any streams */ 462 enum AVFMT_NOBINSEARCH = 0x2000; /**< Format does not allow to fall back on binary search via read_timestamp */ 463 enum AVFMT_NOGENSEARCH = 0x4000; /**< Format does not allow to fall back on generic search */ 464 enum AVFMT_NO_BYTE_SEEK = 0x8000; /**< Format does not allow seeking by bytes */ 465 enum AVFMT_ALLOW_FLUSH = 0x10000; /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */ 466 enum AVFMT_TS_NONSTRICT = 0x20000; /**< Format does not require strictly 467 increasing timestamps, but they must 468 still be monotonic */ 469 enum AVFMT_TS_NEGATIVE = 0x40000; /**< Format allows muxing negative 470 timestamps. If not set the timestamp 471 will be shifted in av_write_frame and 472 av_interleaved_write_frame so they 473 start from 0. 474 The user or muxer can override this through 475 AVFormatContext.avoid_negative_ts 476 */ 477 478 enum AVFMT_SEEK_TO_PTS = 0x4000000; /**< Seeking is based on PTS */ 479 480 /** 481 * @addtogroup lavf_encoding 482 * @{ 483 */ 484 struct AVOutputFormat 485 { 486 const(char)* name; 487 /** 488 * Descriptive name for the format, meant to be more human-readable 489 * than name. You should use the NULL_IF_CONFIG_SMALL() macro 490 * to define it. 491 */ 492 const(char)* long_name; 493 const(char)* mime_type; 494 const(char)* extensions; /**< comma-separated filename extensions */ 495 /* output support */ 496 AVCodecID audio_codec; /**< default audio codec */ 497 AVCodecID video_codec; /**< default video codec */ 498 AVCodecID subtitle_codec; /**< default subtitle codec */ 499 /** 500 * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, 501 * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, 502 * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, 503 * AVFMT_TS_NONSTRICT, AVFMT_TS_NEGATIVE 504 */ 505 int flags; 506 507 /** 508 * List of supported codec_id-codec_tag pairs, ordered by "better 509 * choice first". The arrays are all terminated by AV_CODEC_ID_NONE. 510 */ 511 const(AVCodecTag*)* codec_tag; 512 513 const(AVClass)* priv_class; ///< AVClass for the private context 514 515 /***************************************************************** 516 * No fields below this line are part of the public API. They 517 * may not be used outside of libavformat and can be changed and 518 * removed at will. 519 * New public fields should be added right above. 520 ***************************************************************** 521 */ 522 /** 523 * The ff_const59 define is not part of the public API and will 524 * be removed without further warning. 525 */ 526 527 AVOutputFormat* next; 528 529 /** 530 * size of private data so that it can be allocated in the wrapper 531 */ 532 int priv_data_size; 533 534 int function (AVFormatContext*) write_header; 535 /** 536 * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags, 537 * pkt can be NULL in order to flush data buffered in the muxer. 538 * When flushing, return 0 if there still is more data to flush, 539 * or 1 if everything was flushed and there is no more buffered 540 * data. 541 */ 542 int function (AVFormatContext*, AVPacket* pkt) write_packet; 543 int function (AVFormatContext*) write_trailer; 544 /** 545 * A format-specific function for interleavement. 546 * If unset, packets will be interleaved by dts. 547 */ 548 int function ( 549 AVFormatContext*, 550 AVPacket* out_, 551 AVPacket* in_, 552 int flush) interleave_packet; 553 /** 554 * Test if the given codec can be stored in this container. 555 * 556 * @return 1 if the codec is supported, 0 if it is not. 557 * A negative number if unknown. 558 * MKTAG('A', 'P', 'I', 'C') if the codec is only supported as AV_DISPOSITION_ATTACHED_PIC 559 */ 560 int function (AVCodecID id, int std_compliance) query_codec; 561 562 void function ( 563 AVFormatContext* s, 564 int stream, 565 long* dts, 566 long* wall) get_output_timestamp; 567 /** 568 * Allows sending messages from application to device. 569 */ 570 int function ( 571 AVFormatContext* s, 572 int type, 573 void* data, 574 size_t data_size) control_message; 575 576 /** 577 * Write an uncoded AVFrame. 578 * 579 * See av_write_uncoded_frame() for details. 580 * 581 * The library will free *frame afterwards, but the muxer can prevent it 582 * by setting the pointer to NULL. 583 */ 584 int function ( 585 AVFormatContext*, 586 int stream_index, 587 AVFrame** frame, 588 uint flags) write_uncoded_frame; 589 /** 590 * Returns device list with it properties. 591 * @see avdevice_list_devices() for more details. 592 */ 593 int function (AVFormatContext* s, AVDeviceInfoList* device_list) get_device_list; 594 595 /** 596 * Initialize device capabilities submodule. 597 * @see avdevice_capabilities_create() for more details. 598 */ 599 int function (AVFormatContext* s, AVDeviceCapabilitiesQuery* caps) create_device_capabilities; 600 /** 601 * Free device capabilities submodule. 602 * @see avdevice_capabilities_free() for more details. 603 */ 604 int function (AVFormatContext* s, AVDeviceCapabilitiesQuery* caps) free_device_capabilities; 605 606 AVCodecID data_codec; /**< default data codec */ 607 /** 608 * Initialize format. May allocate data here, and set any AVFormatContext or 609 * AVStream parameters that need to be set before packets are sent. 610 * This method must not write output. 611 * 612 * Return 0 if streams were fully configured, 1 if not, negative AVERROR on failure 613 * 614 * Any allocations made here must be freed in deinit(). 615 */ 616 int function (AVFormatContext*) init; 617 /** 618 * Deinitialize format. If present, this is called whenever the muxer is being 619 * destroyed, regardless of whether or not the header has been written. 620 * 621 * If a trailer is being written, this is called after write_trailer(). 622 * 623 * This is called if init() fails as well. 624 */ 625 void function (AVFormatContext*) deinit; 626 /** 627 * Set up any necessary bitstream filtering and extract any extra data needed 628 * for the global header. 629 * Return 0 if more packets from this stream must be checked; 1 if not. 630 */ 631 int function (AVFormatContext*, const(AVPacket)* pkt) check_bitstream; 632 } 633 634 /** 635 * @} 636 */ 637 638 /** 639 * @addtogroup lavf_decoding 640 * @{ 641 */ 642 struct AVInputFormat 643 { 644 /** 645 * A comma separated list of short names for the format. New names 646 * may be appended with a minor bump. 647 */ 648 const(char)* name; 649 650 /** 651 * Descriptive name for the format, meant to be more human-readable 652 * than name. You should use the NULL_IF_CONFIG_SMALL() macro 653 * to define it. 654 */ 655 const(char)* long_name; 656 657 /** 658 * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, 659 * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, 660 * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS. 661 */ 662 int flags; 663 664 /** 665 * If extensions are defined, then no probe is done. You should 666 * usually not use extension format guessing because it is not 667 * reliable enough 668 */ 669 const(char)* extensions; 670 671 const(AVCodecTag*)* codec_tag; 672 673 const(AVClass)* priv_class; ///< AVClass for the private context 674 675 /** 676 * Comma-separated list of mime types. 677 * It is used check for matching mime types while probing. 678 * @see av_probe_input_format2 679 */ 680 const(char)* mime_type; 681 682 /***************************************************************** 683 * No fields below this line are part of the public API. They 684 * may not be used outside of libavformat and can be changed and 685 * removed at will. 686 * New public fields should be added right above. 687 ***************************************************************** 688 */ 689 690 AVInputFormat* next; 691 692 /** 693 * Raw demuxers store their codec ID here. 694 */ 695 int raw_codec_id; 696 697 /** 698 * Size of private data so that it can be allocated in the wrapper. 699 */ 700 int priv_data_size; 701 702 /** 703 * Tell if a given file has a chance of being parsed as this format. 704 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes 705 * big so you do not have to check for that unless you need more. 706 */ 707 int function (const(AVProbeData)*) read_probe; 708 709 /** 710 * Read the format header and initialize the AVFormatContext 711 * structure. Return 0 if OK. 'avformat_new_stream' should be 712 * called to create new streams. 713 */ 714 int function (AVFormatContext*) read_header; 715 716 /** 717 * Read one packet and put it in 'pkt'. pts and flags are also 718 * set. 'avformat_new_stream' can be called only if the flag 719 * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a 720 * background thread). 721 * @return 0 on success, < 0 on error. 722 * Upon returning an error, pkt must be unreferenced by the caller. 723 */ 724 int function (AVFormatContext*, AVPacket* pkt) read_packet; 725 726 /** 727 * Close the stream. The AVFormatContext and AVStreams are not 728 * freed by this function 729 */ 730 int function (AVFormatContext*) read_close; 731 732 /** 733 * Seek to a given timestamp relative to the frames in 734 * stream component stream_index. 735 * @param stream_index Must not be -1. 736 * @param flags Selects which direction should be preferred if no exact 737 * match is available. 738 * @return >= 0 on success (but not necessarily the new offset) 739 */ 740 int function ( 741 AVFormatContext*, 742 int stream_index, 743 long timestamp, 744 int flags) read_seek; 745 746 /** 747 * Get the next timestamp in stream[stream_index].time_base units. 748 * @return the timestamp or AV_NOPTS_VALUE if an error occurred 749 */ 750 long function ( 751 AVFormatContext* s, 752 int stream_index, 753 long* pos, 754 long pos_limit) read_timestamp; 755 756 /** 757 * Start/resume playing - only meaningful if using a network-based format 758 * (RTSP). 759 */ 760 int function (AVFormatContext*) read_play; 761 762 /** 763 * Pause playing - only meaningful if using a network-based format 764 * (RTSP). 765 */ 766 int function (AVFormatContext*) read_pause; 767 768 /** 769 * Seek to timestamp ts. 770 * Seeking will be done so that the point from which all active streams 771 * can be presented successfully will be closest to ts and within min/max_ts. 772 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL. 773 */ 774 int function (AVFormatContext* s, int stream_index, long min_ts, long ts, long max_ts, int flags) read_seek2; 775 776 /** 777 * Returns device list with it properties. 778 * @see avdevice_list_devices() for more details. 779 */ 780 int function (AVFormatContext* s, AVDeviceInfoList* device_list) get_device_list; 781 782 /** 783 * Initialize device capabilities submodule. 784 * @see avdevice_capabilities_create() for more details. 785 */ 786 int function (AVFormatContext* s, AVDeviceCapabilitiesQuery* caps) create_device_capabilities; 787 788 /** 789 * Free device capabilities submodule. 790 * @see avdevice_capabilities_free() for more details. 791 */ 792 int function (AVFormatContext* s, AVDeviceCapabilitiesQuery* caps) free_device_capabilities; 793 } 794 795 /** 796 * @} 797 */ 798 799 enum AVStreamParseType 800 { 801 AVSTREAM_PARSE_NONE = 0, 802 AVSTREAM_PARSE_FULL = 1, /**< full parsing and repack */ 803 AVSTREAM_PARSE_HEADERS = 2, /**< Only parse headers, do not repack. */ 804 AVSTREAM_PARSE_TIMESTAMPS = 3, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */ 805 AVSTREAM_PARSE_FULL_ONCE = 4, /**< full parsing and repack of the first frame only, only implemented for H.264 currently */ 806 AVSTREAM_PARSE_FULL_RAW = 5 /**< full parsing and repack with timestamp and position generation by parser for raw 807 this assumes that each packet in the file contains no demuxer level headers and 808 just codec level data, otherwise position generation would fail */ 809 } 810 811 struct AVIndexEntry 812 { 813 import std.bitmanip : bitfields; 814 815 long pos; 816 long timestamp; 817 818 mixin(bitfields!( 819 int, "flags", 2, 820 int, "size", 30)); /**< 821 * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available 822 * when seeking to this entry. That means preferable PTS on keyframe based formats. 823 * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better 824 * is known 825 */ 826 827 /** 828 * Flag is used to indicate which frame should be discarded after decoding. 829 */ 830 831 //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment). 832 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */ 833 } 834 835 enum AVINDEX_KEYFRAME = 0x0001; 836 enum AVINDEX_DISCARD_FRAME = 0x0002; 837 838 enum AV_DISPOSITION_DEFAULT = 0x0001; 839 enum AV_DISPOSITION_DUB = 0x0002; 840 enum AV_DISPOSITION_ORIGINAL = 0x0004; 841 enum AV_DISPOSITION_COMMENT = 0x0008; 842 enum AV_DISPOSITION_LYRICS = 0x0010; 843 enum AV_DISPOSITION_KARAOKE = 0x0020; 844 845 /** 846 * Track should be used during playback by default. 847 * Useful for subtitle track that should be displayed 848 * even when user did not explicitly ask for subtitles. 849 */ 850 enum AV_DISPOSITION_FORCED = 0x0040; 851 enum AV_DISPOSITION_HEARING_IMPAIRED = 0x0080; /**< stream for hearing impaired audiences */ 852 enum AV_DISPOSITION_VISUAL_IMPAIRED = 0x0100; /**< stream for visual impaired audiences */ 853 enum AV_DISPOSITION_CLEAN_EFFECTS = 0x0200; /**< stream without voice */ 854 /** 855 * The stream is stored in the file as an attached picture/"cover art" (e.g. 856 * APIC frame in ID3v2). The first (usually only) packet associated with it 857 * will be returned among the first few packets read from the file unless 858 * seeking takes place. It can also be accessed at any time in 859 * AVStream.attached_pic. 860 */ 861 enum AV_DISPOSITION_ATTACHED_PIC = 0x0400; 862 /** 863 * The stream is sparse, and contains thumbnail images, often corresponding 864 * to chapter markers. Only ever used with AV_DISPOSITION_ATTACHED_PIC. 865 */ 866 enum AV_DISPOSITION_TIMED_THUMBNAILS = 0x0800; 867 868 struct AVStreamInternal; 869 870 /** 871 * To specify text track kind (different from subtitles default). 872 */ 873 enum AV_DISPOSITION_CAPTIONS = 0x10000; 874 enum AV_DISPOSITION_DESCRIPTIONS = 0x20000; 875 enum AV_DISPOSITION_METADATA = 0x40000; 876 enum AV_DISPOSITION_DEPENDENT = 0x80000; ///< dependent audio stream (mix_type=0 in mpegts) 877 enum AV_DISPOSITION_STILL_IMAGE = 0x100000; ///< still images in video stream (still_picture_flag=1 in mpegts) 878 879 /** 880 * Options for behavior on timestamp wrap detection. 881 */ 882 enum AV_PTS_WRAP_IGNORE = 0; ///< ignore the wrap 883 enum AV_PTS_WRAP_ADD_OFFSET = 1; ///< add the format specific offset on wrap detection 884 enum AV_PTS_WRAP_SUB_OFFSET = -1; ///< subtract the format specific offset on wrap detection 885 886 /** 887 * Stream structure. 888 * New fields can be added to the end with minor version bumps. 889 * Removal, reordering and changes to existing fields require a major 890 * version bump. 891 * sizeof(AVStream) must not be used outside libav*. 892 */ 893 struct AVStream 894 { 895 int index; /**< stream index in AVFormatContext */ 896 /** 897 * Format-specific stream ID. 898 * decoding: set by libavformat 899 * encoding: set by the user, replaced by libavformat if left unset 900 */ 901 int id; 902 903 /** 904 * @deprecated use the codecpar struct instead 905 */ 906 AVCodecContext* codec; 907 908 void* priv_data; 909 910 /** 911 * This is the fundamental unit of time (in seconds) in terms 912 * of which frame timestamps are represented. 913 * 914 * decoding: set by libavformat 915 * encoding: May be set by the caller before avformat_write_header() to 916 * provide a hint to the muxer about the desired timebase. In 917 * avformat_write_header(), the muxer will overwrite this field 918 * with the timebase that will actually be used for the timestamps 919 * written into the file (which may or may not be related to the 920 * user-provided one, depending on the format). 921 */ 922 AVRational time_base; 923 924 /** 925 * Decoding: pts of the first frame of the stream in presentation order, in stream time base. 926 * Only set this if you are absolutely 100% sure that the value you set 927 * it to really is the pts of the first frame. 928 * This may be undefined (AV_NOPTS_VALUE). 929 * @note The ASF header does NOT contain a correct start_time the ASF 930 * demuxer must NOT set this. 931 */ 932 long start_time; 933 934 /** 935 * Decoding: duration of the stream, in stream time base. 936 * If a source file does not specify a duration, but does specify 937 * a bitrate, this value will be estimated from bitrate and file size. 938 * 939 * Encoding: May be set by the caller before avformat_write_header() to 940 * provide a hint to the muxer about the estimated duration. 941 */ 942 long duration; 943 944 long nb_frames; ///< number of frames in this stream if known or 0 945 946 int disposition; /**< AV_DISPOSITION_* bit field */ 947 948 AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed. 949 950 /** 951 * sample aspect ratio (0 if unknown) 952 * - encoding: Set by user. 953 * - decoding: Set by libavformat. 954 */ 955 AVRational sample_aspect_ratio; 956 957 AVDictionary* metadata; 958 959 /** 960 * Average framerate 961 * 962 * - demuxing: May be set by libavformat when creating the stream or in 963 * avformat_find_stream_info(). 964 * - muxing: May be set by the caller before avformat_write_header(). 965 */ 966 AVRational avg_frame_rate; 967 968 /** 969 * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet 970 * will contain the attached picture. 971 * 972 * decoding: set by libavformat, must not be modified by the caller. 973 * encoding: unused 974 */ 975 AVPacket attached_pic; 976 977 /** 978 * An array of side data that applies to the whole stream (i.e. the 979 * container does not allow it to change between packets). 980 * 981 * There may be no overlap between the side data in this array and side data 982 * in the packets. I.e. a given side data is either exported by the muxer 983 * (demuxing) / set by the caller (muxing) in this array, then it never 984 * appears in the packets, or the side data is exported / sent through 985 * the packets (always in the first packet where the value becomes known or 986 * changes), then it does not appear in this array. 987 * 988 * - demuxing: Set by libavformat when the stream is created. 989 * - muxing: May be set by the caller before avformat_write_header(). 990 * 991 * Freed by libavformat in avformat_free_context(). 992 * 993 * @see av_format_inject_global_side_data() 994 */ 995 AVPacketSideData* side_data; 996 /** 997 * The number of elements in the AVStream.side_data array. 998 */ 999 int nb_side_data; 1000 1001 /** 1002 * Flags indicating events happening on the stream, a combination of 1003 * AVSTREAM_EVENT_FLAG_*. 1004 * 1005 * - demuxing: may be set by the demuxer in avformat_open_input(), 1006 * avformat_find_stream_info() and av_read_frame(). Flags must be cleared 1007 * by the user once the event has been handled. 1008 * - muxing: may be set by the user after avformat_write_header(). to 1009 * indicate a user-triggered event. The muxer will clear the flags for 1010 * events it has handled in av_[interleaved]_write_frame(). 1011 */ 1012 int event_flags; 1013 /** 1014 * - demuxing: the demuxer read new metadata from the file and updated 1015 * AVStream.metadata accordingly 1016 * - muxing: the user updated AVStream.metadata and wishes the muxer to write 1017 * it into the file 1018 */ 1019 1020 /** 1021 * - demuxing: new packets for this stream were read from the file. This 1022 * event is informational only and does not guarantee that new packets 1023 * for this stream will necessarily be returned from av_read_frame(). 1024 */ 1025 1026 /** 1027 * Real base framerate of the stream. 1028 * This is the lowest framerate with which all timestamps can be 1029 * represented accurately (it is the least common multiple of all 1030 * framerates in the stream). Note, this value is just a guess! 1031 * For example, if the time base is 1/90000 and all frames have either 1032 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1. 1033 */ 1034 AVRational r_frame_rate; 1035 1036 /** 1037 * String containing pairs of key and values describing recommended encoder configuration. 1038 * Pairs are separated by ','. 1039 * Keys are separated from values by '='. 1040 * 1041 * @deprecated unused 1042 */ 1043 char* recommended_encoder_configuration; 1044 1045 /** 1046 * Codec parameters associated with this stream. Allocated and freed by 1047 * libavformat in avformat_new_stream() and avformat_free_context() 1048 * respectively. 1049 * 1050 * - demuxing: filled by libavformat on stream creation or in 1051 * avformat_find_stream_info() 1052 * - muxing: filled by the caller before avformat_write_header() 1053 */ 1054 AVCodecParameters* codecpar; 1055 1056 /***************************************************************** 1057 * All fields below this line are not part of the public API. They 1058 * may not be used outside of libavformat and can be changed and 1059 * removed at will. 1060 * Internal note: be aware that physically removing these fields 1061 * will break ABI. Replace removed fields with dummy fields, and 1062 * add new fields to AVStreamInternal. 1063 ***************************************************************** 1064 */ 1065 1066 // kept for ABI compatibility only, do not access in any way 1067 void* unused; 1068 1069 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ 1070 1071 // Timestamp generation support: 1072 /** 1073 * Timestamp corresponding to the last dts sync point. 1074 * 1075 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and 1076 * a DTS is received from the underlying container. Otherwise set to 1077 * AV_NOPTS_VALUE by default. 1078 */ 1079 long first_dts; 1080 long cur_dts; 1081 long last_IP_pts; 1082 int last_IP_duration; 1083 1084 /** 1085 * Number of packets to buffer for codec probing 1086 */ 1087 int probe_packets; 1088 1089 /** 1090 * Number of frames that have been demuxed during avformat_find_stream_info() 1091 */ 1092 int codec_info_nb_frames; 1093 1094 /* av_read_frame() support */ 1095 AVStreamParseType need_parsing; 1096 AVCodecParserContext* parser; 1097 1098 // kept for ABI compatibility only, do not access in any way 1099 void* unused7; 1100 AVProbeData unused6; 1101 long[17] unused5; 1102 1103 AVIndexEntry* index_entries; /**< Only used if the format does not 1104 support seeking natively. */ 1105 int nb_index_entries; 1106 uint index_entries_allocated_size; 1107 1108 /** 1109 * Stream Identifier 1110 * This is the MPEG-TS stream identifier +1 1111 * 0 means unknown 1112 */ 1113 int stream_identifier; 1114 1115 // kept for ABI compatibility only, do not access in any way 1116 int unused8; 1117 int unused9; 1118 int unused10; 1119 1120 /** 1121 * An opaque field for libavformat internal usage. 1122 * Must not be accessed in any way by callers. 1123 */ 1124 AVStreamInternal* internal; 1125 } 1126 1127 enum AVSTREAM_EVENT_FLAG_METADATA_UPDATED = 0x0001; 1128 enum AVSTREAM_EVENT_FLAG_NEW_PACKETS = 1 << 1; 1129 1130 /** 1131 * Accessors for some AVStream fields. These used to be provided for ABI 1132 * compatibility, and do not need to be used anymore. 1133 */ 1134 AVRational av_stream_get_r_frame_rate (const(AVStream)* s); 1135 void av_stream_set_r_frame_rate (AVStream* s, AVRational r); 1136 char* av_stream_get_recommended_encoder_configuration (const(AVStream)* s); 1137 void av_stream_set_recommended_encoder_configuration ( 1138 AVStream* s, 1139 char* configuration); 1140 1141 AVCodecParserContext* av_stream_get_parser (const(AVStream)* s); 1142 1143 /** 1144 * Returns the pts of the last muxed packet + its duration 1145 * 1146 * the retuned value is undefined when used with a demuxer. 1147 */ 1148 long av_stream_get_end_pts (const(AVStream)* st); 1149 1150 enum AV_PROGRAM_RUNNING = 1; 1151 1152 /** 1153 * New fields can be added to the end with minor version bumps. 1154 * Removal, reordering and changes to existing fields require a major 1155 * version bump. 1156 * sizeof(AVProgram) must not be used outside libav*. 1157 */ 1158 struct AVProgram 1159 { 1160 int id; 1161 int flags; 1162 AVDiscard discard; ///< selects which program to discard and which to feed to the caller 1163 uint* stream_index; 1164 uint nb_stream_indexes; 1165 AVDictionary* metadata; 1166 1167 int program_num; 1168 int pmt_pid; 1169 int pcr_pid; 1170 int pmt_version; 1171 1172 /***************************************************************** 1173 * All fields below this line are not part of the public API. They 1174 * may not be used outside of libavformat and can be changed and 1175 * removed at will. 1176 * New public fields should be added right above. 1177 ***************************************************************** 1178 */ 1179 long start_time; 1180 long end_time; 1181 1182 long pts_wrap_reference; ///< reference dts for wrap detection 1183 int pts_wrap_behavior; ///< behavior on wrap detection 1184 } 1185 1186 enum AVFMTCTX_NOHEADER = 0x0001; /**< signal that no header is present 1187 (streams are added dynamically) */ 1188 enum AVFMTCTX_UNSEEKABLE = 0x0002; /**< signal that the stream is definitely 1189 not seekable, and attempts to call the 1190 seek function will fail. For some 1191 network protocols (e.g. HLS), this can 1192 change dynamically at runtime. */ 1193 1194 struct AVChapter 1195 { 1196 int id; ///< unique ID to identify the chapter 1197 1198 ///< unique ID to identify the chapter 1199 1200 AVRational time_base; ///< time base in which the start/end timestamps are specified 1201 long start; 1202 long end; ///< chapter start/end time in time_base units 1203 AVDictionary* metadata; 1204 } 1205 1206 /** 1207 * Callback used by devices to communicate with application. 1208 */ 1209 alias av_format_control_message = int function ( 1210 AVFormatContext* s, 1211 int type, 1212 void* data, 1213 size_t data_size); 1214 1215 alias AVOpenCallback = int function ( 1216 AVFormatContext* s, 1217 AVIOContext** pb, 1218 const(char)* url, 1219 int flags, 1220 const(AVIOInterruptCB)* int_cb, 1221 AVDictionary** options); 1222 1223 /** 1224 * The duration of a video can be estimated through various ways, and this enum can be used 1225 * to know how the duration was estimated. 1226 */ 1227 enum AVDurationEstimationMethod 1228 { 1229 AVFMT_DURATION_FROM_PTS = 0, ///< Duration accurately estimated from PTSes 1230 AVFMT_DURATION_FROM_STREAM = 1, ///< Duration estimated from a stream with a known duration 1231 AVFMT_DURATION_FROM_BITRATE = 2 ///< Duration estimated from bitrate (less accurate) 1232 } 1233 1234 struct AVFormatInternal; 1235 1236 /** 1237 * Format I/O context. 1238 * New fields can be added to the end with minor version bumps. 1239 * Removal, reordering and changes to existing fields require a major 1240 * version bump. 1241 * sizeof(AVFormatContext) must not be used outside libav*, use 1242 * avformat_alloc_context() to create an AVFormatContext. 1243 * 1244 * Fields can be accessed through AVOptions (av_opt*), 1245 * the name string used matches the associated command line parameter name and 1246 * can be found in libavformat/options_table.h. 1247 * The AVOption/command line parameter names differ in some cases from the C 1248 * structure field names for historic reasons or brevity. 1249 */ 1250 struct AVFormatContext 1251 { 1252 /** 1253 * A class for logging and @ref avoptions. Set by avformat_alloc_context(). 1254 * Exports (de)muxer private options if they exist. 1255 */ 1256 const(AVClass)* av_class; 1257 1258 /** 1259 * The input container format. 1260 * 1261 * Demuxing only, set by avformat_open_input(). 1262 */ 1263 AVInputFormat* iformat; 1264 1265 /** 1266 * The output container format. 1267 * 1268 * Muxing only, must be set by the caller before avformat_write_header(). 1269 */ 1270 AVOutputFormat* oformat; 1271 1272 /** 1273 * Format private data. This is an AVOptions-enabled struct 1274 * if and only if iformat/oformat.priv_class is not NULL. 1275 * 1276 * - muxing: set by avformat_write_header() 1277 * - demuxing: set by avformat_open_input() 1278 */ 1279 void* priv_data; 1280 1281 /** 1282 * I/O context. 1283 * 1284 * - demuxing: either set by the user before avformat_open_input() (then 1285 * the user must close it manually) or set by avformat_open_input(). 1286 * - muxing: set by the user before avformat_write_header(). The caller must 1287 * take care of closing / freeing the IO context. 1288 * 1289 * Do NOT set this field if AVFMT_NOFILE flag is set in 1290 * iformat/oformat.flags. In such a case, the (de)muxer will handle 1291 * I/O in some other way and this field will be NULL. 1292 */ 1293 AVIOContext* pb; 1294 1295 /* stream info */ 1296 /** 1297 * Flags signalling stream properties. A combination of AVFMTCTX_*. 1298 * Set by libavformat. 1299 */ 1300 int ctx_flags; 1301 1302 /** 1303 * Number of elements in AVFormatContext.streams. 1304 * 1305 * Set by avformat_new_stream(), must not be modified by any other code. 1306 */ 1307 uint nb_streams; 1308 /** 1309 * A list of all streams in the file. New streams are created with 1310 * avformat_new_stream(). 1311 * 1312 * - demuxing: streams are created by libavformat in avformat_open_input(). 1313 * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also 1314 * appear in av_read_frame(). 1315 * - muxing: streams are created by the user before avformat_write_header(). 1316 * 1317 * Freed by libavformat in avformat_free_context(). 1318 */ 1319 AVStream** streams; 1320 1321 /** 1322 * input or output filename 1323 * 1324 * - demuxing: set by avformat_open_input() 1325 * - muxing: may be set by the caller before avformat_write_header() 1326 * 1327 * @deprecated Use url instead. 1328 */ 1329 char[1024] filename; 1330 1331 /** 1332 * input or output URL. Unlike the old filename field, this field has no 1333 * length restriction. 1334 * 1335 * - demuxing: set by avformat_open_input(), initialized to an empty 1336 * string if url parameter was NULL in avformat_open_input(). 1337 * - muxing: may be set by the caller before calling avformat_write_header() 1338 * (or avformat_init_output() if that is called first) to a string 1339 * which is freeable by av_free(). Set to an empty string if it 1340 * was NULL in avformat_init_output(). 1341 * 1342 * Freed by libavformat in avformat_free_context(). 1343 */ 1344 char* url; 1345 1346 /** 1347 * Position of the first frame of the component, in 1348 * AV_TIME_BASE fractional seconds. NEVER set this value directly: 1349 * It is deduced from the AVStream values. 1350 * 1351 * Demuxing only, set by libavformat. 1352 */ 1353 long start_time; 1354 1355 /** 1356 * Duration of the stream, in AV_TIME_BASE fractional 1357 * seconds. Only set this value if you know none of the individual stream 1358 * durations and also do not set any of them. This is deduced from the 1359 * AVStream values if not set. 1360 * 1361 * Demuxing only, set by libavformat. 1362 */ 1363 long duration; 1364 1365 /** 1366 * Total stream bitrate in bit/s, 0 if not 1367 * available. Never set it directly if the file_size and the 1368 * duration are known as FFmpeg can compute it automatically. 1369 */ 1370 long bit_rate; 1371 1372 uint packet_size; 1373 int max_delay; 1374 1375 /** 1376 * Flags modifying the (de)muxer behaviour. A combination of AVFMT_FLAG_*. 1377 * Set by the user before avformat_open_input() / avformat_write_header(). 1378 */ 1379 int flags; 1380 ///< Generate missing pts even if it requires parsing future frames. 1381 ///< Ignore index. 1382 ///< Do not block when reading packets from input. 1383 ///< Ignore DTS on frames that contain both DTS & PTS 1384 ///< Do not infer any values from other values, just return what is stored in the container 1385 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled 1386 ///< Do not buffer frames when possible 1387 ///< The caller has supplied a custom AVIOContext, don't avio_close() it. 1388 ///< Discard frames marked corrupted 1389 ///< Flush the AVIOContext every packet. 1390 /** 1391 * When muxing, try to avoid writing any random/volatile data to the output. 1392 * This includes any random IDs, real-time timestamps/dates, muxer version, etc. 1393 * 1394 * This flag is mainly intended for testing. 1395 */ 1396 1397 ///< Deprecated, does nothing. 1398 1399 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down) 1400 1401 ///< Enable use of private options by delaying codec open (deprecated, will do nothing once av_demuxer_open() is removed) 1402 1403 ///< Deprecated, does nothing. 1404 1405 ///< Enable fast, but inaccurate seeks for some formats 1406 ///< Stop muxing when the shortest stream stops. 1407 ///< Add bitstream filters as requested by the muxer 1408 1409 /** 1410 * Maximum size of the data read from input for determining 1411 * the input container format. 1412 * Demuxing only, set by the caller before avformat_open_input(). 1413 */ 1414 long probesize; 1415 1416 /** 1417 * Maximum duration (in AV_TIME_BASE units) of the data read 1418 * from input in avformat_find_stream_info(). 1419 * Demuxing only, set by the caller before avformat_find_stream_info(). 1420 * Can be set to 0 to let avformat choose using a heuristic. 1421 */ 1422 long max_analyze_duration; 1423 1424 const(ubyte)* key; 1425 int keylen; 1426 1427 uint nb_programs; 1428 AVProgram** programs; 1429 1430 /** 1431 * Forced video codec_id. 1432 * Demuxing: Set by user. 1433 */ 1434 AVCodecID video_codec_id; 1435 1436 /** 1437 * Forced audio codec_id. 1438 * Demuxing: Set by user. 1439 */ 1440 AVCodecID audio_codec_id; 1441 1442 /** 1443 * Forced subtitle codec_id. 1444 * Demuxing: Set by user. 1445 */ 1446 AVCodecID subtitle_codec_id; 1447 1448 /** 1449 * Maximum amount of memory in bytes to use for the index of each stream. 1450 * If the index exceeds this size, entries will be discarded as 1451 * needed to maintain a smaller size. This can lead to slower or less 1452 * accurate seeking (depends on demuxer). 1453 * Demuxers for which a full in-memory index is mandatory will ignore 1454 * this. 1455 * - muxing: unused 1456 * - demuxing: set by user 1457 */ 1458 uint max_index_size; 1459 1460 /** 1461 * Maximum amount of memory in bytes to use for buffering frames 1462 * obtained from realtime capture devices. 1463 */ 1464 uint max_picture_buffer; 1465 1466 /** 1467 * Number of chapters in AVChapter array. 1468 * When muxing, chapters are normally written in the file header, 1469 * so nb_chapters should normally be initialized before write_header 1470 * is called. Some muxers (e.g. mov and mkv) can also write chapters 1471 * in the trailer. To write chapters in the trailer, nb_chapters 1472 * must be zero when write_header is called and non-zero when 1473 * write_trailer is called. 1474 * - muxing: set by user 1475 * - demuxing: set by libavformat 1476 */ 1477 uint nb_chapters; 1478 AVChapter** chapters; 1479 1480 /** 1481 * Metadata that applies to the whole file. 1482 * 1483 * - demuxing: set by libavformat in avformat_open_input() 1484 * - muxing: may be set by the caller before avformat_write_header() 1485 * 1486 * Freed by libavformat in avformat_free_context(). 1487 */ 1488 AVDictionary* metadata; 1489 1490 /** 1491 * Start time of the stream in real world time, in microseconds 1492 * since the Unix epoch (00:00 1st January 1970). That is, pts=0 in the 1493 * stream was captured at this real world time. 1494 * - muxing: Set by the caller before avformat_write_header(). If set to 1495 * either 0 or AV_NOPTS_VALUE, then the current wall-time will 1496 * be used. 1497 * - demuxing: Set by libavformat. AV_NOPTS_VALUE if unknown. Note that 1498 * the value may become known after some number of frames 1499 * have been received. 1500 */ 1501 long start_time_realtime; 1502 1503 /** 1504 * The number of frames used for determining the framerate in 1505 * avformat_find_stream_info(). 1506 * Demuxing only, set by the caller before avformat_find_stream_info(). 1507 */ 1508 int fps_probe_size; 1509 1510 /** 1511 * Error recognition; higher values will detect more errors but may 1512 * misdetect some more or less valid parts as errors. 1513 * Demuxing only, set by the caller before avformat_open_input(). 1514 */ 1515 int error_recognition; 1516 1517 /** 1518 * Custom interrupt callbacks for the I/O layer. 1519 * 1520 * demuxing: set by the user before avformat_open_input(). 1521 * muxing: set by the user before avformat_write_header() 1522 * (mainly useful for AVFMT_NOFILE formats). The callback 1523 * should also be passed to avio_open2() if it's used to 1524 * open the file. 1525 */ 1526 AVIOInterruptCB interrupt_callback; 1527 1528 /** 1529 * Flags to enable debugging. 1530 */ 1531 int debug_; 1532 1533 /** 1534 * Maximum buffering duration for interleaving. 1535 * 1536 * To ensure all the streams are interleaved correctly, 1537 * av_interleaved_write_frame() will wait until it has at least one packet 1538 * for each stream before actually writing any packets to the output file. 1539 * When some streams are "sparse" (i.e. there are large gaps between 1540 * successive packets), this can result in excessive buffering. 1541 * 1542 * This field specifies the maximum difference between the timestamps of the 1543 * first and the last packet in the muxing queue, above which libavformat 1544 * will output a packet regardless of whether it has queued a packet for all 1545 * the streams. 1546 * 1547 * Muxing only, set by the caller before avformat_write_header(). 1548 */ 1549 long max_interleave_delta; 1550 1551 /** 1552 * Allow non-standard and experimental extension 1553 * @see AVCodecContext.strict_std_compliance 1554 */ 1555 int strict_std_compliance; 1556 1557 /** 1558 * Flags indicating events happening on the file, a combination of 1559 * AVFMT_EVENT_FLAG_*. 1560 * 1561 * - demuxing: may be set by the demuxer in avformat_open_input(), 1562 * avformat_find_stream_info() and av_read_frame(). Flags must be cleared 1563 * by the user once the event has been handled. 1564 * - muxing: may be set by the user after avformat_write_header() to 1565 * indicate a user-triggered event. The muxer will clear the flags for 1566 * events it has handled in av_[interleaved]_write_frame(). 1567 */ 1568 int event_flags; 1569 /** 1570 * - demuxing: the demuxer read new metadata from the file and updated 1571 * AVFormatContext.metadata accordingly 1572 * - muxing: the user updated AVFormatContext.metadata and wishes the muxer to 1573 * write it into the file 1574 */ 1575 1576 /** 1577 * Maximum number of packets to read while waiting for the first timestamp. 1578 * Decoding only. 1579 */ 1580 int max_ts_probe; 1581 1582 /** 1583 * Avoid negative timestamps during muxing. 1584 * Any value of the AVFMT_AVOID_NEG_TS_* constants. 1585 * Note, this only works when using av_interleaved_write_frame. (interleave_packet_per_dts is in use) 1586 * - muxing: Set by user 1587 * - demuxing: unused 1588 */ 1589 int avoid_negative_ts; 1590 ///< Enabled when required by target format 1591 ///< Shift timestamps so they are non negative 1592 ///< Shift timestamps so that they start at 0 1593 1594 /** 1595 * Transport stream id. 1596 * This will be moved into demuxer private options. Thus no API/ABI compatibility 1597 */ 1598 int ts_id; 1599 1600 /** 1601 * Audio preload in microseconds. 1602 * Note, not all formats support this and unpredictable things may happen if it is used when not supported. 1603 * - encoding: Set by user 1604 * - decoding: unused 1605 */ 1606 int audio_preload; 1607 1608 /** 1609 * Max chunk time in microseconds. 1610 * Note, not all formats support this and unpredictable things may happen if it is used when not supported. 1611 * - encoding: Set by user 1612 * - decoding: unused 1613 */ 1614 int max_chunk_duration; 1615 1616 /** 1617 * Max chunk size in bytes 1618 * Note, not all formats support this and unpredictable things may happen if it is used when not supported. 1619 * - encoding: Set by user 1620 * - decoding: unused 1621 */ 1622 int max_chunk_size; 1623 1624 /** 1625 * forces the use of wallclock timestamps as pts/dts of packets 1626 * This has undefined results in the presence of B frames. 1627 * - encoding: unused 1628 * - decoding: Set by user 1629 */ 1630 int use_wallclock_as_timestamps; 1631 1632 /** 1633 * avio flags, used to force AVIO_FLAG_DIRECT. 1634 * - encoding: unused 1635 * - decoding: Set by user 1636 */ 1637 int avio_flags; 1638 1639 /** 1640 * The duration field can be estimated through various ways, and this field can be used 1641 * to know how the duration was estimated. 1642 * - encoding: unused 1643 * - decoding: Read by user 1644 */ 1645 AVDurationEstimationMethod duration_estimation_method; 1646 1647 /** 1648 * Skip initial bytes when opening stream 1649 * - encoding: unused 1650 * - decoding: Set by user 1651 */ 1652 long skip_initial_bytes; 1653 1654 /** 1655 * Correct single timestamp overflows 1656 * - encoding: unused 1657 * - decoding: Set by user 1658 */ 1659 uint correct_ts_overflow; 1660 1661 /** 1662 * Force seeking to any (also non key) frames. 1663 * - encoding: unused 1664 * - decoding: Set by user 1665 */ 1666 int seek2any; 1667 1668 /** 1669 * Flush the I/O context after each packet. 1670 * - encoding: Set by user 1671 * - decoding: unused 1672 */ 1673 int flush_packets; 1674 1675 /** 1676 * format probing score. 1677 * The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes 1678 * the format. 1679 * - encoding: unused 1680 * - decoding: set by avformat, read by user 1681 */ 1682 int probe_score; 1683 1684 /** 1685 * number of bytes to read maximally to identify format. 1686 * - encoding: unused 1687 * - decoding: set by user 1688 */ 1689 int format_probesize; 1690 1691 /** 1692 * ',' separated list of allowed decoders. 1693 * If NULL then all are allowed 1694 * - encoding: unused 1695 * - decoding: set by user 1696 */ 1697 char* codec_whitelist; 1698 1699 /** 1700 * ',' separated list of allowed demuxers. 1701 * If NULL then all are allowed 1702 * - encoding: unused 1703 * - decoding: set by user 1704 */ 1705 char* format_whitelist; 1706 1707 /** 1708 * An opaque field for libavformat internal usage. 1709 * Must not be accessed in any way by callers. 1710 */ 1711 AVFormatInternal* internal; 1712 1713 /** 1714 * IO repositioned flag. 1715 * This is set by avformat when the underlaying IO context read pointer 1716 * is repositioned, for example when doing byte based seeking. 1717 * Demuxers can use the flag to detect such changes. 1718 */ 1719 int io_repositioned; 1720 1721 /** 1722 * Forced video codec. 1723 * This allows forcing a specific decoder, even when there are multiple with 1724 * the same codec_id. 1725 * Demuxing: Set by user 1726 */ 1727 AVCodec* video_codec; 1728 1729 /** 1730 * Forced audio codec. 1731 * This allows forcing a specific decoder, even when there are multiple with 1732 * the same codec_id. 1733 * Demuxing: Set by user 1734 */ 1735 AVCodec* audio_codec; 1736 1737 /** 1738 * Forced subtitle codec. 1739 * This allows forcing a specific decoder, even when there are multiple with 1740 * the same codec_id. 1741 * Demuxing: Set by user 1742 */ 1743 AVCodec* subtitle_codec; 1744 1745 /** 1746 * Forced data codec. 1747 * This allows forcing a specific decoder, even when there are multiple with 1748 * the same codec_id. 1749 * Demuxing: Set by user 1750 */ 1751 AVCodec* data_codec; 1752 1753 /** 1754 * Number of bytes to be written as padding in a metadata header. 1755 * Demuxing: Unused. 1756 * Muxing: Set by user via av_format_set_metadata_header_padding. 1757 */ 1758 int metadata_header_padding; 1759 1760 /** 1761 * User data. 1762 * This is a place for some private data of the user. 1763 */ 1764 void* opaque; 1765 1766 /** 1767 * Callback used by devices to communicate with application. 1768 */ 1769 av_format_control_message control_message_cb; 1770 1771 /** 1772 * Output timestamp offset, in microseconds. 1773 * Muxing: set by user 1774 */ 1775 long output_ts_offset; 1776 1777 /** 1778 * dump format separator. 1779 * can be ", " or "\n " or anything else 1780 * - muxing: Set by user. 1781 * - demuxing: Set by user. 1782 */ 1783 ubyte* dump_separator; 1784 1785 /** 1786 * Forced Data codec_id. 1787 * Demuxing: Set by user. 1788 */ 1789 AVCodecID data_codec_id; 1790 1791 /** 1792 * Called to open further IO contexts when needed for demuxing. 1793 * 1794 * This can be set by the user application to perform security checks on 1795 * the URLs before opening them. 1796 * The function should behave like avio_open2(), AVFormatContext is provided 1797 * as contextual information and to reach AVFormatContext.opaque. 1798 * 1799 * If NULL then some simple checks are used together with avio_open2(). 1800 * 1801 * Must not be accessed directly from outside avformat. 1802 * @See av_format_set_open_cb() 1803 * 1804 * Demuxing: Set by user. 1805 * 1806 * @deprecated Use io_open and io_close. 1807 */ 1808 int function ( 1809 AVFormatContext* s, 1810 AVIOContext** p, 1811 const(char)* url, 1812 int flags, 1813 const(AVIOInterruptCB)* int_cb, 1814 AVDictionary** options) open_cb; 1815 1816 /** 1817 * ',' separated list of allowed protocols. 1818 * - encoding: unused 1819 * - decoding: set by user 1820 */ 1821 char* protocol_whitelist; 1822 1823 /** 1824 * A callback for opening new IO streams. 1825 * 1826 * Whenever a muxer or a demuxer needs to open an IO stream (typically from 1827 * avformat_open_input() for demuxers, but for certain formats can happen at 1828 * other times as well), it will call this callback to obtain an IO context. 1829 * 1830 * @param s the format context 1831 * @param pb on success, the newly opened IO context should be returned here 1832 * @param url the url to open 1833 * @param flags a combination of AVIO_FLAG_* 1834 * @param options a dictionary of additional options, with the same 1835 * semantics as in avio_open2() 1836 * @return 0 on success, a negative AVERROR code on failure 1837 * 1838 * @note Certain muxers and demuxers do nesting, i.e. they open one or more 1839 * additional internal format contexts. Thus the AVFormatContext pointer 1840 * passed to this callback may be different from the one facing the caller. 1841 * It will, however, have the same 'opaque' field. 1842 */ 1843 int function ( 1844 AVFormatContext* s, 1845 AVIOContext** pb, 1846 const(char)* url, 1847 int flags, 1848 AVDictionary** options) io_open; 1849 1850 /** 1851 * A callback for closing the streams opened with AVFormatContext.io_open(). 1852 */ 1853 void function (AVFormatContext* s, AVIOContext* pb) io_close; 1854 1855 /** 1856 * ',' separated list of disallowed protocols. 1857 * - encoding: unused 1858 * - decoding: set by user 1859 */ 1860 char* protocol_blacklist; 1861 1862 /** 1863 * The maximum number of streams. 1864 * - encoding: unused 1865 * - decoding: set by user 1866 */ 1867 int max_streams; 1868 1869 /** 1870 * Skip duration calcuation in estimate_timings_from_pts. 1871 * - encoding: unused 1872 * - decoding: set by user 1873 */ 1874 int skip_estimate_duration_from_pts; 1875 1876 /** 1877 * Maximum number of packets that can be probed 1878 * - encoding: unused 1879 * - decoding: set by user 1880 */ 1881 int max_probe_packets; 1882 } 1883 1884 enum AVFMT_FLAG_GENPTS = 0x0001; 1885 enum AVFMT_FLAG_IGNIDX = 0x0002; 1886 enum AVFMT_FLAG_NONBLOCK = 0x0004; 1887 enum AVFMT_FLAG_IGNDTS = 0x0008; 1888 enum AVFMT_FLAG_NOFILLIN = 0x0010; 1889 enum AVFMT_FLAG_NOPARSE = 0x0020; 1890 enum AVFMT_FLAG_NOBUFFER = 0x0040; 1891 enum AVFMT_FLAG_CUSTOM_IO = 0x0080; 1892 enum AVFMT_FLAG_DISCARD_CORRUPT = 0x0100; 1893 enum AVFMT_FLAG_FLUSH_PACKETS = 0x0200; 1894 enum AVFMT_FLAG_BITEXACT = 0x0400; 1895 enum AVFMT_FLAG_MP4A_LATM = 0x8000; 1896 enum AVFMT_FLAG_SORT_DTS = 0x10000; 1897 enum AVFMT_FLAG_PRIV_OPT = 0x20000; 1898 enum AVFMT_FLAG_KEEP_SIDE_DATA = 0x40000; 1899 enum AVFMT_FLAG_FAST_SEEK = 0x80000; 1900 enum AVFMT_FLAG_SHORTEST = 0x100000; 1901 enum AVFMT_FLAG_AUTO_BSF = 0x200000; 1902 enum FF_FDEBUG_TS = 0x0001; 1903 enum AVFMT_EVENT_FLAG_METADATA_UPDATED = 0x0001; 1904 enum AVFMT_AVOID_NEG_TS_AUTO = -1; 1905 enum AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE = 1; 1906 enum AVFMT_AVOID_NEG_TS_MAKE_ZERO = 2; 1907 1908 /** 1909 * Accessors for some AVFormatContext fields. These used to be provided for ABI 1910 * compatibility, and do not need to be used anymore. 1911 */ 1912 int av_format_get_probe_score (const(AVFormatContext)* s); 1913 AVCodec* av_format_get_video_codec (const(AVFormatContext)* s); 1914 void av_format_set_video_codec (AVFormatContext* s, AVCodec* c); 1915 AVCodec* av_format_get_audio_codec (const(AVFormatContext)* s); 1916 void av_format_set_audio_codec (AVFormatContext* s, AVCodec* c); 1917 AVCodec* av_format_get_subtitle_codec (const(AVFormatContext)* s); 1918 void av_format_set_subtitle_codec (AVFormatContext* s, AVCodec* c); 1919 AVCodec* av_format_get_data_codec (const(AVFormatContext)* s); 1920 void av_format_set_data_codec (AVFormatContext* s, AVCodec* c); 1921 int av_format_get_metadata_header_padding (const(AVFormatContext)* s); 1922 void av_format_set_metadata_header_padding (AVFormatContext* s, int c); 1923 void* av_format_get_opaque (const(AVFormatContext)* s); 1924 void av_format_set_opaque (AVFormatContext* s, void* opaque); 1925 av_format_control_message av_format_get_control_message_cb ( 1926 const(AVFormatContext)* s); 1927 void av_format_set_control_message_cb ( 1928 AVFormatContext* s, 1929 av_format_control_message callback); 1930 AVOpenCallback av_format_get_open_cb (const(AVFormatContext)* s); 1931 void av_format_set_open_cb (AVFormatContext* s, AVOpenCallback callback); 1932 1933 /** 1934 * This function will cause global side data to be injected in the next packet 1935 * of each stream as well as after any subsequent seek. 1936 */ 1937 void av_format_inject_global_side_data (AVFormatContext* s); 1938 1939 /** 1940 * Returns the method used to set ctx->duration. 1941 * 1942 * @return AVFMT_DURATION_FROM_PTS, AVFMT_DURATION_FROM_STREAM, or AVFMT_DURATION_FROM_BITRATE. 1943 */ 1944 AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method (const(AVFormatContext)* ctx); 1945 1946 /** 1947 * @defgroup lavf_core Core functions 1948 * @ingroup libavf 1949 * 1950 * Functions for querying libavformat capabilities, allocating core structures, 1951 * etc. 1952 * @{ 1953 */ 1954 1955 /** 1956 * Return the LIBAVFORMAT_VERSION_INT constant. 1957 */ 1958 uint avformat_version (); 1959 1960 /** 1961 * Return the libavformat build-time configuration. 1962 */ 1963 const(char)* avformat_configuration (); 1964 1965 /** 1966 * Return the libavformat license. 1967 */ 1968 const(char)* avformat_license (); 1969 1970 /** 1971 * Initialize libavformat and register all the muxers, demuxers and 1972 * protocols. If you do not call this function, then you can select 1973 * exactly which formats you want to support. 1974 * 1975 * @see av_register_input_format() 1976 * @see av_register_output_format() 1977 */ 1978 void av_register_all (); 1979 1980 void av_register_input_format (AVInputFormat* format); 1981 void av_register_output_format (AVOutputFormat* format); 1982 1983 /** 1984 * Do global initialization of network libraries. This is optional, 1985 * and not recommended anymore. 1986 * 1987 * This functions only exists to work around thread-safety issues 1988 * with older GnuTLS or OpenSSL libraries. If libavformat is linked 1989 * to newer versions of those libraries, or if you do not use them, 1990 * calling this function is unnecessary. Otherwise, you need to call 1991 * this function before any other threads using them are started. 1992 * 1993 * This function will be deprecated once support for older GnuTLS and 1994 * OpenSSL libraries is removed, and this function has no purpose 1995 * anymore. 1996 */ 1997 int avformat_network_init (); 1998 1999 /** 2000 * Undo the initialization done by avformat_network_init. Call it only 2001 * once for each time you called avformat_network_init. 2002 */ 2003 int avformat_network_deinit (); 2004 2005 /** 2006 * If f is NULL, returns the first registered input format, 2007 * if f is non-NULL, returns the next registered input format after f 2008 * or NULL if f is the last one. 2009 */ 2010 AVInputFormat* av_iformat_next (const(AVInputFormat)* f); 2011 2012 /** 2013 * If f is NULL, returns the first registered output format, 2014 * if f is non-NULL, returns the next registered output format after f 2015 * or NULL if f is the last one. 2016 */ 2017 AVOutputFormat* av_oformat_next (const(AVOutputFormat)* f); 2018 2019 /** 2020 * Iterate over all registered muxers. 2021 * 2022 * @param opaque a pointer where libavformat will store the iteration state. Must 2023 * point to NULL to start the iteration. 2024 * 2025 * @return the next registered muxer or NULL when the iteration is 2026 * finished 2027 */ 2028 const(AVOutputFormat)* av_muxer_iterate (void** opaque); 2029 2030 /** 2031 * Iterate over all registered demuxers. 2032 * 2033 * @param opaque a pointer where libavformat will store the iteration state. Must 2034 * point to NULL to start the iteration. 2035 * 2036 * @return the next registered demuxer or NULL when the iteration is 2037 * finished 2038 */ 2039 const(AVInputFormat)* av_demuxer_iterate (void** opaque); 2040 2041 /** 2042 * Allocate an AVFormatContext. 2043 * avformat_free_context() can be used to free the context and everything 2044 * allocated by the framework within it. 2045 */ 2046 AVFormatContext* avformat_alloc_context (); 2047 2048 /** 2049 * Free an AVFormatContext and all its streams. 2050 * @param s context to free 2051 */ 2052 void avformat_free_context (AVFormatContext* s); 2053 2054 /** 2055 * Get the AVClass for AVFormatContext. It can be used in combination with 2056 * AV_OPT_SEARCH_FAKE_OBJ for examining options. 2057 * 2058 * @see av_opt_find(). 2059 */ 2060 const(AVClass)* avformat_get_class (); 2061 2062 /** 2063 * Add a new stream to a media file. 2064 * 2065 * When demuxing, it is called by the demuxer in read_header(). If the 2066 * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also 2067 * be called in read_packet(). 2068 * 2069 * When muxing, should be called by the user before avformat_write_header(). 2070 * 2071 * User is required to call avcodec_close() and avformat_free_context() to 2072 * clean up the allocation by avformat_new_stream(). 2073 * 2074 * @param s media file handle 2075 * @param c If non-NULL, the AVCodecContext corresponding to the new stream 2076 * will be initialized to use this codec. This is needed for e.g. codec-specific 2077 * defaults to be set, so codec should be provided if it is known. 2078 * 2079 * @return newly created stream or NULL on error. 2080 */ 2081 AVStream* avformat_new_stream (AVFormatContext* s, const(AVCodec)* c); 2082 2083 /** 2084 * Wrap an existing array as stream side data. 2085 * 2086 * @param st stream 2087 * @param type side information type 2088 * @param data the side data array. It must be allocated with the av_malloc() 2089 * family of functions. The ownership of the data is transferred to 2090 * st. 2091 * @param size side information size 2092 * @return zero on success, a negative AVERROR code on failure. On failure, 2093 * the stream is unchanged and the data remains owned by the caller. 2094 */ 2095 int av_stream_add_side_data ( 2096 AVStream* st, 2097 AVPacketSideDataType type, 2098 ubyte* data, 2099 size_t size); 2100 2101 /** 2102 * Allocate new information from stream. 2103 * 2104 * @param stream stream 2105 * @param type desired side information type 2106 * @param size side information size 2107 * @return pointer to fresh allocated data or NULL otherwise 2108 */ 2109 ubyte* av_stream_new_side_data ( 2110 AVStream* stream, 2111 AVPacketSideDataType type, 2112 int size); 2113 2114 /** 2115 * Get side information from stream. 2116 * 2117 * @param stream stream 2118 * @param type desired side information type 2119 * @param size If supplied, *size will be set to the size of the side data 2120 * or to zero if the desired side data is not present. 2121 * @return pointer to data if present or NULL otherwise 2122 */ 2123 ubyte* av_stream_get_side_data ( 2124 const(AVStream)* stream, 2125 AVPacketSideDataType type, 2126 int* size); 2127 2128 AVProgram* av_new_program (AVFormatContext* s, int id); 2129 2130 /** 2131 * @} 2132 */ 2133 2134 /** 2135 * Allocate an AVFormatContext for an output format. 2136 * avformat_free_context() can be used to free the context and 2137 * everything allocated by the framework within it. 2138 * 2139 * @param *ctx is set to the created format context, or to NULL in 2140 * case of failure 2141 * @param oformat format to use for allocating the context, if NULL 2142 * format_name and filename are used instead 2143 * @param format_name the name of output format to use for allocating the 2144 * context, if NULL filename is used instead 2145 * @param filename the name of the filename to use for allocating the 2146 * context, may be NULL 2147 * @return >= 0 in case of success, a negative AVERROR code in case of 2148 * failure 2149 */ 2150 int avformat_alloc_output_context2 ( 2151 AVFormatContext** ctx, 2152 AVOutputFormat* oformat, 2153 const(char)* format_name, 2154 const(char)* filename); 2155 2156 /** 2157 * @addtogroup lavf_decoding 2158 * @{ 2159 */ 2160 2161 /** 2162 * Find AVInputFormat based on the short name of the input format. 2163 */ 2164 AVInputFormat* av_find_input_format (const(char)* short_name); 2165 2166 /** 2167 * Guess the file format. 2168 * 2169 * @param pd data to be probed 2170 * @param is_opened Whether the file is already opened; determines whether 2171 * demuxers with or without AVFMT_NOFILE are probed. 2172 */ 2173 AVInputFormat* av_probe_input_format (AVProbeData* pd, int is_opened); 2174 2175 /** 2176 * Guess the file format. 2177 * 2178 * @param pd data to be probed 2179 * @param is_opened Whether the file is already opened; determines whether 2180 * demuxers with or without AVFMT_NOFILE are probed. 2181 * @param score_max A probe score larger that this is required to accept a 2182 * detection, the variable is set to the actual detection 2183 * score afterwards. 2184 * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended 2185 * to retry with a larger probe buffer. 2186 */ 2187 AVInputFormat* av_probe_input_format2 (AVProbeData* pd, int is_opened, int* score_max); 2188 2189 /** 2190 * Guess the file format. 2191 * 2192 * @param is_opened Whether the file is already opened; determines whether 2193 * demuxers with or without AVFMT_NOFILE are probed. 2194 * @param score_ret The score of the best detection. 2195 */ 2196 AVInputFormat* av_probe_input_format3 (AVProbeData* pd, int is_opened, int* score_ret); 2197 2198 /** 2199 * Probe a bytestream to determine the input format. Each time a probe returns 2200 * with a score that is too low, the probe buffer size is increased and another 2201 * attempt is made. When the maximum probe size is reached, the input format 2202 * with the highest score is returned. 2203 * 2204 * @param pb the bytestream to probe 2205 * @param fmt the input format is put here 2206 * @param url the url of the stream 2207 * @param logctx the log context 2208 * @param offset the offset within the bytestream to probe from 2209 * @param max_probe_size the maximum probe buffer size (zero for default) 2210 * @return the score in case of success, a negative value corresponding to an 2211 * the maximal score is AVPROBE_SCORE_MAX 2212 * AVERROR code otherwise 2213 */ 2214 int av_probe_input_buffer2 ( 2215 AVIOContext* pb, 2216 AVInputFormat** fmt, 2217 const(char)* url, 2218 void* logctx, 2219 uint offset, 2220 uint max_probe_size); 2221 2222 /** 2223 * Like av_probe_input_buffer2() but returns 0 on success 2224 */ 2225 int av_probe_input_buffer ( 2226 AVIOContext* pb, 2227 AVInputFormat** fmt, 2228 const(char)* url, 2229 void* logctx, 2230 uint offset, 2231 uint max_probe_size); 2232 2233 /** 2234 * Open an input stream and read the header. The codecs are not opened. 2235 * The stream must be closed with avformat_close_input(). 2236 * 2237 * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). 2238 * May be a pointer to NULL, in which case an AVFormatContext is allocated by this 2239 * function and written into ps. 2240 * Note that a user-supplied AVFormatContext will be freed on failure. 2241 * @param url URL of the stream to open. 2242 * @param fmt If non-NULL, this parameter forces a specific input format. 2243 * Otherwise the format is autodetected. 2244 * @param options A dictionary filled with AVFormatContext and demuxer-private options. 2245 * On return this parameter will be destroyed and replaced with a dict containing 2246 * options that were not found. May be NULL. 2247 * 2248 * @return 0 on success, a negative AVERROR on failure. 2249 * 2250 * @note If you want to use custom IO, preallocate the format context and set its pb field. 2251 */ 2252 int avformat_open_input (AVFormatContext** ps, const(char)* url, AVInputFormat* fmt, AVDictionary** options); 2253 2254 /** 2255 * @deprecated Use an AVDictionary to pass options to a demuxer. 2256 */ 2257 int av_demuxer_open (AVFormatContext* ic); 2258 2259 /** 2260 * Read packets of a media file to get stream information. This 2261 * is useful for file formats with no headers such as MPEG. This 2262 * function also computes the real framerate in case of MPEG-2 repeat 2263 * frame mode. 2264 * The logical file position is not changed by this function; 2265 * examined packets may be buffered for later processing. 2266 * 2267 * @param ic media file handle 2268 * @param options If non-NULL, an ic.nb_streams long array of pointers to 2269 * dictionaries, where i-th member contains options for 2270 * codec corresponding to i-th stream. 2271 * On return each dictionary will be filled with options that were not found. 2272 * @return >=0 if OK, AVERROR_xxx on error 2273 * 2274 * @note this function isn't guaranteed to open all the codecs, so 2275 * options being non-empty at return is a perfectly normal behavior. 2276 * 2277 * @todo Let the user decide somehow what information is needed so that 2278 * we do not waste time getting stuff the user does not need. 2279 */ 2280 int avformat_find_stream_info (AVFormatContext* ic, AVDictionary** options); 2281 2282 /** 2283 * Find the programs which belong to a given stream. 2284 * 2285 * @param ic media file handle 2286 * @param last the last found program, the search will start after this 2287 * program, or from the beginning if it is NULL 2288 * @param s stream index 2289 * @return the next program which belongs to s, NULL if no program is found or 2290 * the last program is not among the programs of ic. 2291 */ 2292 AVProgram* av_find_program_from_stream (AVFormatContext* ic, AVProgram* last, int s); 2293 2294 void av_program_add_stream_index (AVFormatContext* ac, int progid, uint idx); 2295 2296 /** 2297 * Find the "best" stream in the file. 2298 * The best stream is determined according to various heuristics as the most 2299 * likely to be what the user expects. 2300 * If the decoder parameter is non-NULL, av_find_best_stream will find the 2301 * default decoder for the stream's codec; streams for which no decoder can 2302 * be found are ignored. 2303 * 2304 * @param ic media file handle 2305 * @param type stream type: video, audio, subtitles, etc. 2306 * @param wanted_stream_nb user-requested stream number, 2307 * or -1 for automatic selection 2308 * @param related_stream try to find a stream related (eg. in the same 2309 * program) to this one, or -1 if none 2310 * @param decoder_ret if non-NULL, returns the decoder for the 2311 * selected stream 2312 * @param flags flags; none are currently defined 2313 * @return the non-negative stream number in case of success, 2314 * AVERROR_STREAM_NOT_FOUND if no stream with the requested type 2315 * could be found, 2316 * AVERROR_DECODER_NOT_FOUND if streams were found but no decoder 2317 * @note If av_find_best_stream returns successfully and decoder_ret is not 2318 * NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec. 2319 */ 2320 int av_find_best_stream ( 2321 AVFormatContext* ic, 2322 AVMediaType type, 2323 int wanted_stream_nb, 2324 int related_stream, 2325 AVCodec** decoder_ret, 2326 int flags); 2327 2328 /** 2329 * Return the next frame of a stream. 2330 * This function returns what is stored in the file, and does not validate 2331 * that what is there are valid frames for the decoder. It will split what is 2332 * stored in the file into frames and return one for each call. It will not 2333 * omit invalid data between valid frames so as to give the decoder the maximum 2334 * information possible for decoding. 2335 * 2336 * On success, the returned packet is reference-counted (pkt->buf is set) and 2337 * valid indefinitely. The packet must be freed with av_packet_unref() when 2338 * it is no longer needed. For video, the packet contains exactly one frame. 2339 * For audio, it contains an integer number of frames if each frame has 2340 * a known fixed size (e.g. PCM or ADPCM data). If the audio frames have 2341 * a variable size (e.g. MPEG audio), then it contains one frame. 2342 * 2343 * pkt->pts, pkt->dts and pkt->duration are always set to correct 2344 * values in AVStream.time_base units (and guessed if the format cannot 2345 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format 2346 * has B-frames, so it is better to rely on pkt->dts if you do not 2347 * decompress the payload. 2348 * 2349 * @return 0 if OK, < 0 on error or end of file. On error, pkt will be blank 2350 * (as if it came from av_packet_alloc()). 2351 * 2352 * @note pkt will be initialized, so it may be uninitialized, but it must not 2353 * contain data that needs to be freed. 2354 */ 2355 int av_read_frame (AVFormatContext* s, AVPacket* pkt); 2356 2357 /** 2358 * Seek to the keyframe at timestamp. 2359 * 'timestamp' in 'stream_index'. 2360 * 2361 * @param s media file handle 2362 * @param stream_index If stream_index is (-1), a default 2363 * stream is selected, and timestamp is automatically converted 2364 * from AV_TIME_BASE units to the stream specific time_base. 2365 * @param timestamp Timestamp in AVStream.time_base units 2366 * or, if no stream is specified, in AV_TIME_BASE units. 2367 * @param flags flags which select direction and seeking mode 2368 * @return >= 0 on success 2369 */ 2370 int av_seek_frame ( 2371 AVFormatContext* s, 2372 int stream_index, 2373 long timestamp, 2374 int flags); 2375 2376 /** 2377 * Seek to timestamp ts. 2378 * Seeking will be done so that the point from which all active streams 2379 * can be presented successfully will be closest to ts and within min/max_ts. 2380 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL. 2381 * 2382 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and 2383 * are the file position (this may not be supported by all demuxers). 2384 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames 2385 * in the stream with stream_index (this may not be supported by all demuxers). 2386 * Otherwise all timestamps are in units of the stream selected by stream_index 2387 * or if stream_index is -1, in AV_TIME_BASE units. 2388 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as 2389 * keyframes (this may not be supported by all demuxers). 2390 * If flags contain AVSEEK_FLAG_BACKWARD, it is ignored. 2391 * 2392 * @param s media file handle 2393 * @param stream_index index of the stream which is used as time base reference 2394 * @param min_ts smallest acceptable timestamp 2395 * @param ts target timestamp 2396 * @param max_ts largest acceptable timestamp 2397 * @param flags flags 2398 * @return >=0 on success, error code otherwise 2399 * 2400 * @note This is part of the new seek API which is still under construction. 2401 */ 2402 int avformat_seek_file (AVFormatContext* s, int stream_index, long min_ts, long ts, long max_ts, int flags); 2403 2404 /** 2405 * Discard all internally buffered data. This can be useful when dealing with 2406 * discontinuities in the byte stream. Generally works only with formats that 2407 * can resync. This includes headerless formats like MPEG-TS/TS but should also 2408 * work with NUT, Ogg and in a limited way AVI for example. 2409 * 2410 * The set of streams, the detected duration, stream parameters and codecs do 2411 * not change when calling this function. If you want a complete reset, it's 2412 * better to open a new AVFormatContext. 2413 * 2414 * This does not flush the AVIOContext (s->pb). If necessary, call 2415 * avio_flush(s->pb) before calling this function. 2416 * 2417 * @param s media file handle 2418 * @return >=0 on success, error code otherwise 2419 */ 2420 int avformat_flush (AVFormatContext* s); 2421 2422 /** 2423 * Start playing a network-based stream (e.g. RTSP stream) at the 2424 * current position. 2425 */ 2426 int av_read_play (AVFormatContext* s); 2427 2428 /** 2429 * Pause a network-based stream (e.g. RTSP stream). 2430 * 2431 * Use av_read_play() to resume it. 2432 */ 2433 int av_read_pause (AVFormatContext* s); 2434 2435 /** 2436 * Close an opened input AVFormatContext. Free it and all its contents 2437 * and set *s to NULL. 2438 */ 2439 void avformat_close_input (AVFormatContext** s); 2440 /** 2441 * @} 2442 */ 2443 2444 enum AVSEEK_FLAG_BACKWARD = 1; ///< seek backward 2445 enum AVSEEK_FLAG_BYTE = 2; ///< seeking based on position in bytes 2446 enum AVSEEK_FLAG_ANY = 4; ///< seek to any frame, even non-keyframes 2447 enum AVSEEK_FLAG_FRAME = 8; ///< seeking based on frame number 2448 2449 /** 2450 * @addtogroup lavf_encoding 2451 * @{ 2452 */ 2453 2454 enum AVSTREAM_INIT_IN_WRITE_HEADER = 0; ///< stream parameters initialized in avformat_write_header 2455 enum AVSTREAM_INIT_IN_INIT_OUTPUT = 1; ///< stream parameters initialized in avformat_init_output 2456 2457 /** 2458 * Allocate the stream private data and write the stream header to 2459 * an output media file. 2460 * 2461 * @param s Media file handle, must be allocated with avformat_alloc_context(). 2462 * Its oformat field must be set to the desired output format; 2463 * Its pb field must be set to an already opened AVIOContext. 2464 * @param options An AVDictionary filled with AVFormatContext and muxer-private options. 2465 * On return this parameter will be destroyed and replaced with a dict containing 2466 * options that were not found. May be NULL. 2467 * 2468 * @return AVSTREAM_INIT_IN_WRITE_HEADER on success if the codec had not already been fully initialized in avformat_init, 2469 * AVSTREAM_INIT_IN_INIT_OUTPUT on success if the codec had already been fully initialized in avformat_init, 2470 * negative AVERROR on failure. 2471 * 2472 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next, avformat_init_output. 2473 */ 2474 int avformat_write_header (AVFormatContext* s, AVDictionary** options); 2475 2476 /** 2477 * Allocate the stream private data and initialize the codec, but do not write the header. 2478 * May optionally be used before avformat_write_header to initialize stream parameters 2479 * before actually writing the header. 2480 * If using this function, do not pass the same options to avformat_write_header. 2481 * 2482 * @param s Media file handle, must be allocated with avformat_alloc_context(). 2483 * Its oformat field must be set to the desired output format; 2484 * Its pb field must be set to an already opened AVIOContext. 2485 * @param options An AVDictionary filled with AVFormatContext and muxer-private options. 2486 * On return this parameter will be destroyed and replaced with a dict containing 2487 * options that were not found. May be NULL. 2488 * 2489 * @return AVSTREAM_INIT_IN_WRITE_HEADER on success if the codec requires avformat_write_header to fully initialize, 2490 * AVSTREAM_INIT_IN_INIT_OUTPUT on success if the codec has been fully initialized, 2491 * negative AVERROR on failure. 2492 * 2493 * @see av_opt_find, av_dict_set, avio_open, av_oformat_next, avformat_write_header. 2494 */ 2495 int avformat_init_output (AVFormatContext* s, AVDictionary** options); 2496 2497 /** 2498 * Write a packet to an output media file. 2499 * 2500 * This function passes the packet directly to the muxer, without any buffering 2501 * or reordering. The caller is responsible for correctly interleaving the 2502 * packets if the format requires it. Callers that want libavformat to handle 2503 * the interleaving should call av_interleaved_write_frame() instead of this 2504 * function. 2505 * 2506 * @param s media file handle 2507 * @param pkt The packet containing the data to be written. Note that unlike 2508 * av_interleaved_write_frame(), this function does not take 2509 * ownership of the packet passed to it (though some muxers may make 2510 * an internal reference to the input packet). 2511 * <br> 2512 * This parameter can be NULL (at any time, not just at the end), in 2513 * order to immediately flush data buffered within the muxer, for 2514 * muxers that buffer up data internally before writing it to the 2515 * output. 2516 * <br> 2517 * Packet's @ref AVPacket.stream_index "stream_index" field must be 2518 * set to the index of the corresponding stream in @ref 2519 * AVFormatContext.streams "s->streams". 2520 * <br> 2521 * The timestamps (@ref AVPacket.pts "pts", @ref AVPacket.dts "dts") 2522 * must be set to correct values in the stream's timebase (unless the 2523 * output format is flagged with the AVFMT_NOTIMESTAMPS flag, then 2524 * they can be set to AV_NOPTS_VALUE). 2525 * The dts for subsequent packets passed to this function must be strictly 2526 * increasing when compared in their respective timebases (unless the 2527 * output format is flagged with the AVFMT_TS_NONSTRICT, then they 2528 * merely have to be nondecreasing). @ref AVPacket.duration 2529 * "duration") should also be set if known. 2530 * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush 2531 * 2532 * @see av_interleaved_write_frame() 2533 */ 2534 int av_write_frame (AVFormatContext* s, AVPacket* pkt); 2535 2536 /** 2537 * Write a packet to an output media file ensuring correct interleaving. 2538 * 2539 * This function will buffer the packets internally as needed to make sure the 2540 * packets in the output file are properly interleaved in the order of 2541 * increasing dts. Callers doing their own interleaving should call 2542 * av_write_frame() instead of this function. 2543 * 2544 * Using this function instead of av_write_frame() can give muxers advance 2545 * knowledge of future packets, improving e.g. the behaviour of the mp4 2546 * muxer for VFR content in fragmenting mode. 2547 * 2548 * @param s media file handle 2549 * @param pkt The packet containing the data to be written. 2550 * <br> 2551 * If the packet is reference-counted, this function will take 2552 * ownership of this reference and unreference it later when it sees 2553 * fit. 2554 * The caller must not access the data through this reference after 2555 * this function returns. If the packet is not reference-counted, 2556 * libavformat will make a copy. 2557 * <br> 2558 * This parameter can be NULL (at any time, not just at the end), to 2559 * flush the interleaving queues. 2560 * <br> 2561 * Packet's @ref AVPacket.stream_index "stream_index" field must be 2562 * set to the index of the corresponding stream in @ref 2563 * AVFormatContext.streams "s->streams". 2564 * <br> 2565 * The timestamps (@ref AVPacket.pts "pts", @ref AVPacket.dts "dts") 2566 * must be set to correct values in the stream's timebase (unless the 2567 * output format is flagged with the AVFMT_NOTIMESTAMPS flag, then 2568 * they can be set to AV_NOPTS_VALUE). 2569 * The dts for subsequent packets in one stream must be strictly 2570 * increasing (unless the output format is flagged with the 2571 * AVFMT_TS_NONSTRICT, then they merely have to be nondecreasing). 2572 * @ref AVPacket.duration "duration") should also be set if known. 2573 * 2574 * @return 0 on success, a negative AVERROR on error. Libavformat will always 2575 * take care of freeing the packet, even if this function fails. 2576 * 2577 * @see av_write_frame(), AVFormatContext.max_interleave_delta 2578 */ 2579 int av_interleaved_write_frame (AVFormatContext* s, AVPacket* pkt); 2580 2581 /** 2582 * Write an uncoded frame to an output media file. 2583 * 2584 * The frame must be correctly interleaved according to the container 2585 * specification; if not, av_interleaved_write_uncoded_frame() must be used. 2586 * 2587 * See av_interleaved_write_uncoded_frame() for details. 2588 */ 2589 int av_write_uncoded_frame ( 2590 AVFormatContext* s, 2591 int stream_index, 2592 AVFrame* frame); 2593 2594 /** 2595 * Write an uncoded frame to an output media file. 2596 * 2597 * If the muxer supports it, this function makes it possible to write an AVFrame 2598 * structure directly, without encoding it into a packet. 2599 * It is mostly useful for devices and similar special muxers that use raw 2600 * video or PCM data and will not serialize it into a byte stream. 2601 * 2602 * To test whether it is possible to use it with a given muxer and stream, 2603 * use av_write_uncoded_frame_query(). 2604 * 2605 * The caller gives up ownership of the frame and must not access it 2606 * afterwards. 2607 * 2608 * @return >=0 for success, a negative code on error 2609 */ 2610 int av_interleaved_write_uncoded_frame ( 2611 AVFormatContext* s, 2612 int stream_index, 2613 AVFrame* frame); 2614 2615 /** 2616 * Test whether a muxer supports uncoded frame. 2617 * 2618 * @return >=0 if an uncoded frame can be written to that muxer and stream, 2619 * <0 if not 2620 */ 2621 int av_write_uncoded_frame_query (AVFormatContext* s, int stream_index); 2622 2623 /** 2624 * Write the stream trailer to an output media file and free the 2625 * file private data. 2626 * 2627 * May only be called after a successful call to avformat_write_header. 2628 * 2629 * @param s media file handle 2630 * @return 0 if OK, AVERROR_xxx on error 2631 */ 2632 int av_write_trailer (AVFormatContext* s); 2633 2634 /** 2635 * Return the output format in the list of registered output formats 2636 * which best matches the provided parameters, or return NULL if 2637 * there is no match. 2638 * 2639 * @param short_name if non-NULL checks if short_name matches with the 2640 * names of the registered formats 2641 * @param filename if non-NULL checks if filename terminates with the 2642 * extensions of the registered formats 2643 * @param mime_type if non-NULL checks if mime_type matches with the 2644 * MIME type of the registered formats 2645 */ 2646 AVOutputFormat* av_guess_format ( 2647 const(char)* short_name, 2648 const(char)* filename, 2649 const(char)* mime_type); 2650 2651 /** 2652 * Guess the codec ID based upon muxer and filename. 2653 */ 2654 AVCodecID av_guess_codec ( 2655 AVOutputFormat* fmt, 2656 const(char)* short_name, 2657 const(char)* filename, 2658 const(char)* mime_type, 2659 AVMediaType type); 2660 2661 /** 2662 * Get timing information for the data currently output. 2663 * The exact meaning of "currently output" depends on the format. 2664 * It is mostly relevant for devices that have an internal buffer and/or 2665 * work in real time. 2666 * @param s media file handle 2667 * @param stream stream in the media file 2668 * @param[out] dts DTS of the last packet output for the stream, in stream 2669 * time_base units 2670 * @param[out] wall absolute time when that packet whas output, 2671 * in microsecond 2672 * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it 2673 * Note: some formats or devices may not allow to measure dts and wall 2674 * atomically. 2675 */ 2676 int av_get_output_timestamp ( 2677 AVFormatContext* s, 2678 int stream, 2679 long* dts, 2680 long* wall); 2681 2682 /** 2683 * @} 2684 */ 2685 2686 /** 2687 * @defgroup lavf_misc Utility functions 2688 * @ingroup libavf 2689 * @{ 2690 * 2691 * Miscellaneous utility functions related to both muxing and demuxing 2692 * (or neither). 2693 */ 2694 2695 /** 2696 * Send a nice hexadecimal dump of a buffer to the specified file stream. 2697 * 2698 * @param f The file stream pointer where the dump should be sent to. 2699 * @param buf buffer 2700 * @param size buffer size 2701 * 2702 * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2 2703 */ 2704 void av_hex_dump (FILE* f, const(ubyte)* buf, int size); 2705 2706 /** 2707 * Send a nice hexadecimal dump of a buffer to the log. 2708 * 2709 * @param avcl A pointer to an arbitrary struct of which the first field is a 2710 * pointer to an AVClass struct. 2711 * @param level The importance level of the message, lower values signifying 2712 * higher importance. 2713 * @param buf buffer 2714 * @param size buffer size 2715 * 2716 * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2 2717 */ 2718 void av_hex_dump_log (void* avcl, int level, const(ubyte)* buf, int size); 2719 2720 /** 2721 * Send a nice dump of a packet to the specified file stream. 2722 * 2723 * @param f The file stream pointer where the dump should be sent to. 2724 * @param pkt packet to dump 2725 * @param dump_payload True if the payload must be displayed, too. 2726 * @param st AVStream that the packet belongs to 2727 */ 2728 void av_pkt_dump2 (FILE* f, const(AVPacket)* pkt, int dump_payload, const(AVStream)* st); 2729 2730 /** 2731 * Send a nice dump of a packet to the log. 2732 * 2733 * @param avcl A pointer to an arbitrary struct of which the first field is a 2734 * pointer to an AVClass struct. 2735 * @param level The importance level of the message, lower values signifying 2736 * higher importance. 2737 * @param pkt packet to dump 2738 * @param dump_payload True if the payload must be displayed, too. 2739 * @param st AVStream that the packet belongs to 2740 */ 2741 void av_pkt_dump_log2 ( 2742 void* avcl, 2743 int level, 2744 const(AVPacket)* pkt, 2745 int dump_payload, 2746 const(AVStream)* st); 2747 2748 /** 2749 * Get the AVCodecID for the given codec tag tag. 2750 * If no codec id is found returns AV_CODEC_ID_NONE. 2751 * 2752 * @param tags list of supported codec_id-codec_tag pairs, as stored 2753 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag 2754 * @param tag codec tag to match to a codec ID 2755 */ 2756 AVCodecID av_codec_get_id (const(AVCodecTag*)* tags, uint tag); 2757 2758 /** 2759 * Get the codec tag for the given codec id id. 2760 * If no codec tag is found returns 0. 2761 * 2762 * @param tags list of supported codec_id-codec_tag pairs, as stored 2763 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag 2764 * @param id codec ID to match to a codec tag 2765 */ 2766 uint av_codec_get_tag (const(AVCodecTag*)* tags, AVCodecID id); 2767 2768 /** 2769 * Get the codec tag for the given codec id. 2770 * 2771 * @param tags list of supported codec_id - codec_tag pairs, as stored 2772 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag 2773 * @param id codec id that should be searched for in the list 2774 * @param tag A pointer to the found tag 2775 * @return 0 if id was not found in tags, > 0 if it was found 2776 */ 2777 int av_codec_get_tag2 (const(AVCodecTag*)* tags, AVCodecID id, uint* tag); 2778 2779 int av_find_default_stream_index (AVFormatContext* s); 2780 2781 /** 2782 * Get the index for a specific timestamp. 2783 * 2784 * @param st stream that the timestamp belongs to 2785 * @param timestamp timestamp to retrieve the index for 2786 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond 2787 * to the timestamp which is <= the requested one, if backward 2788 * is 0, then it will be >= 2789 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise 2790 * @return < 0 if no such timestamp could be found 2791 */ 2792 int av_index_search_timestamp (AVStream* st, long timestamp, int flags); 2793 2794 /** 2795 * Add an index entry into a sorted list. Update the entry if the list 2796 * already contains it. 2797 * 2798 * @param timestamp timestamp in the time base of the given stream 2799 */ 2800 int av_add_index_entry ( 2801 AVStream* st, 2802 long pos, 2803 long timestamp, 2804 int size, 2805 int distance, 2806 int flags); 2807 2808 /** 2809 * Split a URL string into components. 2810 * 2811 * The pointers to buffers for storing individual components may be null, 2812 * in order to ignore that component. Buffers for components not found are 2813 * set to empty strings. If the port is not found, it is set to a negative 2814 * value. 2815 * 2816 * @param proto the buffer for the protocol 2817 * @param proto_size the size of the proto buffer 2818 * @param authorization the buffer for the authorization 2819 * @param authorization_size the size of the authorization buffer 2820 * @param hostname the buffer for the host name 2821 * @param hostname_size the size of the hostname buffer 2822 * @param port_ptr a pointer to store the port number in 2823 * @param path the buffer for the path 2824 * @param path_size the size of the path buffer 2825 * @param url the URL to split 2826 */ 2827 void av_url_split ( 2828 char* proto, 2829 int proto_size, 2830 char* authorization, 2831 int authorization_size, 2832 char* hostname, 2833 int hostname_size, 2834 int* port_ptr, 2835 char* path, 2836 int path_size, 2837 const(char)* url); 2838 2839 /** 2840 * Print detailed information about the input or output format, such as 2841 * duration, bitrate, streams, container, programs, metadata, side data, 2842 * codec and time base. 2843 * 2844 * @param ic the context to analyze 2845 * @param index index of the stream to dump information about 2846 * @param url the URL to print, such as source or destination file 2847 * @param is_output Select whether the specified context is an input(0) or output(1) 2848 */ 2849 void av_dump_format ( 2850 AVFormatContext* ic, 2851 int index, 2852 const(char)* url, 2853 int is_output); 2854 2855 enum AV_FRAME_FILENAME_FLAGS_MULTIPLE = 1; ///< Allow multiple %d 2856 2857 /** 2858 * Return in 'buf' the path with '%d' replaced by a number. 2859 * 2860 * Also handles the '%0nd' format where 'n' is the total number 2861 * of digits and '%%'. 2862 * 2863 * @param buf destination buffer 2864 * @param buf_size destination buffer size 2865 * @param path numbered sequence string 2866 * @param number frame number 2867 * @param flags AV_FRAME_FILENAME_FLAGS_* 2868 * @return 0 if OK, -1 on format error 2869 */ 2870 int av_get_frame_filename2 ( 2871 char* buf, 2872 int buf_size, 2873 const(char)* path, 2874 int number, 2875 int flags); 2876 2877 int av_get_frame_filename ( 2878 char* buf, 2879 int buf_size, 2880 const(char)* path, 2881 int number); 2882 2883 /** 2884 * Check whether filename actually is a numbered sequence generator. 2885 * 2886 * @param filename possible numbered sequence string 2887 * @return 1 if a valid numbered sequence string, 0 otherwise 2888 */ 2889 int av_filename_number_test (const(char)* filename); 2890 2891 /** 2892 * Generate an SDP for an RTP session. 2893 * 2894 * Note, this overwrites the id values of AVStreams in the muxer contexts 2895 * for getting unique dynamic payload types. 2896 * 2897 * @param ac array of AVFormatContexts describing the RTP streams. If the 2898 * array is composed by only one context, such context can contain 2899 * multiple AVStreams (one AVStream per RTP stream). Otherwise, 2900 * all the contexts in the array (an AVCodecContext per RTP stream) 2901 * must contain only one AVStream. 2902 * @param n_files number of AVCodecContexts contained in ac 2903 * @param buf buffer where the SDP will be stored (must be allocated by 2904 * the caller) 2905 * @param size the size of the buffer 2906 * @return 0 if OK, AVERROR_xxx on error 2907 */ 2908 int av_sdp_create (AVFormatContext** ac, int n_files, char* buf, int size); 2909 2910 /** 2911 * Return a positive value if the given filename has one of the given 2912 * extensions, 0 otherwise. 2913 * 2914 * @param filename file name to check against the given extensions 2915 * @param extensions a comma-separated list of filename extensions 2916 */ 2917 int av_match_ext (const(char)* filename, const(char)* extensions); 2918 2919 /** 2920 * Test if the given container can store a codec. 2921 * 2922 * @param ofmt container to check for compatibility 2923 * @param codec_id codec to potentially store in container 2924 * @param std_compliance standards compliance level, one of FF_COMPLIANCE_* 2925 * 2926 * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot. 2927 * A negative number if this information is not available. 2928 */ 2929 int avformat_query_codec ( 2930 const(AVOutputFormat)* ofmt, 2931 AVCodecID codec_id, 2932 int std_compliance); 2933 2934 /** 2935 * @defgroup riff_fourcc RIFF FourCCs 2936 * @{ 2937 * Get the tables mapping RIFF FourCCs to libavcodec AVCodecIDs. The tables are 2938 * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the 2939 * following code: 2940 * @code 2941 * uint32_t tag = MKTAG('H', '2', '6', '4'); 2942 * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 }; 2943 * enum AVCodecID id = av_codec_get_id(table, tag); 2944 * @endcode 2945 */ 2946 /** 2947 * @return the table mapping RIFF FourCCs for video to libavcodec AVCodecID. 2948 */ 2949 const(AVCodecTag)* avformat_get_riff_video_tags (); 2950 /** 2951 * @return the table mapping RIFF FourCCs for audio to AVCodecID. 2952 */ 2953 const(AVCodecTag)* avformat_get_riff_audio_tags (); 2954 /** 2955 * @return the table mapping MOV FourCCs for video to libavcodec AVCodecID. 2956 */ 2957 const(AVCodecTag)* avformat_get_mov_video_tags (); 2958 /** 2959 * @return the table mapping MOV FourCCs for audio to AVCodecID. 2960 */ 2961 const(AVCodecTag)* avformat_get_mov_audio_tags (); 2962 2963 /** 2964 * @} 2965 */ 2966 2967 /** 2968 * Guess the sample aspect ratio of a frame, based on both the stream and the 2969 * frame aspect ratio. 2970 * 2971 * Since the frame aspect ratio is set by the codec but the stream aspect ratio 2972 * is set by the demuxer, these two may not be equal. This function tries to 2973 * return the value that you should use if you would like to display the frame. 2974 * 2975 * Basic logic is to use the stream aspect ratio if it is set to something sane 2976 * otherwise use the frame aspect ratio. This way a container setting, which is 2977 * usually easy to modify can override the coded value in the frames. 2978 * 2979 * @param format the format context which the stream is part of 2980 * @param stream the stream which the frame is part of 2981 * @param frame the frame with the aspect ratio to be determined 2982 * @return the guessed (valid) sample_aspect_ratio, 0/1 if no idea 2983 */ 2984 AVRational av_guess_sample_aspect_ratio (AVFormatContext* format, AVStream* stream, AVFrame* frame); 2985 2986 /** 2987 * Guess the frame rate, based on both the container and codec information. 2988 * 2989 * @param ctx the format context which the stream is part of 2990 * @param stream the stream which the frame is part of 2991 * @param frame the frame for which the frame rate should be determined, may be NULL 2992 * @return the guessed (valid) frame rate, 0/1 if no idea 2993 */ 2994 AVRational av_guess_frame_rate (AVFormatContext* ctx, AVStream* stream, AVFrame* frame); 2995 2996 /** 2997 * Check if the stream st contained in s is matched by the stream specifier 2998 * spec. 2999 * 3000 * See the "stream specifiers" chapter in the documentation for the syntax 3001 * of spec. 3002 * 3003 * @return >0 if st is matched by spec; 3004 * 0 if st is not matched by spec; 3005 * AVERROR code if spec is invalid 3006 * 3007 * @note A stream specifier can match several streams in the format. 3008 */ 3009 int avformat_match_stream_specifier ( 3010 AVFormatContext* s, 3011 AVStream* st, 3012 const(char)* spec); 3013 3014 int avformat_queue_attached_pictures (AVFormatContext* s); 3015 3016 /** 3017 * Apply a list of bitstream filters to a packet. 3018 * 3019 * @param codec AVCodecContext, usually from an AVStream 3020 * @param pkt the packet to apply filters to. If, on success, the returned 3021 * packet has size == 0 and side_data_elems == 0, it indicates that 3022 * the packet should be dropped 3023 * @param bsfc a NULL-terminated list of filters to apply 3024 * @return >=0 on success; 3025 * AVERROR code on failure 3026 */ 3027 int av_apply_bitstream_filters ( 3028 AVCodecContext* codec, 3029 AVPacket* pkt, 3030 AVBitStreamFilterContext* bsfc); 3031 3032 enum AVTimebaseSource 3033 { 3034 AVFMT_TBCF_AUTO = -1, 3035 AVFMT_TBCF_DECODER = 0, 3036 AVFMT_TBCF_DEMUXER = 1, 3037 3038 AVFMT_TBCF_R_FRAMERATE = 2 3039 } 3040 3041 /** 3042 * Transfer internal timing information from one stream to another. 3043 * 3044 * This function is useful when doing stream copy. 3045 * 3046 * @param ofmt target output format for ost 3047 * @param ost output stream which needs timings copy and adjustments 3048 * @param ist reference input stream to copy timings from 3049 * @param copy_tb define from where the stream codec timebase needs to be imported 3050 */ 3051 int avformat_transfer_internal_stream_timing_info ( 3052 const(AVOutputFormat)* ofmt, 3053 AVStream* ost, 3054 const(AVStream)* ist, 3055 AVTimebaseSource copy_tb); 3056 3057 /** 3058 * Get the internal codec timebase from a stream. 3059 * 3060 * @param st input stream to extract the timebase from 3061 */ 3062 AVRational av_stream_get_codec_timebase (const(AVStream)* st); 3063 3064 /** 3065 * @} 3066 */ 3067 3068 /* AVFORMAT_AVFORMAT_H */