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