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