avcodec.h (108136B)
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 21 #ifndef AVCODEC_AVCODEC_H 22 #define AVCODEC_AVCODEC_H 23 24 /** 25 * @file 26 * @ingroup libavc 27 * Libavcodec external API header 28 */ 29 30 #include "libavutil/samplefmt.h" 31 #include "libavutil/attributes.h" 32 #include "libavutil/avutil.h" 33 #include "libavutil/buffer.h" 34 #include "libavutil/channel_layout.h" 35 #include "libavutil/dict.h" 36 #include "libavutil/frame.h" 37 #include "libavutil/log.h" 38 #include "libavutil/pixfmt.h" 39 #include "libavutil/rational.h" 40 41 #include "codec.h" 42 #include "codec_id.h" 43 #include "defs.h" 44 #include "packet.h" 45 #include "version_major.h" 46 #ifndef HAVE_AV_CONFIG_H 47 /* When included as part of the ffmpeg build, only include the major version 48 * to avoid unnecessary rebuilds. When included externally, keep including 49 * the full version information. */ 50 #include "version.h" 51 52 #include "codec_desc.h" 53 #include "codec_par.h" 54 #endif 55 56 struct AVCodecParameters; 57 58 /** 59 * @defgroup libavc libavcodec 60 * Encoding/Decoding Library 61 * 62 * @{ 63 * 64 * @defgroup lavc_decoding Decoding 65 * @{ 66 * @} 67 * 68 * @defgroup lavc_encoding Encoding 69 * @{ 70 * @} 71 * 72 * @defgroup lavc_codec Codecs 73 * @{ 74 * @defgroup lavc_codec_native Native Codecs 75 * @{ 76 * @} 77 * @defgroup lavc_codec_wrappers External library wrappers 78 * @{ 79 * @} 80 * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge 81 * @{ 82 * @} 83 * @} 84 * @defgroup lavc_internal Internal 85 * @{ 86 * @} 87 * @} 88 */ 89 90 /** 91 * @ingroup libavc 92 * @defgroup lavc_encdec send/receive encoding and decoding API overview 93 * @{ 94 * 95 * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/ 96 * avcodec_receive_packet() functions provide an encode/decode API, which 97 * decouples input and output. 98 * 99 * The API is very similar for encoding/decoding and audio/video, and works as 100 * follows: 101 * - Set up and open the AVCodecContext as usual. 102 * - Send valid input: 103 * - For decoding, call avcodec_send_packet() to give the decoder raw 104 * compressed data in an AVPacket. 105 * - For encoding, call avcodec_send_frame() to give the encoder an AVFrame 106 * containing uncompressed audio or video. 107 * 108 * In both cases, it is recommended that AVPackets and AVFrames are 109 * refcounted, or libavcodec might have to copy the input data. (libavformat 110 * always returns refcounted AVPackets, and av_frame_get_buffer() allocates 111 * refcounted AVFrames.) 112 * - Receive output in a loop. Periodically call one of the avcodec_receive_*() 113 * functions and process their output: 114 * - For decoding, call avcodec_receive_frame(). On success, it will return 115 * an AVFrame containing uncompressed audio or video data. 116 * - For encoding, call avcodec_receive_packet(). On success, it will return 117 * an AVPacket with a compressed frame. 118 * 119 * Repeat this call until it returns AVERROR(EAGAIN) or an error. The 120 * AVERROR(EAGAIN) return value means that new input data is required to 121 * return new output. In this case, continue with sending input. For each 122 * input frame/packet, the codec will typically return 1 output frame/packet, 123 * but it can also be 0 or more than 1. 124 * 125 * At the beginning of decoding or encoding, the codec might accept multiple 126 * input frames/packets without returning a frame, until its internal buffers 127 * are filled. This situation is handled transparently if you follow the steps 128 * outlined above. 129 * 130 * In theory, sending input can result in EAGAIN - this should happen only if 131 * not all output was received. You can use this to structure alternative decode 132 * or encode loops other than the one suggested above. For example, you could 133 * try sending new input on each iteration, and try to receive output if that 134 * returns EAGAIN. 135 * 136 * End of stream situations. These require "flushing" (aka draining) the codec, 137 * as the codec might buffer multiple frames or packets internally for 138 * performance or out of necessity (consider B-frames). 139 * This is handled as follows: 140 * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding) 141 * or avcodec_send_frame() (encoding) functions. This will enter draining 142 * mode. 143 * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet() 144 * (encoding) in a loop until AVERROR_EOF is returned. The functions will 145 * not return AVERROR(EAGAIN), unless you forgot to enter draining mode. 146 * - Before decoding can be resumed again, the codec has to be reset with 147 * avcodec_flush_buffers(). 148 * 149 * Using the API as outlined above is highly recommended. But it is also 150 * possible to call functions outside of this rigid schema. For example, you can 151 * call avcodec_send_packet() repeatedly without calling 152 * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed 153 * until the codec's internal buffer has been filled up (which is typically of 154 * size 1 per output frame, after initial input), and then reject input with 155 * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to 156 * read at least some output. 157 * 158 * Not all codecs will follow a rigid and predictable dataflow; the only 159 * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on 160 * one end implies that a receive/send call on the other end will succeed, or 161 * at least will not fail with AVERROR(EAGAIN). In general, no codec will 162 * permit unlimited buffering of input or output. 163 * 164 * A codec is not allowed to return AVERROR(EAGAIN) for both sending and receiving. This 165 * would be an invalid state, which could put the codec user into an endless 166 * loop. The API has no concept of time either: it cannot happen that trying to 167 * do avcodec_send_packet() results in AVERROR(EAGAIN), but a repeated call 1 second 168 * later accepts the packet (with no other receive/flush API calls involved). 169 * The API is a strict state machine, and the passage of time is not supposed 170 * to influence it. Some timing-dependent behavior might still be deemed 171 * acceptable in certain cases. But it must never result in both send/receive 172 * returning EAGAIN at the same time at any point. It must also absolutely be 173 * avoided that the current state is "unstable" and can "flip-flop" between 174 * the send/receive APIs allowing progress. For example, it's not allowed that 175 * the codec randomly decides that it actually wants to consume a packet now 176 * instead of returning a frame, after it just returned AVERROR(EAGAIN) on an 177 * avcodec_send_packet() call. 178 * @} 179 */ 180 181 /** 182 * @defgroup lavc_core Core functions/structures. 183 * @ingroup libavc 184 * 185 * Basic definitions, functions for querying libavcodec capabilities, 186 * allocating core structures, etc. 187 * @{ 188 */ 189 190 /** 191 * @ingroup lavc_encoding 192 */ 193 typedef struct RcOverride{ 194 int start_frame; 195 int end_frame; 196 int qscale; // If this is 0 then quality_factor will be used instead. 197 float quality_factor; 198 } RcOverride; 199 200 /* encoding support 201 These flags can be passed in AVCodecContext.flags before initialization. 202 Note: Not everything is supported yet. 203 */ 204 205 /** 206 * Allow decoders to produce frames with data planes that are not aligned 207 * to CPU requirements (e.g. due to cropping). 208 */ 209 #define AV_CODEC_FLAG_UNALIGNED (1 << 0) 210 /** 211 * Use fixed qscale. 212 */ 213 #define AV_CODEC_FLAG_QSCALE (1 << 1) 214 /** 215 * 4 MV per MB allowed / advanced prediction for H.263. 216 */ 217 #define AV_CODEC_FLAG_4MV (1 << 2) 218 /** 219 * Output even those frames that might be corrupted. 220 */ 221 #define AV_CODEC_FLAG_OUTPUT_CORRUPT (1 << 3) 222 /** 223 * Use qpel MC. 224 */ 225 #define AV_CODEC_FLAG_QPEL (1 << 4) 226 /** 227 * Request the encoder to output reconstructed frames, i.e.\ frames that would 228 * be produced by decoding the encoded bitstream. These frames may be retrieved 229 * by calling avcodec_receive_frame() immediately after a successful call to 230 * avcodec_receive_packet(). 231 * 232 * Should only be used with encoders flagged with the 233 * @ref AV_CODEC_CAP_ENCODER_RECON_FRAME capability. 234 * 235 * @note 236 * Each reconstructed frame returned by the encoder corresponds to the last 237 * encoded packet, i.e. the frames are returned in coded order rather than 238 * presentation order. 239 * 240 * @note 241 * Frame parameters (like pixel format or dimensions) do not have to match the 242 * AVCodecContext values. Make sure to use the values from the returned frame. 243 */ 244 #define AV_CODEC_FLAG_RECON_FRAME (1 << 6) 245 /** 246 * @par decoding 247 * Request the decoder to propagate each packet's AVPacket.opaque and 248 * AVPacket.opaque_ref to its corresponding output AVFrame. 249 * 250 * @par encoding: 251 * Request the encoder to propagate each frame's AVFrame.opaque and 252 * AVFrame.opaque_ref values to its corresponding output AVPacket. 253 * 254 * @par 255 * May only be set on encoders that have the 256 * @ref AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability flag. 257 * 258 * @note 259 * While in typical cases one input frame produces exactly one output packet 260 * (perhaps after a delay), in general the mapping of frames to packets is 261 * M-to-N, so 262 * - Any number of input frames may be associated with any given output packet. 263 * This includes zero - e.g. some encoders may output packets that carry only 264 * metadata about the whole stream. 265 * - A given input frame may be associated with any number of output packets. 266 * Again this includes zero - e.g. some encoders may drop frames under certain 267 * conditions. 268 * . 269 * This implies that when using this flag, the caller must NOT assume that 270 * - a given input frame's opaques will necessarily appear on some output packet; 271 * - every output packet will have some non-NULL opaque value. 272 * . 273 * When an output packet contains multiple frames, the opaque values will be 274 * taken from the first of those. 275 * 276 * @note 277 * The converse holds for decoders, with frames and packets switched. 278 */ 279 #define AV_CODEC_FLAG_COPY_OPAQUE (1 << 7) 280 /** 281 * Signal to the encoder that the values of AVFrame.duration are valid and 282 * should be used (typically for transferring them to output packets). 283 * 284 * If this flag is not set, frame durations are ignored. 285 */ 286 #define AV_CODEC_FLAG_FRAME_DURATION (1 << 8) 287 /** 288 * Use internal 2pass ratecontrol in first pass mode. 289 */ 290 #define AV_CODEC_FLAG_PASS1 (1 << 9) 291 /** 292 * Use internal 2pass ratecontrol in second pass mode. 293 */ 294 #define AV_CODEC_FLAG_PASS2 (1 << 10) 295 /** 296 * loop filter. 297 */ 298 #define AV_CODEC_FLAG_LOOP_FILTER (1 << 11) 299 /** 300 * Only decode/encode grayscale. 301 */ 302 #define AV_CODEC_FLAG_GRAY (1 << 13) 303 /** 304 * error[?] variables will be set during encoding. 305 */ 306 #define AV_CODEC_FLAG_PSNR (1 << 15) 307 /** 308 * Use interlaced DCT. 309 */ 310 #define AV_CODEC_FLAG_INTERLACED_DCT (1 << 18) 311 /** 312 * Force low delay. 313 */ 314 #define AV_CODEC_FLAG_LOW_DELAY (1 << 19) 315 /** 316 * Place global headers in extradata instead of every keyframe. 317 */ 318 #define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22) 319 /** 320 * Use only bitexact stuff (except (I)DCT). 321 */ 322 #define AV_CODEC_FLAG_BITEXACT (1 << 23) 323 /* Fx : Flag for H.263+ extra options */ 324 /** 325 * H.263 advanced intra coding / MPEG-4 AC prediction 326 */ 327 #define AV_CODEC_FLAG_AC_PRED (1 << 24) 328 /** 329 * interlaced motion estimation 330 */ 331 #define AV_CODEC_FLAG_INTERLACED_ME (1 << 29) 332 #define AV_CODEC_FLAG_CLOSED_GOP (1U << 31) 333 334 /** 335 * Allow non spec compliant speedup tricks. 336 */ 337 #define AV_CODEC_FLAG2_FAST (1 << 0) 338 /** 339 * Skip bitstream encoding. 340 */ 341 #define AV_CODEC_FLAG2_NO_OUTPUT (1 << 2) 342 /** 343 * Place global headers at every keyframe instead of in extradata. 344 */ 345 #define AV_CODEC_FLAG2_LOCAL_HEADER (1 << 3) 346 347 /** 348 * Input bitstream might be truncated at a packet boundaries 349 * instead of only at frame boundaries. 350 */ 351 #define AV_CODEC_FLAG2_CHUNKS (1 << 15) 352 /** 353 * Discard cropping information from SPS. 354 */ 355 #define AV_CODEC_FLAG2_IGNORE_CROP (1 << 16) 356 357 /** 358 * Show all frames before the first keyframe 359 */ 360 #define AV_CODEC_FLAG2_SHOW_ALL (1 << 22) 361 /** 362 * Export motion vectors through frame side data 363 */ 364 #define AV_CODEC_FLAG2_EXPORT_MVS (1 << 28) 365 /** 366 * Do not skip samples and export skip information as frame side data 367 */ 368 #define AV_CODEC_FLAG2_SKIP_MANUAL (1 << 29) 369 /** 370 * Do not reset ASS ReadOrder field on flush (subtitles decoding) 371 */ 372 #define AV_CODEC_FLAG2_RO_FLUSH_NOOP (1 << 30) 373 /** 374 * Generate/parse ICC profiles on encode/decode, as appropriate for the type of 375 * file. No effect on codecs which cannot contain embedded ICC profiles, or 376 * when compiled without support for lcms2. 377 */ 378 #define AV_CODEC_FLAG2_ICC_PROFILES (1U << 31) 379 380 /* Exported side data. 381 These flags can be passed in AVCodecContext.export_side_data before initialization. 382 */ 383 /** 384 * Export motion vectors through frame side data 385 */ 386 #define AV_CODEC_EXPORT_DATA_MVS (1 << 0) 387 /** 388 * Export encoder Producer Reference Time through packet side data 389 */ 390 #define AV_CODEC_EXPORT_DATA_PRFT (1 << 1) 391 /** 392 * Decoding only. 393 * Export the AVVideoEncParams structure through frame side data. 394 */ 395 #define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS (1 << 2) 396 /** 397 * Decoding only. 398 * Do not apply film grain, export it instead. 399 */ 400 #define AV_CODEC_EXPORT_DATA_FILM_GRAIN (1 << 3) 401 402 /** 403 * Decoding only. 404 * Do not apply picture enhancement layers, export them instead. 405 */ 406 #define AV_CODEC_EXPORT_DATA_ENHANCEMENTS (1 << 4) 407 408 /** 409 * The decoder will keep a reference to the frame and may reuse it later. 410 */ 411 #define AV_GET_BUFFER_FLAG_REF (1 << 0) 412 413 /** 414 * The encoder will keep a reference to the packet and may reuse it later. 415 */ 416 #define AV_GET_ENCODE_BUFFER_FLAG_REF (1 << 0) 417 418 /** 419 * main external API structure. 420 * New fields can be added to the end with minor version bumps. 421 * Removal, reordering and changes to existing fields require a major 422 * version bump. 423 * You can use AVOptions (av_opt* / av_set/get*()) to access these fields from user 424 * applications. 425 * The name string for AVOptions options matches the associated command line 426 * parameter name and can be found in libavcodec/options_table.h 427 * The AVOption/command line parameter names differ in some cases from the C 428 * structure field names for historic reasons or brevity. 429 * sizeof(AVCodecContext) must not be used outside libav*. 430 */ 431 typedef struct AVCodecContext { 432 /** 433 * information on struct for av_log 434 * - set by avcodec_alloc_context3 435 */ 436 const AVClass *av_class; 437 int log_level_offset; 438 439 enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */ 440 const struct AVCodec *codec; 441 enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */ 442 443 /** 444 * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). 445 * This is used to work around some encoder bugs. 446 * A demuxer should set this to what is stored in the field used to identify the codec. 447 * If there are multiple such fields in a container then the demuxer should choose the one 448 * which maximizes the information about the used codec. 449 * If the codec tag field in a container is larger than 32 bits then the demuxer should 450 * remap the longer ID to 32 bits with a table or other structure. Alternatively a new 451 * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated 452 * first. 453 * - encoding: Set by user, if not then the default based on codec_id will be used. 454 * - decoding: Set by user, will be converted to uppercase by libavcodec during init. 455 */ 456 unsigned int codec_tag; 457 458 void *priv_data; 459 460 /** 461 * Private context used for internal data. 462 * 463 * Unlike priv_data, this is not codec-specific. It is used in general 464 * libavcodec functions. 465 */ 466 struct AVCodecInternal *internal; 467 468 /** 469 * Private data of the user, can be used to carry app specific stuff. 470 * - encoding: Set by user. 471 * - decoding: Set by user. 472 */ 473 void *opaque; 474 475 /** 476 * the average bitrate 477 * - encoding: Set by user; unused for constant quantizer encoding. 478 * - decoding: Set by user, may be overwritten by libavcodec 479 * if this info is available in the stream 480 */ 481 int64_t bit_rate; 482 483 /** 484 * AV_CODEC_FLAG_*. 485 * - encoding: Set by user. 486 * - decoding: Set by user. 487 */ 488 int flags; 489 490 /** 491 * AV_CODEC_FLAG2_* 492 * - encoding: Set by user. 493 * - decoding: Set by user. 494 */ 495 int flags2; 496 497 /** 498 * Out-of-band global headers that may be used by some codecs. 499 * 500 * - decoding: Should be set by the caller when available (typically from a 501 * demuxer) before opening the decoder; some decoders require this to be 502 * set and will fail to initialize otherwise. 503 * 504 * The array must be allocated with the av_malloc() family of functions; 505 * allocated size must be at least AV_INPUT_BUFFER_PADDING_SIZE bytes 506 * larger than extradata_size. 507 * 508 * - encoding: May be set by the encoder in avcodec_open2() (possibly 509 * depending on whether the AV_CODEC_FLAG_GLOBAL_HEADER flag is set). 510 * 511 * After being set, the array is owned by the codec and freed in 512 * avcodec_free_context(). 513 */ 514 uint8_t *extradata; 515 int extradata_size; 516 517 /** 518 * This is the fundamental unit of time (in seconds) in terms 519 * of which frame timestamps are represented. For fixed-fps content, 520 * timebase should be 1/framerate and timestamp increments should be 521 * identically 1. 522 * This often, but not always is the inverse of the frame rate or field rate 523 * for video. 1/time_base is not the average frame rate if the frame rate is not 524 * constant. 525 * 526 * Like containers, elementary streams also can store timestamps, 1/time_base 527 * is the unit in which these timestamps are specified. 528 * As example of such codec time base see ISO/IEC 14496-2:2001(E) 529 * vop_time_increment_resolution and fixed_vop_rate 530 * (fixed_vop_rate == 0 implies that it is different from the framerate) 531 * 532 * - encoding: MUST be set by user. 533 * - decoding: unused. 534 */ 535 AVRational time_base; 536 537 /** 538 * Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed. 539 * - encoding: unused. 540 * - decoding: set by user. 541 */ 542 AVRational pkt_timebase; 543 544 /** 545 * - decoding: For codecs that store a framerate value in the compressed 546 * bitstream, the decoder may export it here. { 0, 1} when 547 * unknown. 548 * - encoding: May be used to signal the framerate of CFR content to an 549 * encoder. 550 */ 551 AVRational framerate; 552 553 /** 554 * Codec delay. 555 * 556 * Encoding: Number of frames delay there will be from the encoder input to 557 * the decoder output. (we assume the decoder matches the spec) 558 * Decoding: Number of frames delay in addition to what a standard decoder 559 * as specified in the spec would produce. 560 * 561 * Video: 562 * Number of frames the decoded output will be delayed relative to the 563 * encoded input. 564 * 565 * Audio: 566 * For encoding, this field is unused (see initial_padding). 567 * 568 * For decoding, this is the number of samples the decoder needs to 569 * output before the decoder's output is valid. When seeking, you should 570 * start decoding this many samples prior to your desired seek point. 571 * 572 * - encoding: Set by libavcodec. 573 * - decoding: Set by libavcodec. 574 */ 575 int delay; 576 577 578 /* video only */ 579 /** 580 * picture width / height. 581 * 582 * @note Those fields may not match the values of the last 583 * AVFrame output by avcodec_receive_frame() due frame 584 * reordering. 585 * 586 * - encoding: MUST be set by user. 587 * - decoding: May be set by the user before opening the decoder if known e.g. 588 * from the container. Some decoders will require the dimensions 589 * to be set by the caller. During decoding, the decoder may 590 * overwrite those values as required while parsing the data. 591 */ 592 int width, height; 593 594 /** 595 * Bitstream width / height, may be different from width/height e.g. when 596 * the decoded frame is cropped before being output or lowres is enabled. 597 * 598 * @note Those field may not match the value of the last 599 * AVFrame output by avcodec_receive_frame() due frame 600 * reordering. 601 * 602 * - encoding: unused 603 * - decoding: May be set by the user before opening the decoder if known 604 * e.g. from the container. During decoding, the decoder may 605 * overwrite those values as required while parsing the data. 606 */ 607 int coded_width, coded_height; 608 609 /** 610 * sample aspect ratio (0 if unknown) 611 * That is the width of a pixel divided by the height of the pixel. 612 * Numerator and denominator must be relatively prime and smaller than 256 for some video standards. 613 * - encoding: Set by user. 614 * - decoding: Set by libavcodec. 615 */ 616 AVRational sample_aspect_ratio; 617 618 /** 619 * Pixel format, see AV_PIX_FMT_xxx. 620 * May be set by the demuxer if known from headers. 621 * May be overridden by the decoder if it knows better. 622 * 623 * @note This field may not match the value of the last 624 * AVFrame output by avcodec_receive_frame() due frame 625 * reordering. 626 * 627 * - encoding: Set by user. 628 * - decoding: Set by user if known, overridden by libavcodec while 629 * parsing the data. 630 */ 631 enum AVPixelFormat pix_fmt; 632 633 /** 634 * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx. 635 * - encoding: unused. 636 * - decoding: Set by libavcodec before calling get_format() 637 */ 638 enum AVPixelFormat sw_pix_fmt; 639 640 /** 641 * Chromaticity coordinates of the source primaries. 642 * - encoding: Set by user 643 * - decoding: Set by libavcodec 644 */ 645 enum AVColorPrimaries color_primaries; 646 647 /** 648 * Color Transfer Characteristic. 649 * - encoding: Set by user 650 * - decoding: Set by libavcodec 651 */ 652 enum AVColorTransferCharacteristic color_trc; 653 654 /** 655 * YUV colorspace type. 656 * - encoding: Set by user 657 * - decoding: Set by libavcodec 658 */ 659 enum AVColorSpace colorspace; 660 661 /** 662 * MPEG vs JPEG YUV range. 663 * - encoding: Set by user to override the default output color range value, 664 * If not specified, libavcodec sets the color range depending on the 665 * output format. 666 * - decoding: Set by libavcodec, can be set by the user to propagate the 667 * color range to components reading from the decoder context. 668 */ 669 enum AVColorRange color_range; 670 671 /** 672 * This defines the location of chroma samples. 673 * - encoding: Set by user 674 * - decoding: Set by libavcodec 675 */ 676 enum AVChromaLocation chroma_sample_location; 677 678 /** Field order 679 * - encoding: set by libavcodec 680 * - decoding: Set by user. 681 */ 682 enum AVFieldOrder field_order; 683 684 /** 685 * number of reference frames 686 * - encoding: Set by user. 687 * - decoding: Set by lavc. 688 */ 689 int refs; 690 691 /** 692 * Size of the frame reordering buffer in the decoder. 693 * For MPEG-2 it is 1 IPB or 0 low delay IP. 694 * - encoding: Set by libavcodec. 695 * - decoding: Set by libavcodec. 696 */ 697 int has_b_frames; 698 699 /** 700 * slice flags 701 * - encoding: unused 702 * - decoding: Set by user. 703 */ 704 int slice_flags; 705 #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display 706 #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG-2 field pics) 707 #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1) 708 709 /** 710 * If non NULL, 'draw_horiz_band' is called by the libavcodec 711 * decoder to draw a horizontal band. It improves cache usage. Not 712 * all codecs can do that. You must check the codec capabilities 713 * beforehand. 714 * When multithreading is used, it may be called from multiple threads 715 * at the same time; threads might draw different parts of the same AVFrame, 716 * or multiple AVFrames, and there is no guarantee that slices will be drawn 717 * in order. 718 * The function is also used by hardware acceleration APIs. 719 * It is called at least once during frame decoding to pass 720 * the data needed for hardware render. 721 * In that mode instead of pixel data, AVFrame points to 722 * a structure specific to the acceleration API. The application 723 * reads the structure and can change some fields to indicate progress 724 * or mark state. 725 * - encoding: unused 726 * - decoding: Set by user. 727 * @param height the height of the slice 728 * @param y the y position of the slice 729 * @param type 1->top field, 2->bottom field, 3->frame 730 * @param offset offset into the AVFrame.data from which the slice should be read 731 */ 732 void (*draw_horiz_band)(struct AVCodecContext *s, 733 const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], 734 int y, int type, int height); 735 736 /** 737 * Callback to negotiate the pixel format. Decoding only, may be set by the 738 * caller before avcodec_open2(). 739 * 740 * Called by some decoders to select the pixel format that will be used for 741 * the output frames. This is mainly used to set up hardware acceleration, 742 * then the provided format list contains the corresponding hwaccel pixel 743 * formats alongside the "software" one. The software pixel format may also 744 * be retrieved from \ref sw_pix_fmt. 745 * 746 * This callback will be called when the coded frame properties (such as 747 * resolution, pixel format, etc.) change and more than one output format is 748 * supported for those new properties. If a hardware pixel format is chosen 749 * and initialization for it fails, the callback may be called again 750 * immediately. 751 * 752 * This callback may be called from different threads if the decoder is 753 * multi-threaded, but not from more than one thread simultaneously. 754 * 755 * @param fmt list of formats which may be used in the current 756 * configuration, terminated by AV_PIX_FMT_NONE. 757 * @warning Behavior is undefined if the callback returns a value other 758 * than one of the formats in fmt or AV_PIX_FMT_NONE. 759 * @return the chosen format or AV_PIX_FMT_NONE 760 */ 761 enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt); 762 763 /** 764 * maximum number of B-frames between non-B-frames 765 * Note: The output will be delayed by max_b_frames+1 relative to the input. 766 * - encoding: Set by user. 767 * - decoding: unused 768 */ 769 int max_b_frames; 770 771 /** 772 * qscale factor between IP and B-frames 773 * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset). 774 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). 775 * - encoding: Set by user. 776 * - decoding: unused 777 */ 778 float b_quant_factor; 779 780 /** 781 * qscale offset between IP and B-frames 782 * - encoding: Set by user. 783 * - decoding: unused 784 */ 785 float b_quant_offset; 786 787 /** 788 * qscale factor between P- and I-frames 789 * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset). 790 * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). 791 * - encoding: Set by user. 792 * - decoding: unused 793 */ 794 float i_quant_factor; 795 796 /** 797 * qscale offset between P and I-frames 798 * - encoding: Set by user. 799 * - decoding: unused 800 */ 801 float i_quant_offset; 802 803 /** 804 * luminance masking (0-> disabled) 805 * - encoding: Set by user. 806 * - decoding: unused 807 */ 808 float lumi_masking; 809 810 /** 811 * temporary complexity masking (0-> disabled) 812 * - encoding: Set by user. 813 * - decoding: unused 814 */ 815 float temporal_cplx_masking; 816 817 /** 818 * spatial complexity masking (0-> disabled) 819 * - encoding: Set by user. 820 * - decoding: unused 821 */ 822 float spatial_cplx_masking; 823 824 /** 825 * p block masking (0-> disabled) 826 * - encoding: Set by user. 827 * - decoding: unused 828 */ 829 float p_masking; 830 831 /** 832 * darkness masking (0-> disabled) 833 * - encoding: Set by user. 834 * - decoding: unused 835 */ 836 float dark_masking; 837 838 /** 839 * noise vs. sse weight for the nsse comparison function 840 * - encoding: Set by user. 841 * - decoding: unused 842 */ 843 int nsse_weight; 844 845 /** 846 * motion estimation comparison function 847 * - encoding: Set by user. 848 * - decoding: unused 849 */ 850 int me_cmp; 851 /** 852 * subpixel motion estimation comparison function 853 * - encoding: Set by user. 854 * - decoding: unused 855 */ 856 int me_sub_cmp; 857 /** 858 * macroblock comparison function (not supported yet) 859 * - encoding: Set by user. 860 * - decoding: unused 861 */ 862 int mb_cmp; 863 /** 864 * interlaced DCT comparison function 865 * - encoding: Set by user. 866 * - decoding: unused 867 */ 868 int ildct_cmp; 869 #define FF_CMP_SAD 0 870 #define FF_CMP_SSE 1 871 #define FF_CMP_SATD 2 872 #define FF_CMP_DCT 3 873 #define FF_CMP_PSNR 4 874 #define FF_CMP_BIT 5 875 #define FF_CMP_RD 6 876 #define FF_CMP_ZERO 7 877 #define FF_CMP_VSAD 8 878 #define FF_CMP_VSSE 9 879 #define FF_CMP_NSSE 10 880 #define FF_CMP_W53 11 881 #define FF_CMP_W97 12 882 #define FF_CMP_DCTMAX 13 883 #define FF_CMP_DCT264 14 884 #define FF_CMP_MEDIAN_SAD 15 885 #define FF_CMP_CHROMA 256 886 887 /** 888 * ME diamond size & shape 889 * - encoding: Set by user. 890 * - decoding: unused 891 */ 892 int dia_size; 893 894 /** 895 * amount of previous MV predictors (2a+1 x 2a+1 square) 896 * - encoding: Set by user. 897 * - decoding: unused 898 */ 899 int last_predictor_count; 900 901 /** 902 * motion estimation prepass comparison function 903 * - encoding: Set by user. 904 * - decoding: unused 905 */ 906 int me_pre_cmp; 907 908 /** 909 * ME prepass diamond size & shape 910 * - encoding: Set by user. 911 * - decoding: unused 912 */ 913 int pre_dia_size; 914 915 /** 916 * subpel ME quality 917 * - encoding: Set by user. 918 * - decoding: unused 919 */ 920 int me_subpel_quality; 921 922 /** 923 * maximum motion estimation search range in subpel units 924 * If 0 then no limit. 925 * 926 * - encoding: Set by user. 927 * - decoding: unused 928 */ 929 int me_range; 930 931 /** 932 * macroblock decision mode 933 * - encoding: Set by user. 934 * - decoding: unused 935 */ 936 int mb_decision; 937 #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp 938 #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits 939 #define FF_MB_DECISION_RD 2 ///< rate distortion 940 941 /** 942 * custom intra quantization matrix 943 * Must be allocated with the av_malloc() family of functions, and will be freed in 944 * avcodec_free_context(). 945 * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL. 946 * - decoding: Set/allocated/freed by libavcodec. 947 */ 948 uint16_t *intra_matrix; 949 950 /** 951 * custom inter quantization matrix 952 * Must be allocated with the av_malloc() family of functions, and will be freed in 953 * avcodec_free_context(). 954 * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL. 955 * - decoding: Set/allocated/freed by libavcodec. 956 */ 957 uint16_t *inter_matrix; 958 959 /** 960 * custom intra quantization matrix 961 * - encoding: Set by user, can be NULL. 962 * - decoding: unused. 963 */ 964 uint16_t *chroma_intra_matrix; 965 966 /** 967 * precision of the intra DC coefficient - 8 968 * - encoding: Set by user. 969 * - decoding: Set by libavcodec 970 */ 971 int intra_dc_precision; 972 973 /** 974 * minimum MB Lagrange multiplier 975 * - encoding: Set by user. 976 * - decoding: unused 977 */ 978 int mb_lmin; 979 980 /** 981 * maximum MB Lagrange multiplier 982 * - encoding: Set by user. 983 * - decoding: unused 984 */ 985 int mb_lmax; 986 987 /** 988 * - encoding: Set by user. 989 * - decoding: unused 990 */ 991 int bidir_refine; 992 993 /** 994 * minimum GOP size 995 * - encoding: Set by user. 996 * - decoding: unused 997 */ 998 int keyint_min; 999 1000 /** 1001 * the number of pictures in a group of pictures, or 0 for intra_only 1002 * - encoding: Set by user. 1003 * - decoding: unused 1004 */ 1005 int gop_size; 1006 1007 /** 1008 * Note: Value depends upon the compare function used for fullpel ME. 1009 * - encoding: Set by user. 1010 * - decoding: unused 1011 */ 1012 int mv0_threshold; 1013 1014 /** 1015 * Number of slices. 1016 * Indicates number of picture subdivisions. Used for parallelized 1017 * decoding. 1018 * - encoding: Set by user 1019 * - decoding: unused 1020 */ 1021 int slices; 1022 1023 /* audio only */ 1024 int sample_rate; ///< samples per second 1025 1026 /** 1027 * audio sample format 1028 * - encoding: Set by user. 1029 * - decoding: Set by libavcodec. 1030 */ 1031 enum AVSampleFormat sample_fmt; ///< sample format 1032 1033 /** 1034 * Audio channel layout. 1035 * - encoding: must be set by the caller, to one of AVCodec.ch_layouts. 1036 * - decoding: may be set by the caller if known e.g. from the container. 1037 * The decoder can then override during decoding as needed. 1038 */ 1039 AVChannelLayout ch_layout; 1040 1041 /* The following data should not be initialized. */ 1042 /** 1043 * Number of samples per channel in an audio frame. 1044 * 1045 * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame 1046 * except the last must contain exactly frame_size samples per channel. 1047 * May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the 1048 * frame size is not restricted. 1049 * - decoding: may be set by some decoders to indicate constant frame size 1050 */ 1051 int frame_size; 1052 1053 /** 1054 * number of bytes per packet if constant and known or 0 1055 * Used by some WAV based audio codecs. 1056 */ 1057 int block_align; 1058 1059 /** 1060 * Audio cutoff bandwidth (0 means "automatic") 1061 * - encoding: Set by user. 1062 * - decoding: unused 1063 */ 1064 int cutoff; 1065 1066 /** 1067 * Type of service that the audio stream conveys. 1068 * - encoding: Set by user. 1069 * - decoding: Set by libavcodec. 1070 */ 1071 enum AVAudioServiceType audio_service_type; 1072 1073 /** 1074 * desired sample format 1075 * - encoding: Not used. 1076 * - decoding: Set by user. 1077 * Decoder will decode to this format if it can. 1078 */ 1079 enum AVSampleFormat request_sample_fmt; 1080 1081 /** 1082 * Audio only. The number of "priming" samples (padding) inserted by the 1083 * encoder at the beginning of the audio. I.e. this number of leading 1084 * decoded samples must be discarded by the caller to get the original audio 1085 * without leading padding. 1086 * 1087 * - decoding: unused 1088 * - encoding: Set by libavcodec. The timestamps on the output packets are 1089 * adjusted by the encoder so that they always refer to the 1090 * first sample of the data actually contained in the packet, 1091 * including any added padding. E.g. if the timebase is 1092 * 1/samplerate and the timestamp of the first input sample is 1093 * 0, the timestamp of the first output packet will be 1094 * -initial_padding. 1095 */ 1096 int initial_padding; 1097 1098 /** 1099 * Audio only. The amount of padding (in samples) appended by the encoder to 1100 * the end of the audio. I.e. this number of decoded samples must be 1101 * discarded by the caller from the end of the stream to get the original 1102 * audio without any trailing padding. 1103 * 1104 * - decoding: unused 1105 * - encoding: unused 1106 */ 1107 int trailing_padding; 1108 1109 /** 1110 * Number of samples to skip after a discontinuity 1111 * - decoding: unused 1112 * - encoding: set by libavcodec 1113 */ 1114 int seek_preroll; 1115 1116 /** 1117 * This callback is called at the beginning of each frame to get data 1118 * buffer(s) for it. There may be one contiguous buffer for all the data or 1119 * there may be a buffer per each data plane or anything in between. What 1120 * this means is, you may set however many entries in buf[] you feel necessary. 1121 * Each buffer must be reference-counted using the AVBuffer API (see description 1122 * of buf[] below). 1123 * 1124 * The following fields will be set in the frame before this callback is 1125 * called: 1126 * - format 1127 * - width, height (video only) 1128 * - sample_rate, channel_layout, nb_samples (audio only) 1129 * Their values may differ from the corresponding values in 1130 * AVCodecContext. This callback must use the frame values, not the codec 1131 * context values, to calculate the required buffer size. 1132 * 1133 * This callback must fill the following fields in the frame: 1134 * - data[] 1135 * - linesize[] 1136 * - extended_data: 1137 * * if the data is planar audio with more than 8 channels, then this 1138 * callback must allocate and fill extended_data to contain all pointers 1139 * to all data planes. data[] must hold as many pointers as it can. 1140 * extended_data must be allocated with av_malloc() and will be freed in 1141 * av_frame_unref(). 1142 * * otherwise extended_data must point to data 1143 * - buf[] must contain one or more pointers to AVBufferRef structures. Each of 1144 * the frame's data and extended_data pointers must be contained in these. That 1145 * is, one AVBufferRef for each allocated chunk of memory, not necessarily one 1146 * AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(), 1147 * and av_buffer_ref(). 1148 * - extended_buf and nb_extended_buf must be allocated with av_malloc() by 1149 * this callback and filled with the extra buffers if there are more 1150 * buffers than buf[] can hold. extended_buf will be freed in 1151 * av_frame_unref(). 1152 * Decoders will generally initialize the whole buffer before it is output 1153 * but it can in rare error conditions happen that uninitialized data is passed 1154 * through. \important The buffers returned by get_buffer* should thus not contain sensitive 1155 * data. 1156 * 1157 * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call 1158 * avcodec_default_get_buffer2() instead of providing buffers allocated by 1159 * some other means. 1160 * 1161 * Each data plane must be aligned to the maximum required by the target 1162 * CPU. 1163 * 1164 * @see avcodec_default_get_buffer2() 1165 * 1166 * Video: 1167 * 1168 * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused 1169 * (read and/or written to if it is writable) later by libavcodec. 1170 * 1171 * avcodec_align_dimensions2() should be used to find the required width and 1172 * height, as they normally need to be rounded up to the next multiple of 16. 1173 * 1174 * Some decoders do not support linesizes changing between frames. 1175 * 1176 * If frame multithreading is used, this callback may be called from a 1177 * different thread, but not from more than one at once. Does not need to be 1178 * reentrant. 1179 * 1180 * @see avcodec_align_dimensions2() 1181 * 1182 * Audio: 1183 * 1184 * Decoders request a buffer of a particular size by setting 1185 * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may, 1186 * however, utilize only part of the buffer by setting AVFrame.nb_samples 1187 * to a smaller value in the output frame. 1188 * 1189 * As a convenience, av_samples_get_buffer_size() and 1190 * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2() 1191 * functions to find the required data size and to fill data pointers and 1192 * linesize. In AVFrame.linesize, only linesize[0] may be set for audio 1193 * since all planes must be the same size. 1194 * 1195 * @see av_samples_get_buffer_size(), av_samples_fill_arrays() 1196 * 1197 * - encoding: unused 1198 * - decoding: Set by libavcodec, user can override. 1199 */ 1200 int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags); 1201 1202 /* - encoding parameters */ 1203 /** 1204 * number of bits the bitstream is allowed to diverge from the reference. 1205 * the reference can be CBR (for CBR pass1) or VBR (for pass2) 1206 * - encoding: Set by user; unused for constant quantizer encoding. 1207 * - decoding: unused 1208 */ 1209 int bit_rate_tolerance; 1210 1211 /** 1212 * Global quality for codecs which cannot change it per frame. 1213 * This should be proportional to MPEG-1/2/4 qscale. 1214 * - encoding: Set by user. 1215 * - decoding: unused 1216 */ 1217 int global_quality; 1218 1219 /** 1220 * - encoding: Set by user. 1221 * - decoding: unused 1222 */ 1223 int compression_level; 1224 #define FF_COMPRESSION_DEFAULT -1 1225 1226 float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0) 1227 float qblur; ///< amount of qscale smoothing over time (0.0-1.0) 1228 1229 /** 1230 * minimum quantizer 1231 * - encoding: Set by user. 1232 * - decoding: unused 1233 */ 1234 int qmin; 1235 1236 /** 1237 * maximum quantizer 1238 * - encoding: Set by user. 1239 * - decoding: unused 1240 */ 1241 int qmax; 1242 1243 /** 1244 * maximum quantizer difference between frames 1245 * - encoding: Set by user. 1246 * - decoding: unused 1247 */ 1248 int max_qdiff; 1249 1250 /** 1251 * decoder bitstream buffer size 1252 * - encoding: Set by user. 1253 * - decoding: May be set by libavcodec. 1254 */ 1255 int rc_buffer_size; 1256 1257 /** 1258 * ratecontrol override, see RcOverride 1259 * - encoding: Allocated/set/freed by user. 1260 * - decoding: unused 1261 */ 1262 int rc_override_count; 1263 RcOverride *rc_override; 1264 1265 /** 1266 * maximum bitrate 1267 * - encoding: Set by user. 1268 * - decoding: Set by user, may be overwritten by libavcodec. 1269 */ 1270 int64_t rc_max_rate; 1271 1272 /** 1273 * minimum bitrate 1274 * - encoding: Set by user. 1275 * - decoding: unused 1276 */ 1277 int64_t rc_min_rate; 1278 1279 /** 1280 * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow. 1281 * - encoding: Set by user. 1282 * - decoding: unused. 1283 */ 1284 float rc_max_available_vbv_use; 1285 1286 /** 1287 * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow. 1288 * - encoding: Set by user. 1289 * - decoding: unused. 1290 */ 1291 float rc_min_vbv_overflow_use; 1292 1293 /** 1294 * Number of bits which should be loaded into the rc buffer before decoding starts. 1295 * - encoding: Set by user. 1296 * - decoding: unused 1297 */ 1298 int rc_initial_buffer_occupancy; 1299 1300 /** 1301 * trellis RD quantization 1302 * - encoding: Set by user. 1303 * - decoding: unused 1304 */ 1305 int trellis; 1306 1307 /** 1308 * pass1 encoding statistics output buffer 1309 * - encoding: Set by libavcodec. 1310 * - decoding: unused 1311 */ 1312 char *stats_out; 1313 1314 /** 1315 * pass2 encoding statistics input buffer 1316 * Concatenated stuff from stats_out of pass1 should be placed here. 1317 * - encoding: Allocated/set/freed by user. 1318 * - decoding: unused 1319 */ 1320 char *stats_in; 1321 1322 /** 1323 * Work around bugs in encoders which sometimes cannot be detected automatically. 1324 * - encoding: Set by user 1325 * - decoding: Set by user 1326 */ 1327 int workaround_bugs; 1328 #define FF_BUG_AUTODETECT 1 ///< autodetection 1329 #define FF_BUG_XVID_ILACE 4 1330 #define FF_BUG_UMP4 8 1331 #define FF_BUG_NO_PADDING 16 1332 #define FF_BUG_AMV 32 1333 #define FF_BUG_QPEL_CHROMA 64 1334 #define FF_BUG_STD_QPEL 128 1335 #define FF_BUG_QPEL_CHROMA2 256 1336 #define FF_BUG_DIRECT_BLOCKSIZE 512 1337 #define FF_BUG_EDGE 1024 1338 #define FF_BUG_HPEL_CHROMA 2048 1339 #define FF_BUG_DC_CLIP 4096 1340 #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. 1341 #define FF_BUG_TRUNCATED 16384 1342 #define FF_BUG_IEDGE 32768 1343 1344 /** 1345 * strictly follow the standard (MPEG-4, ...). 1346 * - encoding: Set by user. 1347 * - decoding: Set by user. 1348 * Setting this to STRICT or higher means the encoder and decoder will 1349 * generally do stupid things, whereas setting it to unofficial or lower 1350 * will mean the encoder might produce output that is not supported by all 1351 * spec-compliant decoders. Decoders don't differentiate between normal, 1352 * unofficial and experimental (that is, they always try to decode things 1353 * when they can) unless they are explicitly asked to behave stupidly 1354 * (=strictly conform to the specs) 1355 * This may only be set to one of the FF_COMPLIANCE_* values in defs.h. 1356 */ 1357 int strict_std_compliance; 1358 1359 /** 1360 * error concealment flags 1361 * - encoding: unused 1362 * - decoding: Set by user. 1363 */ 1364 int error_concealment; 1365 #define FF_EC_GUESS_MVS 1 1366 #define FF_EC_DEBLOCK 2 1367 #define FF_EC_FAVOR_INTER 256 1368 1369 /** 1370 * debug 1371 * - encoding: Set by user. 1372 * - decoding: Set by user. 1373 */ 1374 int debug; 1375 #define FF_DEBUG_PICT_INFO 1 1376 #define FF_DEBUG_RC 2 1377 #define FF_DEBUG_BITSTREAM 4 1378 #define FF_DEBUG_MB_TYPE 8 1379 #define FF_DEBUG_QP 16 1380 #define FF_DEBUG_DCT_COEFF 0x00000040 1381 #define FF_DEBUG_SKIP 0x00000080 1382 #define FF_DEBUG_STARTCODE 0x00000100 1383 #define FF_DEBUG_ER 0x00000400 1384 #define FF_DEBUG_MMCO 0x00000800 1385 #define FF_DEBUG_BUGS 0x00001000 1386 #define FF_DEBUG_BUFFERS 0x00008000 1387 #define FF_DEBUG_THREADS 0x00010000 1388 #define FF_DEBUG_GREEN_MD 0x00800000 1389 #define FF_DEBUG_NOMC 0x01000000 1390 1391 /** 1392 * Error recognition; may misdetect some more or less valid parts as errors. 1393 * This is a bitfield of the AV_EF_* values defined in defs.h. 1394 * 1395 * - encoding: Set by user. 1396 * - decoding: Set by user. 1397 */ 1398 int err_recognition; 1399 1400 /** 1401 * Hardware accelerator in use 1402 * - encoding: unused. 1403 * - decoding: Set by libavcodec 1404 */ 1405 const struct AVHWAccel *hwaccel; 1406 1407 /** 1408 * Legacy hardware accelerator context. 1409 * 1410 * For some hardware acceleration methods, the caller may use this field to 1411 * signal hwaccel-specific data to the codec. The struct pointed to by this 1412 * pointer is hwaccel-dependent and defined in the respective header. Please 1413 * refer to the FFmpeg HW accelerator documentation to know how to fill 1414 * this. 1415 * 1416 * In most cases this field is optional - the necessary information may also 1417 * be provided to libavcodec through @ref hw_frames_ctx or @ref 1418 * hw_device_ctx (see avcodec_get_hw_config()). However, in some cases it 1419 * may be the only method of signalling some (optional) information. 1420 * 1421 * The struct and its contents are owned by the caller. 1422 * 1423 * - encoding: May be set by the caller before avcodec_open2(). Must remain 1424 * valid until avcodec_free_context(). 1425 * - decoding: May be set by the caller in the get_format() callback. 1426 * Must remain valid until the next get_format() call, 1427 * or avcodec_free_context() (whichever comes first). 1428 */ 1429 void *hwaccel_context; 1430 1431 /** 1432 * A reference to the AVHWFramesContext describing the input (for encoding) 1433 * or output (decoding) frames. The reference is set by the caller and 1434 * afterwards owned (and freed) by libavcodec - it should never be read by 1435 * the caller after being set. 1436 * 1437 * - decoding: This field should be set by the caller from the get_format() 1438 * callback. The previous reference (if any) will always be 1439 * unreffed by libavcodec before the get_format() call. 1440 * 1441 * If the default get_buffer2() is used with a hwaccel pixel 1442 * format, then this AVHWFramesContext will be used for 1443 * allocating the frame buffers. 1444 * 1445 * - encoding: For hardware encoders configured to use a hwaccel pixel 1446 * format, this field should be set by the caller to a reference 1447 * to the AVHWFramesContext describing input frames. 1448 * AVHWFramesContext.format must be equal to 1449 * AVCodecContext.pix_fmt. 1450 * 1451 * This field should be set before avcodec_open2() is called. 1452 */ 1453 AVBufferRef *hw_frames_ctx; 1454 1455 /** 1456 * A reference to the AVHWDeviceContext describing the device which will 1457 * be used by a hardware encoder/decoder. The reference is set by the 1458 * caller and afterwards owned (and freed) by libavcodec. 1459 * 1460 * This should be used if either the codec device does not require 1461 * hardware frames or any that are used are to be allocated internally by 1462 * libavcodec. If the user wishes to supply any of the frames used as 1463 * encoder input or decoder output then hw_frames_ctx should be used 1464 * instead. When hw_frames_ctx is set in get_format() for a decoder, this 1465 * field will be ignored while decoding the associated stream segment, but 1466 * may again be used on a following one after another get_format() call. 1467 * 1468 * For both encoders and decoders this field should be set before 1469 * avcodec_open2() is called and must not be written to thereafter. 1470 * 1471 * Note that some decoders may require this field to be set initially in 1472 * order to support hw_frames_ctx at all - in that case, all frames 1473 * contexts used must be created on the same device. 1474 */ 1475 AVBufferRef *hw_device_ctx; 1476 1477 /** 1478 * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated 1479 * decoding (if active). 1480 * - encoding: unused 1481 * - decoding: Set by user (either before avcodec_open2(), or in the 1482 * AVCodecContext.get_format callback) 1483 */ 1484 int hwaccel_flags; 1485 1486 /** 1487 * Video decoding only. Sets the number of extra hardware frames which 1488 * the decoder will allocate for use by the caller. This must be set 1489 * before avcodec_open2() is called. 1490 * 1491 * Some hardware decoders require all frames that they will use for 1492 * output to be defined in advance before decoding starts. For such 1493 * decoders, the hardware frame pool must therefore be of a fixed size. 1494 * The extra frames set here are on top of any number that the decoder 1495 * needs internally in order to operate normally (for example, frames 1496 * used as reference pictures). 1497 */ 1498 int extra_hw_frames; 1499 1500 /** 1501 * error 1502 * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR. 1503 * - decoding: unused 1504 */ 1505 uint64_t error[AV_NUM_DATA_POINTERS]; 1506 1507 /** 1508 * DCT algorithm, see FF_DCT_* below 1509 * - encoding: Set by user. 1510 * - decoding: unused 1511 */ 1512 int dct_algo; 1513 #define FF_DCT_AUTO 0 1514 #define FF_DCT_FASTINT 1 1515 #define FF_DCT_INT 2 1516 #define FF_DCT_MMX 3 1517 #define FF_DCT_ALTIVEC 5 1518 #define FF_DCT_FAAN 6 1519 #define FF_DCT_NEON 7 1520 1521 /** 1522 * IDCT algorithm, see FF_IDCT_* below. 1523 * - encoding: Set by user. 1524 * - decoding: Set by user. 1525 */ 1526 int idct_algo; 1527 #define FF_IDCT_AUTO 0 1528 #define FF_IDCT_INT 1 1529 #define FF_IDCT_SIMPLE 2 1530 #define FF_IDCT_SIMPLEMMX 3 1531 #define FF_IDCT_ARM 7 1532 #define FF_IDCT_ALTIVEC 8 1533 #define FF_IDCT_SIMPLEARM 10 1534 #define FF_IDCT_XVID 14 1535 #define FF_IDCT_SIMPLEARMV5TE 16 1536 #define FF_IDCT_SIMPLEARMV6 17 1537 #define FF_IDCT_FAAN 20 1538 #define FF_IDCT_SIMPLENEON 22 1539 #define FF_IDCT_SIMPLEAUTO 128 1540 1541 /** 1542 * bits per sample/pixel from the demuxer (needed for huffyuv). 1543 * - encoding: Set by libavcodec. 1544 * - decoding: Set by user. 1545 */ 1546 int bits_per_coded_sample; 1547 1548 /** 1549 * Bits per sample/pixel of internal libavcodec pixel/sample format. 1550 * - encoding: set by user. 1551 * - decoding: set by libavcodec. 1552 */ 1553 int bits_per_raw_sample; 1554 1555 /** 1556 * thread count 1557 * is used to decide how many independent tasks should be passed to execute() 1558 * - encoding: Set by user. 1559 * - decoding: Set by user. 1560 */ 1561 int thread_count; 1562 1563 /** 1564 * Which multithreading methods to use. 1565 * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread, 1566 * so clients which cannot provide future frames should not use it. 1567 * 1568 * - encoding: Set by user, otherwise the default is used. 1569 * - decoding: Set by user, otherwise the default is used. 1570 */ 1571 int thread_type; 1572 #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once 1573 #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once 1574 1575 /** 1576 * Which multithreading methods are in use by the codec. 1577 * - encoding: Set by libavcodec. 1578 * - decoding: Set by libavcodec. 1579 */ 1580 int active_thread_type; 1581 1582 /** 1583 * The codec may call this to execute several independent things. 1584 * It will return only after finishing all tasks. 1585 * The user may replace this with some multithreaded implementation, 1586 * the default implementation will execute the parts serially. 1587 * @param count the number of things to execute 1588 * - encoding: Set by libavcodec, user can override. 1589 * - decoding: Set by libavcodec, user can override. 1590 */ 1591 int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size); 1592 1593 /** 1594 * The codec may call this to execute several independent things. 1595 * It will return only after finishing all tasks. 1596 * The user may replace this with some multithreaded implementation, 1597 * the default implementation will execute the parts serially. 1598 * @param c context passed also to func 1599 * @param count the number of things to execute 1600 * @param arg2 argument passed unchanged to func 1601 * @param ret return values of executed functions, must have space for "count" values. May be NULL. 1602 * @param func function that will be called count times, with jobnr from 0 to count-1. 1603 * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no 1604 * two instances of func executing at the same time will have the same threadnr. 1605 * @return always 0 currently, but code should handle a future improvement where when any call to func 1606 * returns < 0 no further calls to func may be done and < 0 is returned. 1607 * - encoding: Set by libavcodec, user can override. 1608 * - decoding: Set by libavcodec, user can override. 1609 */ 1610 int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count); 1611 1612 /** 1613 * profile 1614 * - encoding: Set by user. 1615 * - decoding: Set by libavcodec. 1616 * See the AV_PROFILE_* defines in defs.h. 1617 */ 1618 int profile; 1619 1620 /** 1621 * Encoding level descriptor. 1622 * - encoding: Set by user, corresponds to a specific level defined by the 1623 * codec, usually corresponding to the profile level, if not specified it 1624 * is set to AV_LEVEL_UNKNOWN. 1625 * - decoding: Set by libavcodec. 1626 * See AV_LEVEL_* in defs.h. 1627 */ 1628 int level; 1629 1630 #if FF_API_CODEC_PROPS 1631 /** 1632 * Properties of the stream that gets decoded 1633 * - encoding: unused 1634 * - decoding: set by libavcodec 1635 */ 1636 attribute_deprecated 1637 unsigned properties; 1638 #define FF_CODEC_PROPERTY_LOSSLESS 0x00000001 1639 #define FF_CODEC_PROPERTY_CLOSED_CAPTIONS 0x00000002 1640 #define FF_CODEC_PROPERTY_FILM_GRAIN 0x00000004 1641 #endif 1642 1643 /** 1644 * Skip loop filtering for selected frames. 1645 * - encoding: unused 1646 * - decoding: Set by user. 1647 */ 1648 enum AVDiscard skip_loop_filter; 1649 1650 /** 1651 * Skip IDCT/dequantization for selected frames. 1652 * - encoding: unused 1653 * - decoding: Set by user. 1654 */ 1655 enum AVDiscard skip_idct; 1656 1657 /** 1658 * Skip decoding for selected frames. 1659 * - encoding: unused 1660 * - decoding: Set by user. 1661 */ 1662 enum AVDiscard skip_frame; 1663 1664 /** 1665 * Skip processing alpha if supported by codec. 1666 * Note that if the format uses pre-multiplied alpha (common with VP6, 1667 * and recommended due to better video quality/compression) 1668 * the image will look as if alpha-blended onto a black background. 1669 * However for formats that do not use pre-multiplied alpha 1670 * there might be serious artefacts (though e.g. libswscale currently 1671 * assumes pre-multiplied alpha anyway). 1672 * 1673 * - decoding: set by user 1674 * - encoding: unused 1675 */ 1676 int skip_alpha; 1677 1678 /** 1679 * Number of macroblock rows at the top which are skipped. 1680 * - encoding: unused 1681 * - decoding: Set by user. 1682 */ 1683 int skip_top; 1684 1685 /** 1686 * Number of macroblock rows at the bottom which are skipped. 1687 * - encoding: unused 1688 * - decoding: Set by user. 1689 */ 1690 int skip_bottom; 1691 1692 /** 1693 * low resolution decoding, 1-> 1/2 size, 2->1/4 size 1694 * - encoding: unused 1695 * - decoding: Set by user. 1696 */ 1697 int lowres; 1698 1699 /** 1700 * AVCodecDescriptor 1701 * - encoding: unused. 1702 * - decoding: set by libavcodec. 1703 */ 1704 const struct AVCodecDescriptor *codec_descriptor; 1705 1706 /** 1707 * Character encoding of the input subtitles file. 1708 * - decoding: set by user 1709 * - encoding: unused 1710 */ 1711 char *sub_charenc; 1712 1713 /** 1714 * Subtitles character encoding mode. Formats or codecs might be adjusting 1715 * this setting (if they are doing the conversion themselves for instance). 1716 * - decoding: set by libavcodec 1717 * - encoding: unused 1718 */ 1719 int sub_charenc_mode; 1720 #define FF_SUB_CHARENC_MODE_DO_NOTHING -1 ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance) 1721 #define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself 1722 #define FF_SUB_CHARENC_MODE_PRE_DECODER 1 ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv 1723 #define FF_SUB_CHARENC_MODE_IGNORE 2 ///< neither convert the subtitles, nor check them for valid UTF-8 1724 1725 /** 1726 * Header containing style information for text subtitles. 1727 * For SUBTITLE_ASS subtitle type, it should contain the whole ASS 1728 * [Script Info] and [V4+ Styles] section, plus the [Events] line and 1729 * the Format line following. It shouldn't include any Dialogue line. 1730 * 1731 * - encoding: May be set by the caller before avcodec_open2() to an array 1732 * allocated with the av_malloc() family of functions. 1733 * - decoding: May be set by libavcodec in avcodec_open2(). 1734 * 1735 * After being set, the array is owned by the codec and freed in 1736 * avcodec_free_context(). 1737 */ 1738 int subtitle_header_size; 1739 uint8_t *subtitle_header; 1740 1741 /** 1742 * dump format separator. 1743 * can be ", " or "\n " or anything else 1744 * - encoding: Set by user. 1745 * - decoding: Set by user. 1746 */ 1747 uint8_t *dump_separator; 1748 1749 /** 1750 * ',' separated list of allowed decoders. 1751 * If NULL then all are allowed 1752 * - encoding: unused 1753 * - decoding: set by user 1754 */ 1755 char *codec_whitelist; 1756 1757 /** 1758 * Additional data associated with the entire coded stream. 1759 * 1760 * - decoding: may be set by user before calling avcodec_open2(). 1761 * - encoding: may be set by libavcodec after avcodec_open2(). 1762 */ 1763 AVPacketSideData *coded_side_data; 1764 int nb_coded_side_data; 1765 1766 /** 1767 * Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of 1768 * metadata exported in frame, packet, or coded stream side data by 1769 * decoders and encoders. 1770 * 1771 * - decoding: set by user 1772 * - encoding: set by user 1773 */ 1774 int export_side_data; 1775 1776 /** 1777 * The number of pixels per image to maximally accept. 1778 * 1779 * - decoding: set by user 1780 * - encoding: set by user 1781 */ 1782 int64_t max_pixels; 1783 1784 /** 1785 * Video decoding only. Certain video codecs support cropping, meaning that 1786 * only a sub-rectangle of the decoded frame is intended for display. This 1787 * option controls how cropping is handled by libavcodec. 1788 * 1789 * When set to 1 (the default), libavcodec will apply cropping internally. 1790 * I.e. it will modify the output frame width/height fields and offset the 1791 * data pointers (only by as much as possible while preserving alignment, or 1792 * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that 1793 * the frames output by the decoder refer only to the cropped area. The 1794 * crop_* fields of the output frames will be zero. 1795 * 1796 * When set to 0, the width/height fields of the output frames will be set 1797 * to the coded dimensions and the crop_* fields will describe the cropping 1798 * rectangle. Applying the cropping is left to the caller. 1799 * 1800 * @warning When hardware acceleration with opaque output frames is used, 1801 * libavcodec is unable to apply cropping from the top/left border. 1802 * 1803 * @note when this option is set to zero, the width/height fields of the 1804 * AVCodecContext and output AVFrames have different meanings. The codec 1805 * context fields store display dimensions (with the coded dimensions in 1806 * coded_width/height), while the frame fields store the coded dimensions 1807 * (with the display dimensions being determined by the crop_* fields). 1808 */ 1809 int apply_cropping; 1810 1811 /** 1812 * The percentage of damaged samples to discard a frame. 1813 * 1814 * - decoding: set by user 1815 * - encoding: unused 1816 */ 1817 int discard_damaged_percentage; 1818 1819 /** 1820 * The number of samples per frame to maximally accept. 1821 * 1822 * - decoding: set by user 1823 * - encoding: set by user 1824 */ 1825 int64_t max_samples; 1826 1827 /** 1828 * This callback is called at the beginning of each packet to get a data 1829 * buffer for it. 1830 * 1831 * The following field will be set in the packet before this callback is 1832 * called: 1833 * - size 1834 * This callback must use the above value to calculate the required buffer size, 1835 * which must padded by at least AV_INPUT_BUFFER_PADDING_SIZE bytes. 1836 * 1837 * In some specific cases, the encoder may not use the entire buffer allocated by this 1838 * callback. This will be reflected in the size value in the packet once returned by 1839 * avcodec_receive_packet(). 1840 * 1841 * This callback must fill the following fields in the packet: 1842 * - data: alignment requirements for AVPacket apply, if any. Some architectures and 1843 * encoders may benefit from having aligned data. 1844 * - buf: must contain a pointer to an AVBufferRef structure. The packet's 1845 * data pointer must be contained in it. See: av_buffer_create(), av_buffer_alloc(), 1846 * and av_buffer_ref(). 1847 * 1848 * If AV_CODEC_CAP_DR1 is not set then get_encode_buffer() must call 1849 * avcodec_default_get_encode_buffer() instead of providing a buffer allocated by 1850 * some other means. 1851 * 1852 * The flags field may contain a combination of AV_GET_ENCODE_BUFFER_FLAG_ flags. 1853 * They may be used for example to hint what use the buffer may get after being 1854 * created. 1855 * Implementations of this callback may ignore flags they don't understand. 1856 * If AV_GET_ENCODE_BUFFER_FLAG_REF is set in flags then the packet may be reused 1857 * (read and/or written to if it is writable) later by libavcodec. 1858 * 1859 * This callback must be thread-safe, as when frame threading is used, it may 1860 * be called from multiple threads simultaneously. 1861 * 1862 * @see avcodec_default_get_encode_buffer() 1863 * 1864 * - encoding: Set by libavcodec, user can override. 1865 * - decoding: unused 1866 */ 1867 int (*get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int flags); 1868 1869 /** 1870 * Frame counter, set by libavcodec. 1871 * 1872 * - decoding: total number of frames returned from the decoder so far. 1873 * - encoding: total number of frames passed to the encoder so far. 1874 * 1875 * @note the counter is not incremented if encoding/decoding resulted in 1876 * an error. 1877 */ 1878 int64_t frame_num; 1879 1880 /** 1881 * Decoding only. May be set by the caller before avcodec_open2() to an 1882 * av_malloc()'ed array (or via AVOptions). Owned and freed by the decoder 1883 * afterwards. 1884 * 1885 * Side data attached to decoded frames may come from several sources: 1886 * 1. coded_side_data, which the decoder will for certain types translate 1887 * from packet-type to frame-type and attach to frames; 1888 * 2. side data attached to an AVPacket sent for decoding (same 1889 * considerations as above); 1890 * 3. extracted from the coded bytestream. 1891 * The first two cases are supplied by the caller and typically come from a 1892 * container. 1893 * 1894 * This array configures decoder behaviour in cases when side data of the 1895 * same type is present both in the coded bytestream and in the 1896 * user-supplied side data (items 1. and 2. above). In all cases, at most 1897 * one instance of each side data type will be attached to output frames. By 1898 * default it will be the bytestream side data. Adding an 1899 * AVPacketSideDataType value to this array will flip the preference for 1900 * this type, thus making the decoder prefer user-supplied side data over 1901 * bytestream. In case side data of the same type is present both in 1902 * coded_data and attacked to a packet, the packet instance always has 1903 * priority. 1904 * 1905 * The array may also contain a single -1, in which case the preference is 1906 * switched for all side data types. 1907 */ 1908 int *side_data_prefer_packet; 1909 /** 1910 * Number of entries in side_data_prefer_packet. 1911 */ 1912 unsigned nb_side_data_prefer_packet; 1913 1914 /** 1915 * Array containing static side data, such as HDR10 CLL / MDCV structures. 1916 * Side data entries should be allocated by usage of helpers defined in 1917 * libavutil/frame.h. 1918 * 1919 * - encoding: may be set by user before calling avcodec_open2() for 1920 * encoder configuration. Afterwards owned and freed by the 1921 * encoder. 1922 * - decoding: may be set by libavcodec in avcodec_open2(). 1923 */ 1924 AVFrameSideData **decoded_side_data; 1925 int nb_decoded_side_data; 1926 } AVCodecContext; 1927 1928 /** 1929 * @defgroup lavc_hwaccel AVHWAccel 1930 * 1931 * @note Nothing in this structure should be accessed by the user. At some 1932 * point in future it will not be externally visible at all. 1933 * 1934 * @{ 1935 */ 1936 typedef struct AVHWAccel { 1937 /** 1938 * Name of the hardware accelerated codec. 1939 * The name is globally unique among encoders and among decoders (but an 1940 * encoder and a decoder can share the same name). 1941 */ 1942 const char *name; 1943 1944 /** 1945 * Type of codec implemented by the hardware accelerator. 1946 * 1947 * See AVMEDIA_TYPE_xxx 1948 */ 1949 enum AVMediaType type; 1950 1951 /** 1952 * Codec implemented by the hardware accelerator. 1953 * 1954 * See AV_CODEC_ID_xxx 1955 */ 1956 enum AVCodecID id; 1957 1958 /** 1959 * Supported pixel format. 1960 * 1961 * Only hardware accelerated formats are supported here. 1962 */ 1963 enum AVPixelFormat pix_fmt; 1964 1965 /** 1966 * Hardware accelerated codec capabilities. 1967 * see AV_HWACCEL_CODEC_CAP_* 1968 */ 1969 int capabilities; 1970 } AVHWAccel; 1971 1972 /** 1973 * HWAccel is experimental and is thus avoided in favor of non experimental 1974 * codecs 1975 */ 1976 #define AV_HWACCEL_CODEC_CAP_EXPERIMENTAL 0x0200 1977 1978 /** 1979 * Hardware acceleration should be used for decoding even if the codec level 1980 * used is unknown or higher than the maximum supported level reported by the 1981 * hardware driver. 1982 * 1983 * It's generally a good idea to pass this flag unless you have a specific 1984 * reason not to, as hardware tends to under-report supported levels. 1985 */ 1986 #define AV_HWACCEL_FLAG_IGNORE_LEVEL (1 << 0) 1987 1988 /** 1989 * Hardware acceleration can output YUV pixel formats with a different chroma 1990 * sampling than 4:2:0 and/or other than 8 bits per component. 1991 */ 1992 #define AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH (1 << 1) 1993 1994 /** 1995 * Hardware acceleration should still be attempted for decoding when the 1996 * codec profile does not match the reported capabilities of the hardware. 1997 * 1998 * For example, this can be used to try to decode baseline profile H.264 1999 * streams in hardware - it will often succeed, because many streams marked 2000 * as baseline profile actually conform to constrained baseline profile. 2001 * 2002 * @warning If the stream is actually not supported then the behaviour is 2003 * undefined, and may include returning entirely incorrect output 2004 * while indicating success. 2005 */ 2006 #define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH (1 << 2) 2007 2008 /** 2009 * Some hardware decoders (namely nvdec) can either output direct decoder 2010 * surfaces, or make an on-device copy and return said copy. 2011 * There is a hard limit on how many decoder surfaces there can be, and it 2012 * cannot be accurately guessed ahead of time. 2013 * For some processing chains, this can be okay, but others will run into the 2014 * limit and in turn produce very confusing errors that require fine tuning of 2015 * more or less obscure options by the user, or in extreme cases cannot be 2016 * resolved at all without inserting an avfilter that forces a copy. 2017 * 2018 * Thus, the hwaccel will by default make a copy for safety and resilience. 2019 * If a users really wants to minimize the amount of copies, they can set this 2020 * flag and ensure their processing chain does not exhaust the surface pool. 2021 */ 2022 #define AV_HWACCEL_FLAG_UNSAFE_OUTPUT (1 << 3) 2023 2024 /** 2025 * @} 2026 */ 2027 2028 enum AVSubtitleType { 2029 SUBTITLE_NONE, 2030 2031 SUBTITLE_BITMAP, ///< A bitmap, pict will be set 2032 2033 /** 2034 * Plain text, the text field must be set by the decoder and is 2035 * authoritative. ass and pict fields may contain approximations. 2036 */ 2037 SUBTITLE_TEXT, 2038 2039 /** 2040 * Formatted text, the ass field must be set by the decoder and is 2041 * authoritative. pict and text fields may contain approximations. 2042 */ 2043 SUBTITLE_ASS, 2044 }; 2045 2046 #define AV_SUBTITLE_FLAG_FORCED 0x00000001 2047 2048 typedef struct AVSubtitleRect { 2049 int x; ///< top left corner of pict, undefined when pict is not set 2050 int y; ///< top left corner of pict, undefined when pict is not set 2051 int w; ///< width of pict, undefined when pict is not set 2052 int h; ///< height of pict, undefined when pict is not set 2053 int nb_colors; ///< number of colors in pict, undefined when pict is not set 2054 2055 /** 2056 * data+linesize for the bitmap of this subtitle. 2057 * Can be set for text/ass as well once they are rendered. 2058 */ 2059 uint8_t *data[4]; 2060 int linesize[4]; 2061 2062 int flags; 2063 enum AVSubtitleType type; 2064 2065 char *text; ///< 0 terminated plain UTF-8 text 2066 2067 /** 2068 * 0 terminated ASS/SSA compatible event line. 2069 * The presentation of this is unaffected by the other values in this 2070 * struct. 2071 */ 2072 char *ass; 2073 } AVSubtitleRect; 2074 2075 typedef struct AVSubtitle { 2076 uint16_t format; /* 0 = graphics */ 2077 uint32_t start_display_time; /* relative to packet pts, in ms */ 2078 uint32_t end_display_time; /* relative to packet pts, in ms */ 2079 unsigned num_rects; 2080 AVSubtitleRect **rects; 2081 int64_t pts; ///< Same as packet pts, in AV_TIME_BASE 2082 } AVSubtitle; 2083 2084 /** 2085 * Return the LIBAVCODEC_VERSION_INT constant. 2086 */ 2087 unsigned avcodec_version(void); 2088 2089 /** 2090 * Return the libavcodec build-time configuration. 2091 */ 2092 const char *avcodec_configuration(void); 2093 2094 /** 2095 * Return the libavcodec license. 2096 */ 2097 const char *avcodec_license(void); 2098 2099 /** 2100 * Allocate an AVCodecContext and set its fields to default values. The 2101 * resulting struct should be freed with avcodec_free_context(). 2102 * 2103 * @param codec if non-NULL, allocate private data and initialize defaults 2104 * for the given codec. It is illegal to then call avcodec_open2() 2105 * with a different codec. 2106 * If NULL, then the codec-specific defaults won't be initialized, 2107 * which may result in suboptimal default settings (this is 2108 * important mainly for encoders, e.g. libx264). 2109 * 2110 * @return An AVCodecContext filled with default values or NULL on failure. 2111 */ 2112 AVCodecContext *avcodec_alloc_context3(const AVCodec *codec); 2113 2114 /** 2115 * Free the codec context and everything associated with it and write NULL to 2116 * the provided pointer. 2117 */ 2118 void avcodec_free_context(AVCodecContext **avctx); 2119 2120 /** 2121 * Get the AVClass for AVCodecContext. It can be used in combination with 2122 * AV_OPT_SEARCH_FAKE_OBJ for examining options. 2123 * 2124 * @see av_opt_find(). 2125 */ 2126 const AVClass *avcodec_get_class(void); 2127 2128 /** 2129 * Get the AVClass for AVSubtitleRect. It can be used in combination with 2130 * AV_OPT_SEARCH_FAKE_OBJ for examining options. 2131 * 2132 * @see av_opt_find(). 2133 */ 2134 const AVClass *avcodec_get_subtitle_rect_class(void); 2135 2136 /** 2137 * Fill the parameters struct based on the values from the supplied codec 2138 * context. Any allocated fields in par are freed and replaced with duplicates 2139 * of the corresponding fields in codec. 2140 * 2141 * @return >= 0 on success, a negative AVERROR code on failure 2142 */ 2143 int avcodec_parameters_from_context(struct AVCodecParameters *par, 2144 const AVCodecContext *codec); 2145 2146 /** 2147 * Fill the codec context based on the values from the supplied codec 2148 * parameters. Any allocated fields in codec that have a corresponding field in 2149 * par are freed and replaced with duplicates of the corresponding field in par. 2150 * Fields in codec that do not have a counterpart in par are not touched. 2151 * 2152 * @return >= 0 on success, a negative AVERROR code on failure. 2153 */ 2154 int avcodec_parameters_to_context(AVCodecContext *codec, 2155 const struct AVCodecParameters *par); 2156 2157 /** 2158 * Initialize the AVCodecContext to use the given AVCodec. Prior to using this 2159 * function the context has to be allocated with avcodec_alloc_context3(). 2160 * 2161 * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), 2162 * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for 2163 * retrieving a codec. 2164 * 2165 * Depending on the codec, you might need to set options in the codec context 2166 * also for decoding (e.g. width, height, or the pixel or audio sample format in 2167 * the case the information is not available in the bitstream, as when decoding 2168 * raw audio or video). 2169 * 2170 * Options in the codec context can be set either by setting them in the options 2171 * AVDictionary, or by setting the values in the context itself, directly or by 2172 * using the av_opt_set() API before calling this function. 2173 * 2174 * Example: 2175 * @code 2176 * av_dict_set(&opts, "b", "2.5M", 0); 2177 * codec = avcodec_find_decoder(AV_CODEC_ID_H264); 2178 * if (!codec) 2179 * exit(1); 2180 * 2181 * context = avcodec_alloc_context3(codec); 2182 * 2183 * if (avcodec_open2(context, codec, opts) < 0) 2184 * exit(1); 2185 * @endcode 2186 * 2187 * In the case AVCodecParameters are available (e.g. when demuxing a stream 2188 * using libavformat, and accessing the AVStream contained in the demuxer), the 2189 * codec parameters can be copied to the codec context using 2190 * avcodec_parameters_to_context(), as in the following example: 2191 * 2192 * @code 2193 * AVStream *stream = ...; 2194 * context = avcodec_alloc_context3(codec); 2195 * if (avcodec_parameters_to_context(context, stream->codecpar) < 0) 2196 * exit(1); 2197 * if (avcodec_open2(context, codec, NULL) < 0) 2198 * exit(1); 2199 * @endcode 2200 * 2201 * @note Always call this function before using decoding routines (such as 2202 * @ref avcodec_receive_frame()). 2203 * 2204 * @param avctx The context to initialize. 2205 * @param codec The codec to open this context for. If a non-NULL codec has been 2206 * previously passed to avcodec_alloc_context3() or 2207 * for this context, then this parameter MUST be either NULL or 2208 * equal to the previously passed codec. 2209 * @param options A dictionary filled with AVCodecContext and codec-private 2210 * options, which are set on top of the options already set in 2211 * avctx, can be NULL. On return this object will be filled with 2212 * options that were not found in the avctx codec context. 2213 * 2214 * @return zero on success, a negative value on error 2215 * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(), 2216 * av_dict_set(), av_opt_set(), av_opt_find(), avcodec_parameters_to_context() 2217 */ 2218 int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options); 2219 2220 /** 2221 * Free all allocated data in the given subtitle struct. 2222 * 2223 * @param sub AVSubtitle to free. 2224 */ 2225 void avsubtitle_free(AVSubtitle *sub); 2226 2227 /** 2228 * @} 2229 */ 2230 2231 /** 2232 * @addtogroup lavc_decoding 2233 * @{ 2234 */ 2235 2236 /** 2237 * The default callback for AVCodecContext.get_buffer2(). It is made public so 2238 * it can be called by custom get_buffer2() implementations for decoders without 2239 * AV_CODEC_CAP_DR1 set. 2240 */ 2241 int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags); 2242 2243 /** 2244 * The default callback for AVCodecContext.get_encode_buffer(). It is made public so 2245 * it can be called by custom get_encode_buffer() implementations for encoders without 2246 * AV_CODEC_CAP_DR1 set. 2247 */ 2248 int avcodec_default_get_encode_buffer(AVCodecContext *s, AVPacket *pkt, int flags); 2249 2250 /** 2251 * Modify width and height values so that they will result in a memory 2252 * buffer that is acceptable for the codec if you do not use any horizontal 2253 * padding. 2254 * 2255 * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened. 2256 */ 2257 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height); 2258 2259 /** 2260 * Modify width and height values so that they will result in a memory 2261 * buffer that is acceptable for the codec if you also ensure that all 2262 * line sizes are a multiple of the respective linesize_align[i]. 2263 * 2264 * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened. 2265 */ 2266 void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, 2267 int linesize_align[AV_NUM_DATA_POINTERS]); 2268 2269 /** 2270 * Decode a subtitle message. 2271 * Return a negative value on error, otherwise return the number of bytes used. 2272 * If no subtitle could be decompressed, got_sub_ptr is zero. 2273 * Otherwise, the subtitle is stored in *sub. 2274 * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for 2275 * simplicity, because the performance difference is expected to be negligible 2276 * and reusing a get_buffer written for video codecs would probably perform badly 2277 * due to a potentially very different allocation pattern. 2278 * 2279 * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input 2280 * and output. This means that for some packets they will not immediately 2281 * produce decoded output and need to be flushed at the end of decoding to get 2282 * all the decoded data. Flushing is done by calling this function with packets 2283 * with avpkt->data set to NULL and avpkt->size set to 0 until it stops 2284 * returning subtitles. It is safe to flush even those decoders that are not 2285 * marked with AV_CODEC_CAP_DELAY, then no subtitles will be returned. 2286 * 2287 * @note The AVCodecContext MUST have been opened with @ref avcodec_open2() 2288 * before packets may be fed to the decoder. 2289 * 2290 * @param avctx the codec context 2291 * @param[out] sub The preallocated AVSubtitle in which the decoded subtitle will be stored, 2292 * must be freed with avsubtitle_free if *got_sub_ptr is set. 2293 * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero. 2294 * @param[in] avpkt The input AVPacket containing the input buffer. 2295 */ 2296 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, 2297 int *got_sub_ptr, const AVPacket *avpkt); 2298 2299 /** 2300 * Supply raw packet data as input to a decoder. 2301 * 2302 * Internally, this call will copy relevant AVCodecContext fields, which can 2303 * influence decoding per-packet, and apply them when the packet is actually 2304 * decoded. (For example AVCodecContext.skip_frame, which might direct the 2305 * decoder to drop the frame contained by the packet sent with this function.) 2306 * 2307 * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE 2308 * larger than the actual read bytes because some optimized bitstream 2309 * readers read 32 or 64 bits at once and could read over the end. 2310 * 2311 * @note The AVCodecContext MUST have been opened with @ref avcodec_open2() 2312 * before packets may be fed to the decoder. 2313 * 2314 * @param avctx codec context 2315 * @param[in] avpkt The input AVPacket. Usually, this will be a single video 2316 * frame, or several complete audio frames. 2317 * Ownership of the packet remains with the caller, and the 2318 * decoder will not write to the packet. The decoder may create 2319 * a reference to the packet data (or copy it if the packet is 2320 * not reference-counted). 2321 * Unlike with older APIs, the packet is always fully consumed, 2322 * and if it contains multiple frames (e.g. some audio codecs), 2323 * will require you to call avcodec_receive_frame() multiple 2324 * times afterwards before you can send a new packet. 2325 * It can be NULL (or an AVPacket with data set to NULL and 2326 * size set to 0); in this case, it is considered a flush 2327 * packet, which signals the end of the stream. Sending the 2328 * first flush packet will return success. Subsequent ones are 2329 * unnecessary and will return AVERROR_EOF. If the decoder 2330 * still has frames buffered, it will return them after sending 2331 * a flush packet. 2332 * 2333 * @retval 0 success 2334 * @retval AVERROR(EAGAIN) input is not accepted in the current state - user 2335 * must read output with avcodec_receive_frame() (once 2336 * all output is read, the packet should be resent, 2337 * and the call will not fail with EAGAIN). 2338 * @retval AVERROR_EOF the decoder has been flushed, and no new packets can be 2339 * sent to it (also returned if more than 1 flush 2340 * packet is sent) 2341 * @retval AVERROR(EINVAL) codec not opened, it is an encoder, or requires flush 2342 * @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar 2343 * @retval "another negative error code" legitimate decoding errors 2344 */ 2345 int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt); 2346 2347 /** 2348 * Return decoded output data from a decoder or encoder (when the 2349 * @ref AV_CODEC_FLAG_RECON_FRAME flag is used). 2350 * 2351 * @param avctx codec context 2352 * @param frame This will be set to a reference-counted video or audio 2353 * frame (depending on the decoder type) allocated by the 2354 * codec. Note that the function will always call 2355 * av_frame_unref(frame) before doing anything else. 2356 * 2357 * @retval 0 success, a frame was returned 2358 * @retval AVERROR(EAGAIN) output is not available in this state - user must 2359 * try to send new input 2360 * @retval AVERROR_EOF the codec has been fully flushed, and there will be 2361 * no more output frames 2362 * @retval AVERROR(EINVAL) codec not opened, or it is an encoder without the 2363 * @ref AV_CODEC_FLAG_RECON_FRAME flag enabled 2364 * @retval "other negative error code" legitimate decoding errors 2365 */ 2366 int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame); 2367 2368 /** 2369 * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet() 2370 * to retrieve buffered output packets. 2371 * 2372 * @param avctx codec context 2373 * @param[in] frame AVFrame containing the raw audio or video frame to be encoded. 2374 * Ownership of the frame remains with the caller, and the 2375 * encoder will not write to the frame. The encoder may create 2376 * a reference to the frame data (or copy it if the frame is 2377 * not reference-counted). 2378 * It can be NULL, in which case it is considered a flush 2379 * packet. This signals the end of the stream. If the encoder 2380 * still has packets buffered, it will return them after this 2381 * call. Once flushing mode has been entered, additional flush 2382 * packets are ignored, and sending frames will return 2383 * AVERROR_EOF. 2384 * 2385 * For audio: 2386 * If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame 2387 * can have any number of samples. 2388 * If it is not set, frame->nb_samples must be equal to 2389 * avctx->frame_size for all frames except the last. 2390 * The final frame may be smaller than avctx->frame_size. 2391 * @retval 0 success 2392 * @retval AVERROR(EAGAIN) input is not accepted in the current state - user must 2393 * read output with avcodec_receive_packet() (once all 2394 * output is read, the packet should be resent, and the 2395 * call will not fail with EAGAIN). 2396 * @retval AVERROR_EOF the encoder has been flushed, and no new frames can 2397 * be sent to it 2398 * @retval AVERROR(EINVAL) codec not opened, it is a decoder, or requires flush 2399 * @retval AVERROR(ENOMEM) failed to add packet to internal queue, or similar 2400 * @retval "another negative error code" legitimate encoding errors 2401 */ 2402 int avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame); 2403 2404 /** 2405 * Read encoded data from the encoder. 2406 * 2407 * @param avctx codec context 2408 * @param avpkt This will be set to a reference-counted packet allocated by the 2409 * encoder. Note that the function will always call 2410 * av_packet_unref(avpkt) before doing anything else. 2411 * @retval 0 success 2412 * @retval AVERROR(EAGAIN) output is not available in the current state - user must 2413 * try to send input 2414 * @retval AVERROR_EOF the encoder has been fully flushed, and there will be no 2415 * more output packets 2416 * @retval AVERROR(EINVAL) codec not opened, or it is a decoder 2417 * @retval "another negative error code" legitimate encoding errors 2418 */ 2419 int avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt); 2420 2421 /** 2422 * Create and return a AVHWFramesContext with values adequate for hardware 2423 * decoding. This is meant to get called from the get_format callback, and is 2424 * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx. 2425 * This API is for decoding with certain hardware acceleration modes/APIs only. 2426 * 2427 * The returned AVHWFramesContext is not initialized. The caller must do this 2428 * with av_hwframe_ctx_init(). 2429 * 2430 * Calling this function is not a requirement, but makes it simpler to avoid 2431 * codec or hardware API specific details when manually allocating frames. 2432 * 2433 * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx, 2434 * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes 2435 * it unnecessary to call this function or having to care about 2436 * AVHWFramesContext initialization at all. 2437 * 2438 * There are a number of requirements for calling this function: 2439 * 2440 * - It must be called from get_format with the same avctx parameter that was 2441 * passed to get_format. Calling it outside of get_format is not allowed, and 2442 * can trigger undefined behavior. 2443 * - The function is not always supported (see description of return values). 2444 * Even if this function returns successfully, hwaccel initialization could 2445 * fail later. (The degree to which implementations check whether the stream 2446 * is actually supported varies. Some do this check only after the user's 2447 * get_format callback returns.) 2448 * - The hw_pix_fmt must be one of the choices suggested by get_format. If the 2449 * user decides to use a AVHWFramesContext prepared with this API function, 2450 * the user must return the same hw_pix_fmt from get_format. 2451 * - The device_ref passed to this function must support the given hw_pix_fmt. 2452 * - After calling this API function, it is the user's responsibility to 2453 * initialize the AVHWFramesContext (returned by the out_frames_ref parameter), 2454 * and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done 2455 * before returning from get_format (this is implied by the normal 2456 * AVCodecContext.hw_frames_ctx API rules). 2457 * - The AVHWFramesContext parameters may change every time time get_format is 2458 * called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So 2459 * you are inherently required to go through this process again on every 2460 * get_format call. 2461 * - It is perfectly possible to call this function without actually using 2462 * the resulting AVHWFramesContext. One use-case might be trying to reuse a 2463 * previously initialized AVHWFramesContext, and calling this API function 2464 * only to test whether the required frame parameters have changed. 2465 * - Fields that use dynamically allocated values of any kind must not be set 2466 * by the user unless setting them is explicitly allowed by the documentation. 2467 * If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque, 2468 * the new free callback must call the potentially set previous free callback. 2469 * This API call may set any dynamically allocated fields, including the free 2470 * callback. 2471 * 2472 * The function will set at least the following fields on AVHWFramesContext 2473 * (potentially more, depending on hwaccel API): 2474 * 2475 * - All fields set by av_hwframe_ctx_alloc(). 2476 * - Set the format field to hw_pix_fmt. 2477 * - Set the sw_format field to the most suited and most versatile format. (An 2478 * implication is that this will prefer generic formats over opaque formats 2479 * with arbitrary restrictions, if possible.) 2480 * - Set the width/height fields to the coded frame size, rounded up to the 2481 * API-specific minimum alignment. 2482 * - Only _if_ the hwaccel requires a pre-allocated pool: set the initial_pool_size 2483 * field to the number of maximum reference surfaces possible with the codec, 2484 * plus 1 surface for the user to work (meaning the user can safely reference 2485 * at most 1 decoded surface at a time), plus additional buffering introduced 2486 * by frame threading. If the hwaccel does not require pre-allocation, the 2487 * field is left to 0, and the decoder will allocate new surfaces on demand 2488 * during decoding. 2489 * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying 2490 * hardware API. 2491 * 2492 * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but 2493 * with basic frame parameters set. 2494 * 2495 * The function is stateless, and does not change the AVCodecContext or the 2496 * device_ref AVHWDeviceContext. 2497 * 2498 * @param avctx The context which is currently calling get_format, and which 2499 * implicitly contains all state needed for filling the returned 2500 * AVHWFramesContext properly. 2501 * @param device_ref A reference to the AVHWDeviceContext describing the device 2502 * which will be used by the hardware decoder. 2503 * @param hw_pix_fmt The hwaccel format you are going to return from get_format. 2504 * @param out_frames_ref On success, set to a reference to an _uninitialized_ 2505 * AVHWFramesContext, created from the given device_ref. 2506 * Fields will be set to values required for decoding. 2507 * Not changed if an error is returned. 2508 * @return zero on success, a negative value on error. The following error codes 2509 * have special semantics: 2510 * AVERROR(ENOENT): the decoder does not support this functionality. Setup 2511 * is always manual, or it is a decoder which does not 2512 * support setting AVCodecContext.hw_frames_ctx at all, 2513 * or it is a software format. 2514 * AVERROR(EINVAL): it is known that hardware decoding is not supported for 2515 * this configuration, or the device_ref is not supported 2516 * for the hwaccel referenced by hw_pix_fmt. 2517 */ 2518 int avcodec_get_hw_frames_parameters(AVCodecContext *avctx, 2519 AVBufferRef *device_ref, 2520 enum AVPixelFormat hw_pix_fmt, 2521 AVBufferRef **out_frames_ref); 2522 2523 enum AVCodecConfig { 2524 AV_CODEC_CONFIG_PIX_FORMAT, ///< AVPixelFormat, terminated by AV_PIX_FMT_NONE 2525 AV_CODEC_CONFIG_FRAME_RATE, ///< AVRational, terminated by {0, 0} 2526 AV_CODEC_CONFIG_SAMPLE_RATE, ///< int, terminated by 0 2527 AV_CODEC_CONFIG_SAMPLE_FORMAT, ///< AVSampleFormat, terminated by AV_SAMPLE_FMT_NONE 2528 AV_CODEC_CONFIG_CHANNEL_LAYOUT, ///< AVChannelLayout, terminated by {0} 2529 AV_CODEC_CONFIG_COLOR_RANGE, ///< AVColorRange, terminated by AVCOL_RANGE_UNSPECIFIED 2530 AV_CODEC_CONFIG_COLOR_SPACE, ///< AVColorSpace, terminated by AVCOL_SPC_UNSPECIFIED 2531 }; 2532 2533 /** 2534 * Retrieve a list of all supported values for a given configuration type. 2535 * 2536 * @param avctx An optional context to use. Values such as 2537 * `strict_std_compliance` may affect the result. If NULL, 2538 * default values are used. 2539 * @param codec The codec to query, or NULL to use avctx->codec. 2540 * @param config The configuration to query. 2541 * @param flags Currently unused; should be set to zero. 2542 * @param out_configs On success, set to a list of configurations, terminated 2543 * by a config-specific terminator, or NULL if all 2544 * possible values are supported. 2545 * @param out_num_configs On success, set to the number of elements in 2546 *out_configs, excluding the terminator. Optional. 2547 */ 2548 int avcodec_get_supported_config(const AVCodecContext *avctx, 2549 const AVCodec *codec, enum AVCodecConfig config, 2550 unsigned flags, const void **out_configs, 2551 int *out_num_configs); 2552 2553 2554 2555 /** 2556 * @defgroup lavc_parsing Frame parsing 2557 * @{ 2558 */ 2559 2560 enum AVPictureStructure { 2561 AV_PICTURE_STRUCTURE_UNKNOWN, ///< unknown 2562 AV_PICTURE_STRUCTURE_TOP_FIELD, ///< coded as top field 2563 AV_PICTURE_STRUCTURE_BOTTOM_FIELD, ///< coded as bottom field 2564 AV_PICTURE_STRUCTURE_FRAME, ///< coded as frame 2565 }; 2566 2567 typedef struct AVCodecParserContext { 2568 void *priv_data; 2569 const struct AVCodecParser *parser; 2570 int64_t frame_offset; /* offset of the current frame */ 2571 int64_t cur_offset; /* current offset 2572 (incremented by each av_parser_parse()) */ 2573 int64_t next_frame_offset; /* offset of the next frame */ 2574 /* video info */ 2575 int pict_type; /* XXX: Put it back in AVCodecContext. */ 2576 /** 2577 * This field is used for proper frame duration computation in lavf. 2578 * It signals, how much longer the frame duration of the current frame 2579 * is compared to normal frame duration. 2580 * 2581 * frame_duration = (1 + repeat_pict) * time_base 2582 * 2583 * It is used by codecs like H.264 to display telecined material. 2584 */ 2585 int repeat_pict; /* XXX: Put it back in AVCodecContext. */ 2586 int64_t pts; /* pts of the current frame */ 2587 int64_t dts; /* dts of the current frame */ 2588 2589 /* private data */ 2590 int64_t last_pts; 2591 int64_t last_dts; 2592 int fetch_timestamp; 2593 2594 #define AV_PARSER_PTS_NB 4 2595 int cur_frame_start_index; 2596 int64_t cur_frame_offset[AV_PARSER_PTS_NB]; 2597 int64_t cur_frame_pts[AV_PARSER_PTS_NB]; 2598 int64_t cur_frame_dts[AV_PARSER_PTS_NB]; 2599 2600 int flags; 2601 #define PARSER_FLAG_COMPLETE_FRAMES 0x0001 2602 #define PARSER_FLAG_ONCE 0x0002 2603 /// Set if the parser has a valid file offset 2604 #define PARSER_FLAG_FETCHED_OFFSET 0x0004 2605 #define PARSER_FLAG_USE_CODEC_TS 0x1000 2606 2607 int64_t offset; ///< byte offset from starting packet start 2608 int64_t cur_frame_end[AV_PARSER_PTS_NB]; 2609 2610 /** 2611 * Set by parser to 1 for key frames and 0 for non-key frames. 2612 * It is initialized to -1, so if the parser doesn't set this flag, 2613 * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames 2614 * will be used. 2615 */ 2616 int key_frame; 2617 2618 // Timestamp generation support: 2619 /** 2620 * Synchronization point for start of timestamp generation. 2621 * 2622 * Set to >0 for sync point, 0 for no sync point and <0 for undefined 2623 * (default). 2624 * 2625 * For example, this corresponds to presence of H.264 buffering period 2626 * SEI message. 2627 */ 2628 int dts_sync_point; 2629 2630 /** 2631 * Offset of the current timestamp against last timestamp sync point in 2632 * units of AVCodecContext.time_base. 2633 * 2634 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must 2635 * contain a valid timestamp offset. 2636 * 2637 * Note that the timestamp of sync point has usually a nonzero 2638 * dts_ref_dts_delta, which refers to the previous sync point. Offset of 2639 * the next frame after timestamp sync point will be usually 1. 2640 * 2641 * For example, this corresponds to H.264 cpb_removal_delay. 2642 */ 2643 int dts_ref_dts_delta; 2644 2645 /** 2646 * Presentation delay of current frame in units of AVCodecContext.time_base. 2647 * 2648 * Set to INT_MIN when dts_sync_point unused. Otherwise, it must 2649 * contain valid non-negative timestamp delta (presentation time of a frame 2650 * must not lie in the past). 2651 * 2652 * This delay represents the difference between decoding and presentation 2653 * time of the frame. 2654 * 2655 * For example, this corresponds to H.264 dpb_output_delay. 2656 */ 2657 int pts_dts_delta; 2658 2659 /** 2660 * Position of the packet in file. 2661 * 2662 * Analogous to cur_frame_pts/dts 2663 */ 2664 int64_t cur_frame_pos[AV_PARSER_PTS_NB]; 2665 2666 /** 2667 * Byte position of currently parsed frame in stream. 2668 */ 2669 int64_t pos; 2670 2671 /** 2672 * Previous frame byte position. 2673 */ 2674 int64_t last_pos; 2675 2676 /** 2677 * Duration of the current frame. 2678 * For audio, this is in units of 1 / AVCodecContext.sample_rate. 2679 * For all other types, this is in units of AVCodecContext.time_base. 2680 */ 2681 int duration; 2682 2683 enum AVFieldOrder field_order; 2684 2685 /** 2686 * Indicate whether a picture is coded as a frame, top field or bottom field. 2687 * 2688 * For example, H.264 field_pic_flag equal to 0 corresponds to 2689 * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag 2690 * equal to 1 and bottom_field_flag equal to 0 corresponds to 2691 * AV_PICTURE_STRUCTURE_TOP_FIELD. 2692 */ 2693 enum AVPictureStructure picture_structure; 2694 2695 /** 2696 * Picture number incremented in presentation or output order. 2697 * This field may be reinitialized at the first picture of a new sequence. 2698 * 2699 * For example, this corresponds to H.264 PicOrderCnt. 2700 */ 2701 int output_picture_number; 2702 2703 /** 2704 * Dimensions of the decoded video intended for presentation. 2705 */ 2706 int width; 2707 int height; 2708 2709 /** 2710 * Dimensions of the coded video. 2711 */ 2712 int coded_width; 2713 int coded_height; 2714 2715 /** 2716 * The format of the coded data, corresponds to enum AVPixelFormat for video 2717 * and for enum AVSampleFormat for audio. 2718 * 2719 * Note that a decoder can have considerable freedom in how exactly it 2720 * decodes the data, so the format reported here might be different from the 2721 * one returned by a decoder. 2722 */ 2723 int format; 2724 } AVCodecParserContext; 2725 2726 typedef struct AVCodecParser { 2727 int codec_ids[7]; /* several codec IDs are permitted */ 2728 int priv_data_size; 2729 int (*parser_init)(AVCodecParserContext *s); 2730 /* This callback never returns an error, a negative value means that 2731 * the frame start was in a previous packet. */ 2732 int (*parser_parse)(AVCodecParserContext *s, 2733 AVCodecContext *avctx, 2734 const uint8_t **poutbuf, int *poutbuf_size, 2735 const uint8_t *buf, int buf_size); 2736 void (*parser_close)(AVCodecParserContext *s); 2737 int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size); 2738 } AVCodecParser; 2739 2740 /** 2741 * Iterate over all registered codec parsers. 2742 * 2743 * @param opaque a pointer where libavcodec will store the iteration state. Must 2744 * point to NULL to start the iteration. 2745 * 2746 * @return the next registered codec parser or NULL when the iteration is 2747 * finished 2748 */ 2749 const AVCodecParser *av_parser_iterate(void **opaque); 2750 2751 AVCodecParserContext *av_parser_init(int codec_id); 2752 2753 /** 2754 * Parse a packet. 2755 * 2756 * @param s parser context. 2757 * @param avctx codec context. 2758 * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished. 2759 * @param poutbuf_size set to size of parsed buffer or zero if not yet finished. 2760 * @param buf input buffer. 2761 * @param buf_size buffer size in bytes without the padding. I.e. the full buffer 2762 size is assumed to be buf_size + AV_INPUT_BUFFER_PADDING_SIZE. 2763 To signal EOF, this should be 0 (so that the last frame 2764 can be output). 2765 * @param pts input presentation timestamp. 2766 * @param dts input decoding timestamp. 2767 * @param pos input byte position in stream. 2768 * @return the number of bytes of the input bitstream used. 2769 * 2770 * Example: 2771 * @code 2772 * while(in_len){ 2773 * len = av_parser_parse2(myparser, AVCodecContext, &data, &size, 2774 * in_data, in_len, 2775 * pts, dts, pos); 2776 * in_data += len; 2777 * in_len -= len; 2778 * 2779 * if(size) 2780 * decode_frame(data, size); 2781 * } 2782 * @endcode 2783 */ 2784 int av_parser_parse2(AVCodecParserContext *s, 2785 AVCodecContext *avctx, 2786 uint8_t **poutbuf, int *poutbuf_size, 2787 const uint8_t *buf, int buf_size, 2788 int64_t pts, int64_t dts, 2789 int64_t pos); 2790 2791 void av_parser_close(AVCodecParserContext *s); 2792 2793 /** 2794 * @} 2795 * @} 2796 */ 2797 2798 /** 2799 * @addtogroup lavc_encoding 2800 * @{ 2801 */ 2802 2803 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, 2804 const AVSubtitle *sub); 2805 2806 2807 /** 2808 * @} 2809 */ 2810 2811 /** 2812 * @defgroup lavc_misc Utility functions 2813 * @ingroup libavc 2814 * 2815 * Miscellaneous utility functions related to both encoding and decoding 2816 * (or neither). 2817 * @{ 2818 */ 2819 2820 /** 2821 * @defgroup lavc_misc_pixfmt Pixel formats 2822 * 2823 * Functions for working with pixel formats. 2824 * @{ 2825 */ 2826 2827 /** 2828 * Return a value representing the fourCC code associated to the 2829 * pixel format pix_fmt, or 0 if no associated fourCC code can be 2830 * found. 2831 */ 2832 unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt); 2833 2834 /** 2835 * Find the best pixel format to convert to given a certain source pixel 2836 * format. When converting from one pixel format to another, information loss 2837 * may occur. For example, when converting from RGB24 to GRAY, the color 2838 * information will be lost. Similarly, other losses occur when converting from 2839 * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of 2840 * the given pixel formats should be used to suffer the least amount of loss. 2841 * The pixel formats from which it chooses one, are determined by the 2842 * pix_fmt_list parameter. 2843 * 2844 * 2845 * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from 2846 * @param[in] src_pix_fmt source pixel format 2847 * @param[in] has_alpha Whether the source pixel format alpha channel is used. 2848 * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur. 2849 * @return The best pixel format to convert to or -1 if none was found. 2850 */ 2851 enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *pix_fmt_list, 2852 enum AVPixelFormat src_pix_fmt, 2853 int has_alpha, int *loss_ptr); 2854 2855 enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat * fmt); 2856 2857 /** 2858 * @} 2859 */ 2860 2861 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode); 2862 2863 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); 2864 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); 2865 //FIXME func typedef 2866 2867 /** 2868 * Fill AVFrame audio data and linesize pointers. 2869 * 2870 * The buffer buf must be a preallocated buffer with a size big enough 2871 * to contain the specified samples amount. The filled AVFrame data 2872 * pointers will point to this buffer. 2873 * 2874 * AVFrame extended_data channel pointers are allocated if necessary for 2875 * planar audio. 2876 * 2877 * @param frame the AVFrame 2878 * frame->nb_samples must be set prior to calling the 2879 * function. This function fills in frame->data, 2880 * frame->extended_data, frame->linesize[0]. 2881 * @param nb_channels channel count 2882 * @param sample_fmt sample format 2883 * @param buf buffer to use for frame data 2884 * @param buf_size size of buffer 2885 * @param align plane size sample alignment (0 = default) 2886 * @return >=0 on success, negative error code on failure 2887 * @todo return the size in bytes required to store the samples in 2888 * case of success, at the next libavutil bump 2889 */ 2890 int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, 2891 enum AVSampleFormat sample_fmt, const uint8_t *buf, 2892 int buf_size, int align); 2893 2894 /** 2895 * Reset the internal codec state / flush internal buffers. Should be called 2896 * e.g. when seeking or when switching to a different stream. 2897 * 2898 * @note for decoders, this function just releases any references the decoder 2899 * might keep internally, but the caller's references remain valid. 2900 * 2901 * @note for encoders, this function will only do something if the encoder 2902 * declares support for AV_CODEC_CAP_ENCODER_FLUSH. When called, the encoder 2903 * will drain any remaining packets, and can then be reused for a different 2904 * stream (as opposed to sending a null frame which will leave the encoder 2905 * in a permanent EOF state after draining). This can be desirable if the 2906 * cost of tearing down and replacing the encoder instance is high. 2907 */ 2908 void avcodec_flush_buffers(AVCodecContext *avctx); 2909 2910 /** 2911 * Return audio frame duration. 2912 * 2913 * @param avctx codec context 2914 * @param frame_bytes size of the frame, or 0 if unknown 2915 * @return frame duration, in samples, if known. 0 if not able to 2916 * determine. 2917 */ 2918 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes); 2919 2920 /* memory */ 2921 2922 /** 2923 * Same behaviour av_fast_malloc but the buffer has additional 2924 * AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0. 2925 * 2926 * In addition the whole buffer will initially and after resizes 2927 * be 0-initialized so that no uninitialized data will ever appear. 2928 */ 2929 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size); 2930 2931 /** 2932 * Same behaviour av_fast_padded_malloc except that buffer will always 2933 * be 0-initialized after call. 2934 */ 2935 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); 2936 2937 /** 2938 * @return a positive value if s is open (i.e. avcodec_open2() was called on it), 2939 * 0 otherwise. 2940 */ 2941 int avcodec_is_open(AVCodecContext *s); 2942 2943 /** 2944 * @} 2945 */ 2946 2947 #endif /* AVCODEC_AVCODEC_H */