FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avcodec.h
Go to the documentation of this file.
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  * external API header
27  */
28 
29 #include <errno.h>
30 #include "libavutil/samplefmt.h"
31 #include "libavutil/avutil.h"
32 #include "libavutil/cpu.h"
34 #include "libavutil/dict.h"
35 #include "libavutil/log.h"
36 #include "libavutil/pixfmt.h"
37 #include "libavutil/rational.h"
38 
39 #include "libavcodec/version.h"
40 /**
41  * @defgroup libavc Encoding/Decoding Library
42  * @{
43  *
44  * @defgroup lavc_decoding Decoding
45  * @{
46  * @}
47  *
48  * @defgroup lavc_encoding Encoding
49  * @{
50  * @}
51  *
52  * @defgroup lavc_codec Codecs
53  * @{
54  * @defgroup lavc_codec_native Native Codecs
55  * @{
56  * @}
57  * @defgroup lavc_codec_wrappers External library wrappers
58  * @{
59  * @}
60  * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
61  * @{
62  * @}
63  * @}
64  * @defgroup lavc_internal Internal
65  * @{
66  * @}
67  * @}
68  *
69  */
70 
71 /**
72  * @defgroup lavc_core Core functions/structures.
73  * @ingroup libavc
74  *
75  * Basic definitions, functions for querying libavcodec capabilities,
76  * allocating core structures, etc.
77  * @{
78  */
79 
80 
81 /**
82  * Identify the syntax and semantics of the bitstream.
83  * The principle is roughly:
84  * Two decoders with the same ID can decode the same streams.
85  * Two encoders with the same ID can encode compatible streams.
86  * There may be slight deviations from the principle due to implementation
87  * details.
88  *
89  * If you add a codec ID to this list, add it so that
90  * 1. no value of a existing codec ID changes (that would break ABI),
91  * 2. Give it a value which when taken as ASCII is recognized uniquely by a human as this specific codec.
92  * This ensures that 2 forks can independently add AVCodecIDs without producing conflicts.
93  *
94  * After adding new codec IDs, do not forget to add an entry to the codec
95  * descriptor list and bump libavcodec minor version.
96  */
97 enum AVCodecID {
99 
100  /* video codecs */
102  AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
271  AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'),
272  AV_CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),
273  AV_CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'),
274  AV_CODEC_ID_EXR = MKBETAG('0','E','X','R'),
275  AV_CODEC_ID_AVRP = MKBETAG('A','V','R','P'),
276 
277  AV_CODEC_ID_012V = MKBETAG('0','1','2','V'),
278  AV_CODEC_ID_G2M = MKBETAG( 0 ,'G','2','M'),
279  AV_CODEC_ID_AVUI = MKBETAG('A','V','U','I'),
280  AV_CODEC_ID_AYUV = MKBETAG('A','Y','U','V'),
281  AV_CODEC_ID_TARGA_Y216 = MKBETAG('T','2','1','6'),
282  AV_CODEC_ID_V308 = MKBETAG('V','3','0','8'),
283  AV_CODEC_ID_V408 = MKBETAG('V','4','0','8'),
284  AV_CODEC_ID_YUV4 = MKBETAG('Y','U','V','4'),
285  AV_CODEC_ID_SANM = MKBETAG('S','A','N','M'),
286  AV_CODEC_ID_PAF_VIDEO = MKBETAG('P','A','F','V'),
287  AV_CODEC_ID_AVRN = MKBETAG('A','V','R','n'),
288  AV_CODEC_ID_CPIA = MKBETAG('C','P','I','A'),
289  AV_CODEC_ID_XFACE = MKBETAG('X','F','A','C'),
290  AV_CODEC_ID_SGIRLE = MKBETAG('S','G','I','R'),
291  AV_CODEC_ID_MVC1 = MKBETAG('M','V','C','1'),
292  AV_CODEC_ID_MVC2 = MKBETAG('M','V','C','2'),
293 
294  /* various PCM "codecs" */
295  AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
327 
328  /* various ADPCM codecs */
359  AV_CODEC_ID_VIMA = MKBETAG('V','I','M','A'),
360  AV_CODEC_ID_ADPCM_AFC = MKBETAG('A','F','C',' '),
361  AV_CODEC_ID_ADPCM_IMA_OKI = MKBETAG('O','K','I',' '),
362 
363  /* AMR */
366 
367  /* RealAudio codecs*/
370 
371  /* various DPCM codecs */
376 
377  /* audio codecs */
378  AV_CODEC_ID_MP2 = 0x15000,
379  AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
396  AV_CODEC_ID_GSM, ///< as in Berlin toast format
408  AV_CODEC_ID_GSM_MS, /* as found in WAV */
442  AV_CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'),
443 #if LIBAVCODEC_VERSION_MAJOR <= 54
444  AV_CODEC_ID_8SVX_RAW = MKBETAG('8','S','V','X'),
445 #endif
446  AV_CODEC_ID_SONIC = MKBETAG('S','O','N','C'),
447  AV_CODEC_ID_SONIC_LS = MKBETAG('S','O','N','L'),
448  AV_CODEC_ID_PAF_AUDIO = MKBETAG('P','A','F','A'),
449  AV_CODEC_ID_OPUS = MKBETAG('O','P','U','S'),
450  AV_CODEC_ID_TAK = MKBETAG('t','B','a','K'),
451  AV_CODEC_ID_EVRC = MKBETAG('s','e','v','c'),
452  AV_CODEC_ID_SMV = MKBETAG('s','s','m','v'),
453 
454  /* subtitle codecs */
455  AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
458  AV_CODEC_ID_TEXT, ///< raw UTF-8 text
465  AV_CODEC_ID_MICRODVD = MKBETAG('m','D','V','D'),
466  AV_CODEC_ID_EIA_608 = MKBETAG('c','6','0','8'),
467  AV_CODEC_ID_JACOSUB = MKBETAG('J','S','U','B'),
468  AV_CODEC_ID_SAMI = MKBETAG('S','A','M','I'),
469  AV_CODEC_ID_REALTEXT = MKBETAG('R','T','X','T'),
470  AV_CODEC_ID_SUBVIEWER1 = MKBETAG('S','b','V','1'),
471  AV_CODEC_ID_SUBVIEWER = MKBETAG('S','u','b','V'),
472  AV_CODEC_ID_SUBRIP = MKBETAG('S','R','i','p'),
473  AV_CODEC_ID_WEBVTT = MKBETAG('W','V','T','T'),
474  AV_CODEC_ID_MPL2 = MKBETAG('M','P','L','2'),
475  AV_CODEC_ID_VPLAYER = MKBETAG('V','P','l','r'),
476  AV_CODEC_ID_PJS = MKBETAG('P','h','J','S'),
477 
478  /* other specific kind of codecs (generally used for attachments) */
479  AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
480  AV_CODEC_ID_TTF = 0x18000,
481  AV_CODEC_ID_BINTEXT = MKBETAG('B','T','X','T'),
482  AV_CODEC_ID_XBIN = MKBETAG('X','B','I','N'),
483  AV_CODEC_ID_IDF = MKBETAG( 0 ,'I','D','F'),
484  AV_CODEC_ID_OTF = MKBETAG( 0 ,'O','T','F'),
485  AV_CODEC_ID_SMPTE_KLV = MKBETAG('K','L','V','A'),
486 
487  AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
488 
489  AV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
490  * stream (only used by libavformat) */
491  AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
492  * stream (only used by libavformat) */
493  AV_CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information.
494 
495 #if FF_API_CODEC_ID
496 #include "old_codec_ids.h"
497 #endif
498 };
499 
500 #if FF_API_CODEC_ID
501 #define CodecID AVCodecID
502 #endif
503 
504 /**
505  * This struct describes the properties of a single codec described by an
506  * AVCodecID.
507  * @see avcodec_get_descriptor()
508  */
509 typedef struct AVCodecDescriptor {
510  enum AVCodecID id;
512  /**
513  * Name of the codec described by this descriptor. It is non-empty and
514  * unique for each codec descriptor. It should contain alphanumeric
515  * characters and '_' only.
516  */
517  const char *name;
518  /**
519  * A more descriptive name for this codec. May be NULL.
520  */
521  const char *long_name;
522  /**
523  * Codec properties, a combination of AV_CODEC_PROP_* flags.
524  */
525  int props;
527 
528 /**
529  * Codec uses only intra compression.
530  * Video codecs only.
531  */
532 #define AV_CODEC_PROP_INTRA_ONLY (1 << 0)
533 /**
534  * Codec supports lossy compression. Audio and video codecs only.
535  * @note a codec may support both lossy and lossless
536  * compression modes
537  */
538 #define AV_CODEC_PROP_LOSSY (1 << 1)
539 /**
540  * Codec supports lossless compression. Audio and video codecs only.
541  */
542 #define AV_CODEC_PROP_LOSSLESS (1 << 2)
543 /**
544  * Subtitle codec is bitmap based
545  */
546 #define AV_CODEC_PROP_BITMAP_SUB (1 << 16)
547 
548 #if FF_API_OLD_DECODE_AUDIO
549 /* in bytes */
550 #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
551 #endif
552 
553 /**
554  * @ingroup lavc_decoding
555  * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
556  * This is mainly needed because some optimized bitstream readers read
557  * 32 or 64 bit at once and could read over the end.<br>
558  * Note: If the first 23 bits of the additional bytes are not 0, then damaged
559  * MPEG bitstreams could cause overread and segfault.
560  */
561 #define FF_INPUT_BUFFER_PADDING_SIZE 16
562 
563 /**
564  * @ingroup lavc_encoding
565  * minimum encoding buffer size
566  * Used to avoid some checks during header writing.
567  */
568 #define FF_MIN_BUFFER_SIZE 16384
569 
570 
571 /**
572  * @ingroup lavc_encoding
573  * motion estimation type.
574  */
576  ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed
580  ME_EPZS, ///< enhanced predictive zonal search
581  ME_X1, ///< reserved for experiments
582  ME_HEX, ///< hexagon based search
583  ME_UMH, ///< uneven multi-hexagon search
584  ME_ITER, ///< iterative search
585  ME_TESA, ///< transformed exhaustive search algorithm
586 };
587 
588 /**
589  * @ingroup lavc_decoding
590  */
592  /* We leave some space between them for extensions (drop some
593  * keyframes for intra-only or drop just some bidir frames). */
594  AVDISCARD_NONE =-16, ///< discard nothing
595  AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
596  AVDISCARD_NONREF = 8, ///< discard all non reference
597  AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
598  AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
599  AVDISCARD_ALL = 48, ///< discard all
600 };
601 
603  AVCOL_PRI_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
606  AVCOL_PRI_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
607  AVCOL_PRI_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
608  AVCOL_PRI_SMPTE240M = 7, ///< functionally identical to above
610  AVCOL_PRI_NB , ///< Not part of ABI
611 };
612 
614  AVCOL_TRC_BT709 = 1, ///< also ITU-R BT1361
616  AVCOL_TRC_GAMMA22 = 4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
617  AVCOL_TRC_GAMMA28 = 5, ///< also ITU-R BT470BG
619  AVCOL_TRC_NB , ///< Not part of ABI
620 };
621 
624  AVCOL_SPC_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
627  AVCOL_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
628  AVCOL_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
630  AVCOL_SPC_YCOCG = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
631  AVCOL_SPC_NB , ///< Not part of ABI
632 };
633 #define AVCOL_SPC_YCGCO AVCOL_SPC_YCOCG
634 
637  AVCOL_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
638  AVCOL_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges
639  AVCOL_RANGE_NB , ///< Not part of ABI
640 };
641 
642 /**
643  * X X 3 4 X X are luma samples,
644  * 1 2 1-6 are possible chroma positions
645  * X X 5 6 X 0 is undefined/unknown position
646  */
649  AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
650  AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
651  AVCHROMA_LOC_TOPLEFT = 3, ///< DV
655  AVCHROMA_LOC_NB , ///< Not part of ABI
656 };
657 
668  AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI
669 };
670 
671 /**
672  * @ingroup lavc_encoding
673  */
674 typedef struct RcOverride{
677  int qscale; // If this is 0 then quality_factor will be used instead.
679 } RcOverride;
680 
681 #define FF_MAX_B_FRAMES 16
682 
683 /* encoding support
684  These flags can be passed in AVCodecContext.flags before initialization.
685  Note: Not everything is supported yet.
686 */
687 
688 #define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale.
689 #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263.
690 #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC.
691 #define CODEC_FLAG_GMC 0x0020 ///< Use GMC.
692 #define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>.
693 /**
694  * The parent program guarantees that the input for B-frames containing
695  * streams is not written to for at least s->max_b_frames+1 frames, if
696  * this is not set the input will be copied.
697  */
698 #define CODEC_FLAG_INPUT_PRESERVED 0x0100
699 #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode.
700 #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode.
701 #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale.
702 #define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges.
703 #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding.
704 #define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random
705  location instead of only at frame boundaries. */
706 #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization.
707 #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT.
708 #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay.
709 #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe.
710 #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
711 /* Fx : Flag for h263+ extra options */
712 #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
713 #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
714 #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
715 #define CODEC_FLAG_CLOSED_GOP 0x80000000
716 #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
717 #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
718 #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
719 #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
720 #define CODEC_FLAG2_IGNORE_CROP 0x00010000 ///< Discard cropping information from SPS.
721 
722 #if FF_API_MPV_GLOBAL_OPTS
723 #define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
724 #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
725 #define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
726 #define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
727 #endif
728 #define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
729 #define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe
730 
731 /* Unsupported options :
732  * Syntax Arithmetic coding (SAC)
733  * Reference Picture Selection
734  * Independent Segment Decoding */
735 /* /Fx */
736 /* codec capabilities */
738 #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback.
739 /**
740  * Codec uses get_buffer() for allocating buffers and supports custom allocators.
741  * If not set, it might not use get_buffer() at all or use operations that
742  * assume the buffer was allocated by avcodec_default_get_buffer.
743  */
744 #define CODEC_CAP_DR1 0x0002
745 #define CODEC_CAP_TRUNCATED 0x0008
746 /* Codec can export data for HW decoding (XvMC). */
747 #define CODEC_CAP_HWACCEL 0x0010
748 /**
749  * Encoder or decoder requires flushing with NULL input at the end in order to
750  * give the complete and correct output.
751  *
752  * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
753  * with NULL data. The user can still send NULL data to the public encode
754  * or decode function, but libavcodec will not pass it along to the codec
755  * unless this flag is set.
756  *
757  * Decoders:
758  * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
759  * avpkt->size=0 at the end to get the delayed data until the decoder no longer
760  * returns frames.
761  *
762  * Encoders:
763  * The encoder needs to be fed with NULL data at the end of encoding until the
764  * encoder no longer returns data.
765  *
766  * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
767  * flag also means that the encoder must set the pts and duration for
768  * each output packet. If this flag is not set, the pts and duration will
769  * be determined by libavcodec from the input frame.
770  */
771 #define CODEC_CAP_DELAY 0x0020
772 /**
773  * Codec can be fed a final frame with a smaller size.
774  * This can be used to prevent truncation of the last audio samples.
775  */
776 #define CODEC_CAP_SMALL_LAST_FRAME 0x0040
777 /**
778  * Codec can export data for HW decoding (VDPAU).
779  */
780 #define CODEC_CAP_HWACCEL_VDPAU 0x0080
781 /**
782  * Codec can output multiple frames per AVPacket
783  * Normally demuxers return one frame at a time, demuxers which do not do
784  * are connected to a parser to split what they return into proper frames.
785  * This flag is reserved to the very rare category of codecs which have a
786  * bitstream that cannot be split into frames without timeconsuming
787  * operations like full decoding. Demuxers carring such bitstreams thus
788  * may return multiple frames in a packet. This has many disadvantages like
789  * prohibiting stream copy in many cases thus it should only be considered
790  * as a last resort.
791  */
792 #define CODEC_CAP_SUBFRAMES 0x0100
793 /**
794  * Codec is experimental and is thus avoided in favor of non experimental
795  * encoders
796  */
797 #define CODEC_CAP_EXPERIMENTAL 0x0200
798 /**
799  * Codec should fill in channel configuration and samplerate instead of container
800  */
801 #define CODEC_CAP_CHANNEL_CONF 0x0400
802 
803 /**
804  * Codec is able to deal with negative linesizes
805  */
806 #define CODEC_CAP_NEG_LINESIZES 0x0800
807 
808 /**
809  * Codec supports frame-level multithreading.
810  */
811 #define CODEC_CAP_FRAME_THREADS 0x1000
812 /**
813  * Codec supports slice-based (or partition-based) multithreading.
814  */
815 #define CODEC_CAP_SLICE_THREADS 0x2000
816 /**
817  * Codec supports changed parameters at any point.
818  */
819 #define CODEC_CAP_PARAM_CHANGE 0x4000
820 /**
821  * Codec supports avctx->thread_count == 0 (auto).
822  */
823 #define CODEC_CAP_AUTO_THREADS 0x8000
824 /**
825  * Audio encoder supports receiving a different number of samples in each call.
826  */
827 #define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000
828 /**
829  * Codec is intra only.
830  */
831 #define CODEC_CAP_INTRA_ONLY 0x40000000
832 /**
833  * Codec is lossless.
834  */
835 #define CODEC_CAP_LOSSLESS 0x80000000
836 
837 //The following defines may change, don't expect compatibility if you use them.
838 #define MB_TYPE_INTRA4x4 0x0001
839 #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific
840 #define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific
841 #define MB_TYPE_16x16 0x0008
842 #define MB_TYPE_16x8 0x0010
843 #define MB_TYPE_8x16 0x0020
844 #define MB_TYPE_8x8 0x0040
845 #define MB_TYPE_INTERLACED 0x0080
846 #define MB_TYPE_DIRECT2 0x0100 //FIXME
847 #define MB_TYPE_ACPRED 0x0200
848 #define MB_TYPE_GMC 0x0400
849 #define MB_TYPE_SKIP 0x0800
850 #define MB_TYPE_P0L0 0x1000
851 #define MB_TYPE_P1L0 0x2000
852 #define MB_TYPE_P0L1 0x4000
853 #define MB_TYPE_P1L1 0x8000
854 #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
855 #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
856 #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
857 #define MB_TYPE_QUANT 0x00010000
858 #define MB_TYPE_CBP 0x00020000
859 //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
860 
861 /**
862  * Pan Scan area.
863  * This specifies the area which should be displayed.
864  * Note there may be multiple such areas for one frame.
865  */
866 typedef struct AVPanScan{
867  /**
868  * id
869  * - encoding: Set by user.
870  * - decoding: Set by libavcodec.
871  */
872  int id;
873 
874  /**
875  * width and height in 1/16 pel
876  * - encoding: Set by user.
877  * - decoding: Set by libavcodec.
878  */
879  int width;
880  int height;
881 
882  /**
883  * position of the top left corner in 1/16 pel for up to 3 fields/frames
884  * - encoding: Set by user.
885  * - decoding: Set by libavcodec.
886  */
887  int16_t position[3][2];
888 }AVPanScan;
890 #define FF_QSCALE_TYPE_MPEG1 0
891 #define FF_QSCALE_TYPE_MPEG2 1
892 #define FF_QSCALE_TYPE_H264 2
893 #define FF_QSCALE_TYPE_VP56 3
895 #define FF_BUFFER_TYPE_INTERNAL 1
896 #define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user)
897 #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared.
898 #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything.
900 #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore).
901 #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer.
902 #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content.
903 #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update).
904 
905 /**
906  * @defgroup lavc_packet AVPacket
907  *
908  * Types and functions for working with AVPacket.
909  * @{
910  */
914 
915  /**
916  * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
917  * @code
918  * u32le param_flags
919  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT)
920  * s32le channel_count
921  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT)
922  * u64le channel_layout
923  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE)
924  * s32le sample_rate
925  * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS)
926  * s32le width
927  * s32le height
928  * @endcode
929  */
931 
932  /**
933  * An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of
934  * structures with info about macroblocks relevant to splitting the
935  * packet into smaller packets on macroblock edges (e.g. as for RFC 2190).
936  * That is, it does not necessarily contain info about all macroblocks,
937  * as long as the distance between macroblocks in the info is smaller
938  * than the target payload size.
939  * Each MB info structure is 12 bytes, and is laid out as follows:
940  * @code
941  * u32le bit offset from the start of the packet
942  * u8 current quantizer at the start of the macroblock
943  * u8 GOB number
944  * u16le macroblock address within the GOB
945  * u8 horizontal MV predictor
946  * u8 vertical MV predictor
947  * u8 horizontal MV predictor for block number 3
948  * u8 vertical MV predictor for block number 3
949  * @endcode
950  */
952 
953  /**
954  * Recommmends skipping the specified number of samples
955  * @code
956  * u32le number of samples to skip from start of this packet
957  * u32le number of samples to skip from end of this packet
958  * u8 reason for start skip
959  * u8 reason for end skip (0=padding silence, 1=convergence)
960  * @endcode
961  */
963 
964  /**
965  * An AV_PKT_DATA_JP_DUALMONO side data packet indicates that
966  * the packet may contain "dual mono" audio specific to Japanese DTV
967  * and if it is true, recommends only the selected channel to be used.
968  * @code
969  * u8 selected channels (0=mail/left, 1=sub/right, 2=both)
970  * @endcode
971  */
973 
974  /**
975  * A list of zero terminated key/value strings. There is no end marker for
976  * the list, so it is required to rely on the side data size to stop.
977  */
979 
980  /**
981  * Subtitle event position
982  * @code
983  * u32le x1
984  * u32le y1
985  * u32le x2
986  * u32le y2
987  * @endcode
988  */
990 
991  /**
992  * Data found in BlockAdditional element of matroska container. There is
993  * no end marker for the data, so it is required to rely on the side data
994  * size to recognize the end. 8 byte id (as found in BlockAddId) followed
995  * by data.
996  */
998 };
999 
1000 /**
1001  * This structure stores compressed data. It is typically exported by demuxers
1002  * and then passed as input to decoders, or received as output from encoders and
1003  * then passed to muxers.
1004  *
1005  * For video, it should typically contain one compressed frame. For audio it may
1006  * contain several compressed frames.
1007  *
1008  * AVPacket is one of the few structs in FFmpeg, whose size is a part of public
1009  * ABI. Thus it may be allocated on stack and no new fields can be added to it
1010  * without libavcodec and libavformat major bump.
1011  *
1012  * The semantics of data ownership depends on the destruct field.
1013  * If it is set, the packet data is dynamically allocated and is valid
1014  * indefinitely until av_free_packet() is called (which in turn calls the
1015  * destruct callback to free the data). If destruct is not set, the packet data
1016  * is typically backed by some static buffer somewhere and is only valid for a
1017  * limited time (e.g. until the next read call when demuxing).
1018  *
1019  * The side data is always allocated with av_malloc() and is freed in
1020  * av_free_packet().
1021  */
1022 typedef struct AVPacket {
1023  /**
1024  * Presentation timestamp in AVStream->time_base units; the time at which
1025  * the decompressed packet will be presented to the user.
1026  * Can be AV_NOPTS_VALUE if it is not stored in the file.
1027  * pts MUST be larger or equal to dts as presentation cannot happen before
1028  * decompression, unless one wants to view hex dumps. Some formats misuse
1029  * the terms dts and pts/cts to mean something different. Such timestamps
1030  * must be converted to true pts/dts before they are stored in AVPacket.
1031  */
1032  int64_t pts;
1033  /**
1034  * Decompression timestamp in AVStream->time_base units; the time at which
1035  * the packet is decompressed.
1036  * Can be AV_NOPTS_VALUE if it is not stored in the file.
1037  */
1038  int64_t dts;
1040  int size;
1041  int stream_index;
1042  /**
1043  * A combination of AV_PKT_FLAG values
1044  */
1045  int flags;
1046  /**
1047  * Additional packet data that can be provided by the container.
1048  * Packet can contain several types of side information.
1049  */
1050  struct {
1051  uint8_t *data;
1052  int size;
1055  int side_data_elems;
1056 
1057  /**
1058  * Duration of this packet in AVStream->time_base units, 0 if unknown.
1059  * Equals next_pts - this_pts in presentation order.
1060  */
1062  void (*destruct)(struct AVPacket *);
1063  void *priv;
1064  int64_t pos; ///< byte position in stream, -1 if unknown
1065 
1066  /**
1067  * Time difference in AVStream->time_base units from the pts of this
1068  * packet to the point at which the output from the decoder has converged
1069  * independent from the availability of previous frames. That is, the
1070  * frames are virtually identical no matter if decoding started from
1071  * the very first frame or from this keyframe.
1072  * Is AV_NOPTS_VALUE if unknown.
1073  * This field is not the display duration of the current packet.
1074  * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
1075  * set.
1076  *
1077  * The purpose of this field is to allow seeking in streams that have no
1078  * keyframes in the conventional sense. It corresponds to the
1079  * recovery point SEI in H.264 and match_time_delta in NUT. It is also
1080  * essential for some types of subtitle streams to ensure that all
1081  * subtitles are correctly displayed after seeking.
1082  */
1083  int64_t convergence_duration;
1085 #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
1086 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
1093 };
1094 /**
1095  * @}
1096  */
1097 
1098 /**
1099  * This structure describes decoded (raw) audio or video data.
1100  *
1101  * AVFrame must be allocated using avcodec_alloc_frame() and freed with
1102  * avcodec_free_frame(). Note that this allocates only the AVFrame itself. The
1103  * buffers for the data must be managed through other means.
1104  *
1105  * AVFrame is typically allocated once and then reused multiple times to hold
1106  * different data (e.g. a single AVFrame to hold frames received from a
1107  * decoder). In such a case, avcodec_get_frame_defaults() should be used to
1108  * reset the frame to its original clean state before it is reused again.
1109  *
1110  * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
1111  * to the end with a minor bump.
1112  * Similarly fields that are marked as to be only accessed by
1113  * av_opt_ptr() can be reordered. This allows 2 forks to add fields
1114  * without breaking compatibility with each other.
1115  */
1116 typedef struct AVFrame {
1117 #define AV_NUM_DATA_POINTERS 8
1118  /**
1119  * pointer to the picture/channel planes.
1120  * This might be different from the first allocated byte
1121  * - encoding: Set by user
1122  * - decoding: set by AVCodecContext.get_buffer()
1123  */
1125 
1126  /**
1127  * Size, in bytes, of the data for each picture/channel plane.
1128  *
1129  * For audio, only linesize[0] may be set. For planar audio, each channel
1130  * plane must be the same size.
1131  *
1132  * - encoding: Set by user
1133  * - decoding: set by AVCodecContext.get_buffer()
1134  */
1136 
1137  /**
1138  * pointers to the data planes/channels.
1139  *
1140  * For video, this should simply point to data[].
1141  *
1142  * For planar audio, each channel has a separate data pointer, and
1143  * linesize[0] contains the size of each channel buffer.
1144  * For packed audio, there is just one data pointer, and linesize[0]
1145  * contains the total size of the buffer for all channels.
1146  *
1147  * Note: Both data and extended_data will always be set by get_buffer(),
1148  * but for planar audio with more channels that can fit in data,
1149  * extended_data must be used by the decoder in order to access all
1150  * channels.
1151  *
1152  * encoding: set by user
1153  * decoding: set by AVCodecContext.get_buffer()
1154  */
1156 
1157  /**
1158  * width and height of the video frame
1159  * - encoding: unused
1160  * - decoding: Read by user.
1161  */
1162  int width, height;
1163 
1164  /**
1165  * number of audio samples (per channel) described by this frame
1166  * - encoding: Set by user
1167  * - decoding: Set by libavcodec
1168  */
1169  int nb_samples;
1170 
1171  /**
1172  * format of the frame, -1 if unknown or unset
1173  * Values correspond to enum AVPixelFormat for video frames,
1174  * enum AVSampleFormat for audio)
1175  * - encoding: unused
1176  * - decoding: Read by user.
1177  */
1178  int format;
1179 
1180  /**
1181  * 1 -> keyframe, 0-> not
1182  * - encoding: Set by libavcodec.
1183  * - decoding: Set by libavcodec.
1184  */
1185  int key_frame;
1186 
1187  /**
1188  * Picture type of the frame, see ?_TYPE below.
1189  * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
1190  * - decoding: Set by libavcodec.
1191  */
1192  enum AVPictureType pict_type;
1193 
1194  /**
1195  * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.
1196  * This isn't used by libavcodec unless the default get/release_buffer() is used.
1197  * - encoding:
1198  * - decoding:
1199  */
1201 
1202  /**
1203  * sample aspect ratio for the video frame, 0/1 if unknown/unspecified
1204  * - encoding: unused
1205  * - decoding: Read by user.
1206  */
1208 
1209  /**
1210  * presentation timestamp in time_base units (time when frame should be shown to user)
1211  * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.
1212  * - encoding: MUST be set by user.
1213  * - decoding: Set by libavcodec.
1214  */
1215  int64_t pts;
1216 
1217  /**
1218  * pts copied from the AVPacket that was decoded to produce this frame
1219  * - encoding: unused
1220  * - decoding: Read by user.
1221  */
1222  int64_t pkt_pts;
1223 
1224  /**
1225  * dts copied from the AVPacket that triggered returning this frame
1226  * - encoding: unused
1227  * - decoding: Read by user.
1228  */
1229  int64_t pkt_dts;
1230 
1231  /**
1232  * picture number in bitstream order
1233  * - encoding: set by
1234  * - decoding: Set by libavcodec.
1235  */
1237  /**
1238  * picture number in display order
1239  * - encoding: set by
1240  * - decoding: Set by libavcodec.
1241  */
1243 
1244  /**
1245  * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
1246  * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
1247  * - decoding: Set by libavcodec.
1248  */
1249  int quality;
1250 
1251  /**
1252  * is this picture used as reference
1253  * The values for this are the same as the MpegEncContext.picture_structure
1254  * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
1255  * Set to 4 for delayed, non-reference frames.
1256  * - encoding: unused
1257  * - decoding: Set by libavcodec. (before get_buffer() call)).
1258  */
1259  int reference;
1260 
1261  /**
1262  * QP table
1263  * - encoding: unused
1264  * - decoding: Set by libavcodec.
1265  */
1266  int8_t *qscale_table;
1267  /**
1268  * QP store stride
1269  * - encoding: unused
1270  * - decoding: Set by libavcodec.
1271  */
1272  int qstride;
1273 
1274  /**
1275  *
1276  */
1277  int qscale_type;
1278 
1279  /**
1280  * mbskip_table[mb]>=1 if MB didn't change
1281  * stride= mb_width = (width+15)>>4
1282  * - encoding: unused
1283  * - decoding: Set by libavcodec.
1284  */
1286 
1287  /**
1288  * motion vector table
1289  * @code
1290  * example:
1291  * int mv_sample_log2= 4 - motion_subsample_log2;
1292  * int mb_width= (width+15)>>4;
1293  * int mv_stride= (mb_width << mv_sample_log2) + 1;
1294  * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
1295  * @endcode
1296  * - encoding: Set by user.
1297  * - decoding: Set by libavcodec.
1298  */
1299  int16_t (*motion_val[2])[2];
1300 
1301  /**
1302  * macroblock type table
1303  * mb_type_base + mb_width + 2
1304  * - encoding: Set by user.
1305  * - decoding: Set by libavcodec.
1306  */
1307  uint32_t *mb_type;
1308 
1309  /**
1310  * DCT coefficients
1311  * - encoding: unused
1312  * - decoding: Set by libavcodec.
1313  */
1314  short *dct_coeff;
1315 
1316  /**
1317  * motion reference frame index
1318  * the order in which these are stored can depend on the codec.
1319  * - encoding: Set by user.
1320  * - decoding: Set by libavcodec.
1321  */
1322  int8_t *ref_index[2];
1323 
1324  /**
1325  * for some private data of the user
1326  * - encoding: unused
1327  * - decoding: Set by user.
1328  */
1329  void *opaque;
1330 
1331  /**
1332  * error
1333  * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.
1334  * - decoding: unused
1335  */
1336  uint64_t error[AV_NUM_DATA_POINTERS];
1337 
1338  /**
1339  * type of the buffer (to keep track of who has to deallocate data[*])
1340  * - encoding: Set by the one who allocates it.
1341  * - decoding: Set by the one who allocates it.
1342  * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.
1343  */
1344  int type;
1345 
1346  /**
1347  * When decoding, this signals how much the picture must be delayed.
1348  * extra_delay = repeat_pict / (2*fps)
1349  * - encoding: unused
1350  * - decoding: Set by libavcodec.
1351  */
1352  int repeat_pict;
1353 
1354  /**
1355  * The content of the picture is interlaced.
1356  * - encoding: Set by user.
1357  * - decoding: Set by libavcodec. (default 0)
1358  */
1359  int interlaced_frame;
1360 
1361  /**
1362  * If the content is interlaced, is top field displayed first.
1363  * - encoding: Set by user.
1364  * - decoding: Set by libavcodec.
1365  */
1366  int top_field_first;
1367 
1368  /**
1369  * Tell user application that palette has changed from previous frame.
1370  * - encoding: ??? (no palette-enabled encoder yet)
1371  * - decoding: Set by libavcodec. (default 0).
1372  */
1373  int palette_has_changed;
1374 
1375  /**
1376  * codec suggestion on buffer type if != 0
1377  * - encoding: unused
1378  * - decoding: Set by libavcodec. (before get_buffer() call)).
1379  */
1380  int buffer_hints;
1381 
1382  /**
1383  * Pan scan.
1384  * - encoding: Set by user.
1385  * - decoding: Set by libavcodec.
1386  */
1388 
1389  /**
1390  * reordered opaque 64bit (generally an integer or a double precision float
1391  * PTS but can be anything).
1392  * The user sets AVCodecContext.reordered_opaque to represent the input at
1393  * that time,
1394  * the decoder reorders values as needed and sets AVFrame.reordered_opaque
1395  * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
1396  * @deprecated in favor of pkt_pts
1397  * - encoding: unused
1398  * - decoding: Read by user.
1399  */
1400  int64_t reordered_opaque;
1401 
1402  /**
1403  * hardware accelerator private data (FFmpeg-allocated)
1404  * - encoding: unused
1405  * - decoding: Set by libavcodec
1406  */
1408 
1409  /**
1410  * the AVCodecContext which ff_thread_get_buffer() was last called on
1411  * - encoding: Set by libavcodec.
1412  * - decoding: Set by libavcodec.
1413  */
1414  struct AVCodecContext *owner;
1415 
1416  /**
1417  * used by multithreading to store frame-specific info
1418  * - encoding: Set by libavcodec.
1419  * - decoding: Set by libavcodec.
1420  */
1421  void *thread_opaque;
1422 
1423  /**
1424  * log2 of the size of the block which a single vector in motion_val represents:
1425  * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
1426  * - encoding: unused
1427  * - decoding: Set by libavcodec.
1428  */
1430 
1431  /**
1432  * Sample rate of the audio data.
1433  *
1434  * - encoding: unused
1435  * - decoding: read by user
1436  */
1437  int sample_rate;
1438 
1439  /**
1440  * Channel layout of the audio data.
1441  *
1442  * - encoding: unused
1443  * - decoding: read by user.
1444  */
1445  uint64_t channel_layout;
1446 
1447  /**
1448  * frame timestamp estimated using various heuristics, in stream time base
1449  * Code outside libavcodec should access this field using:
1450  * av_frame_get_best_effort_timestamp(frame)
1451  * - encoding: unused
1452  * - decoding: set by libavcodec, read by user.
1453  */
1454  int64_t best_effort_timestamp;
1455 
1456  /**
1457  * reordered pos from the last AVPacket that has been input into the decoder
1458  * Code outside libavcodec should access this field using:
1459  * av_frame_get_pkt_pos(frame)
1460  * - encoding: unused
1461  * - decoding: Read by user.
1462  */
1463  int64_t pkt_pos;
1464 
1465  /**
1466  * duration of the corresponding packet, expressed in
1467  * AVStream->time_base units, 0 if unknown.
1468  * Code outside libavcodec should access this field using:
1469  * av_frame_get_pkt_duration(frame)
1470  * - encoding: unused
1471  * - decoding: Read by user.
1472  */
1473  int64_t pkt_duration;
1474 
1475  /**
1476  * metadata.
1477  * Code outside libavcodec should access this field using:
1478  * av_frame_get_metadata(frame)
1479  * - encoding: Set by user.
1480  * - decoding: Set by libavcodec.
1481  */
1483 
1484  /**
1485  * decode error flags of the frame, set to a combination of
1486  * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
1487  * were errors during the decoding.
1488  * Code outside libavcodec should access this field using:
1489  * av_frame_get_decode_error_flags(frame)
1490  * - encoding: unused
1491  * - decoding: set by libavcodec, read by user.
1492  */
1494 #define FF_DECODE_ERROR_INVALID_BITSTREAM 1
1495 #define FF_DECODE_ERROR_MISSING_REFERENCE 2
1496 
1497  /**
1498  * number of audio channels, only used for audio.
1499  * Code outside libavcodec should access this field using:
1500  * av_frame_get_channels(frame)
1501  * - encoding: unused
1502  * - decoding: Read by user.
1503  */
1504  int channels;
1505 
1506  /**
1507  * size of the corresponding packet containing the compressed
1508  * frame. It must be accessed using av_frame_get_pkt_size() and
1509  * av_frame_set_pkt_size().
1510  * It is set to a negative value if unknown.
1511  * - encoding: unused
1512  * - decoding: set by libavcodec, read by user.
1513  */
1514  int pkt_size;
1515 } AVFrame;
1516 
1517 /**
1518  * Accessors for some AVFrame fields.
1519  * The position of these field in the structure is not part of the ABI,
1520  * they should not be accessed directly outside libavcodec.
1521  */
1524 int64_t av_frame_get_pkt_duration (const AVFrame *frame);
1525 void av_frame_set_pkt_duration (AVFrame *frame, int64_t val);
1526 int64_t av_frame_get_pkt_pos (const AVFrame *frame);
1527 void av_frame_set_pkt_pos (AVFrame *frame, int64_t val);
1528 int64_t av_frame_get_channel_layout (const AVFrame *frame);
1529 void av_frame_set_channel_layout (AVFrame *frame, int64_t val);
1530 int av_frame_get_channels (const AVFrame *frame);
1531 void av_frame_set_channels (AVFrame *frame, int val);
1533 void av_frame_set_sample_rate (AVFrame *frame, int val);
1538 int av_frame_get_pkt_size(const AVFrame *frame);
1539 void av_frame_set_pkt_size(AVFrame *frame, int val);
1540 
1541 struct AVCodecInternal;
1546  AV_FIELD_TT, //< Top coded_first, top displayed first
1547  AV_FIELD_BB, //< Bottom coded first, bottom displayed first
1548  AV_FIELD_TB, //< Top coded first, bottom displayed first
1549  AV_FIELD_BT, //< Bottom coded first, top displayed first
1550 };
1551 
1552 /**
1553  * main external API structure.
1554  * New fields can be added to the end with minor version bumps.
1555  * Removal, reordering and changes to existing fields require a major
1556  * version bump.
1557  * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
1558  * applications.
1559  * sizeof(AVCodecContext) must not be used outside libav*.
1560  */
1561 typedef struct AVCodecContext {
1562  /**
1563  * information on struct for av_log
1564  * - set by avcodec_alloc_context3
1565  */
1567  int log_level_offset;
1569  enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
1570  const struct AVCodec *codec;
1571  char codec_name[32];
1572  enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
1573 
1574  /**
1575  * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1576  * This is used to work around some encoder bugs.
1577  * A demuxer should set this to what is stored in the field used to identify the codec.
1578  * If there are multiple such fields in a container then the demuxer should choose the one
1579  * which maximizes the information about the used codec.
1580  * If the codec tag field in a container is larger than 32 bits then the demuxer should
1581  * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
1582  * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
1583  * first.
1584  * - encoding: Set by user, if not then the default based on codec_id will be used.
1585  * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1586  */
1587  unsigned int codec_tag;
1588 
1589  /**
1590  * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
1591  * This is used to work around some encoder bugs.
1592  * - encoding: unused
1593  * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
1594  */
1595  unsigned int stream_codec_tag;
1596 
1597 #if FF_API_SUB_ID
1598  /**
1599  * @deprecated this field is unused
1600  */
1601  attribute_deprecated int sub_id;
1602 #endif
1604  void *priv_data;
1605 
1606  /**
1607  * Private context used for internal data.
1608  *
1609  * Unlike priv_data, this is not codec-specific. It is used in general
1610  * libavcodec functions.
1611  */
1612  struct AVCodecInternal *internal;
1613 
1614  /**
1615  * Private data of the user, can be used to carry app specific stuff.
1616  * - encoding: Set by user.
1617  * - decoding: Set by user.
1618  */
1619  void *opaque;
1620 
1621  /**
1622  * the average bitrate
1623  * - encoding: Set by user; unused for constant quantizer encoding.
1624  * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
1625  */
1626  int bit_rate;
1627 
1628  /**
1629  * number of bits the bitstream is allowed to diverge from the reference.
1630  * the reference can be CBR (for CBR pass1) or VBR (for pass2)
1631  * - encoding: Set by user; unused for constant quantizer encoding.
1632  * - decoding: unused
1633  */
1634  int bit_rate_tolerance;
1635 
1636  /**
1637  * Global quality for codecs which cannot change it per frame.
1638  * This should be proportional to MPEG-1/2/4 qscale.
1639  * - encoding: Set by user.
1640  * - decoding: unused
1641  */
1642  int global_quality;
1643 
1644  /**
1645  * - encoding: Set by user.
1646  * - decoding: unused
1647  */
1649 #define FF_COMPRESSION_DEFAULT -1
1650 
1651  /**
1652  * CODEC_FLAG_*.
1653  * - encoding: Set by user.
1654  * - decoding: Set by user.
1655  */
1656  int flags;
1657 
1658  /**
1659  * CODEC_FLAG2_*
1660  * - encoding: Set by user.
1661  * - decoding: Set by user.
1662  */
1663  int flags2;
1664 
1665  /**
1666  * some codecs need / can use extradata like Huffman tables.
1667  * mjpeg: Huffman tables
1668  * rv10: additional flags
1669  * mpeg4: global headers (they can be in the bitstream or here)
1670  * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
1671  * than extradata_size to avoid prolems if it is read with the bitstream reader.
1672  * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
1673  * - encoding: Set/allocated/freed by libavcodec.
1674  * - decoding: Set/allocated/freed by user.
1675  */
1677  int extradata_size;
1678 
1679  /**
1680  * This is the fundamental unit of time (in seconds) in terms
1681  * of which frame timestamps are represented. For fixed-fps content,
1682  * timebase should be 1/framerate and timestamp increments should be
1683  * identically 1.
1684  * - encoding: MUST be set by user.
1685  * - decoding: Set by libavcodec.
1686  */
1688 
1689  /**
1690  * For some codecs, the time base is closer to the field rate than the frame rate.
1691  * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
1692  * if no telecine is used ...
1693  *
1694  * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
1695  */
1696  int ticks_per_frame;
1697 
1698  /**
1699  * Codec delay.
1700  *
1701  * Encoding: Number of frames delay there will be from the encoder input to
1702  * the decoder output. (we assume the decoder matches the spec)
1703  * Decoding: Number of frames delay in addition to what a standard decoder
1704  * as specified in the spec would produce.
1705  *
1706  * Video:
1707  * Number of frames the decoded output will be delayed relative to the
1708  * encoded input.
1709  *
1710  * Audio:
1711  * For encoding, this is the number of "priming" samples added to the
1712  * beginning of the stream. The decoded output will be delayed by this
1713  * many samples relative to the input to the encoder. Note that this
1714  * field is purely informational and does not directly affect the pts
1715  * output by the encoder, which should always be based on the actual
1716  * presentation time, including any delay.
1717  * For decoding, this is the number of samples the decoder needs to
1718  * output before the decoder's output is valid. When seeking, you should
1719  * start decoding this many samples prior to your desired seek point.
1720  *
1721  * - encoding: Set by libavcodec.
1722  * - decoding: Set by libavcodec.
1723  */
1724  int delay;
1725 
1726 
1727  /* video only */
1728  /**
1729  * picture width / height.
1730  * - encoding: MUST be set by user.
1731  * - decoding: Set by libavcodec.
1732  * Note: For compatibility it is possible to set this instead of
1733  * coded_width/height before decoding.
1734  */
1735  int width, height;
1736 
1737  /**
1738  * Bitstream width / height, may be different from width/height if lowres enabled.
1739  * - encoding: unused
1740  * - decoding: Set by user before init if known. Codec should override / dynamically change if needed.
1741  */
1744 #define FF_ASPECT_EXTENDED 15
1745 
1746  /**
1747  * the number of pictures in a group of pictures, or 0 for intra_only
1748  * - encoding: Set by user.
1749  * - decoding: unused
1750  */
1751  int gop_size;
1752 
1753  /**
1754  * Pixel format, see AV_PIX_FMT_xxx.
1755  * May be set by the demuxer if known from headers.
1756  * May be overridden by the decoder if it knows better.
1757  * - encoding: Set by user.
1758  * - decoding: Set by user if known, overridden by libavcodec if known
1759  */
1760  enum AVPixelFormat pix_fmt;
1761 
1762  /**
1763  * Motion estimation algorithm used for video coding.
1764  * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
1765  * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific]
1766  * - encoding: MUST be set by user.
1767  * - decoding: unused
1768  */
1769  int me_method;
1770 
1771  /**
1772  * If non NULL, 'draw_horiz_band' is called by the libavcodec
1773  * decoder to draw a horizontal band. It improves cache usage. Not
1774  * all codecs can do that. You must check the codec capabilities
1775  * beforehand.
1776  * When multithreading is used, it may be called from multiple threads
1777  * at the same time; threads might draw different parts of the same AVFrame,
1778  * or multiple AVFrames, and there is no guarantee that slices will be drawn
1779  * in order.
1780  * The function is also used by hardware acceleration APIs.
1781  * It is called at least once during frame decoding to pass
1782  * the data needed for hardware render.
1783  * In that mode instead of pixel data, AVFrame points to
1784  * a structure specific to the acceleration API. The application
1785  * reads the structure and can change some fields to indicate progress
1786  * or mark state.
1787  * - encoding: unused
1788  * - decoding: Set by user.
1789  * @param height the height of the slice
1790  * @param y the y position of the slice
1791  * @param type 1->top field, 2->bottom field, 3->frame
1792  * @param offset offset into the AVFrame.data from which the slice should be read
1793  */
1794  void (*draw_horiz_band)(struct AVCodecContext *s,
1795  const AVFrame *src, int offset[AV_NUM_DATA_POINTERS],
1796  int y, int type, int height);
1797 
1798  /**
1799  * callback to negotiate the pixelFormat
1800  * @param fmt is the list of formats which are supported by the codec,
1801  * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
1802  * The first is always the native one.
1803  * @return the chosen format
1804  * - encoding: unused
1805  * - decoding: Set by user, if not set the native format will be chosen.
1806  */
1807  enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat * fmt);
1808 
1809  /**
1810  * maximum number of B-frames between non-B-frames
1811  * Note: The output will be delayed by max_b_frames+1 relative to the input.
1812  * - encoding: Set by user.
1813  * - decoding: unused
1814  */
1815  int max_b_frames;
1816 
1817  /**
1818  * qscale factor between IP and B-frames
1819  * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
1820  * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1821  * - encoding: Set by user.
1822  * - decoding: unused
1823  */
1824  float b_quant_factor;
1825 
1826  /** obsolete FIXME remove */
1828 #define FF_RC_STRATEGY_XVID 1
1830  int b_frame_strategy;
1831 
1832 #if FF_API_MPV_GLOBAL_OPTS
1833  /**
1834  * luma single coefficient elimination threshold
1835  * - encoding: Set by user.
1836  * - decoding: unused
1837  */
1838  attribute_deprecated int luma_elim_threshold;
1839 
1840  /**
1841  * chroma single coeff elimination threshold
1842  * - encoding: Set by user.
1843  * - decoding: unused
1844  */
1845  attribute_deprecated int chroma_elim_threshold;
1846 #endif
1847 
1848  /**
1849  * qscale offset between IP and B-frames
1850  * - encoding: Set by user.
1851  * - decoding: unused
1852  */
1853  float b_quant_offset;
1854 
1855  /**
1856  * Size of the frame reordering buffer in the decoder.
1857  * For MPEG-2 it is 1 IPB or 0 low delay IP.
1858  * - encoding: Set by libavcodec.
1859  * - decoding: Set by libavcodec.
1860  */
1861  int has_b_frames;
1862 
1863  /**
1864  * 0-> h263 quant 1-> mpeg quant
1865  * - encoding: Set by user.
1866  * - decoding: unused
1867  */
1868  int mpeg_quant;
1869 
1870  /**
1871  * qscale factor between P and I-frames
1872  * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset).
1873  * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
1874  * - encoding: Set by user.
1875  * - decoding: unused
1876  */
1877  float i_quant_factor;
1878 
1879  /**
1880  * qscale offset between P and I-frames
1881  * - encoding: Set by user.
1882  * - decoding: unused
1883  */
1884  float i_quant_offset;
1885 
1886  /**
1887  * luminance masking (0-> disabled)
1888  * - encoding: Set by user.
1889  * - decoding: unused
1890  */
1891  float lumi_masking;
1892 
1893  /**
1894  * temporary complexity masking (0-> disabled)
1895  * - encoding: Set by user.
1896  * - decoding: unused
1897  */
1898  float temporal_cplx_masking;
1899 
1900  /**
1901  * spatial complexity masking (0-> disabled)
1902  * - encoding: Set by user.
1903  * - decoding: unused
1904  */
1905  float spatial_cplx_masking;
1906 
1907  /**
1908  * p block masking (0-> disabled)
1909  * - encoding: Set by user.
1910  * - decoding: unused
1911  */
1912  float p_masking;
1913 
1914  /**
1915  * darkness masking (0-> disabled)
1916  * - encoding: Set by user.
1917  * - decoding: unused
1918  */
1919  float dark_masking;
1920 
1921  /**
1922  * slice count
1923  * - encoding: Set by libavcodec.
1924  * - decoding: Set by user (or 0).
1925  */
1926  int slice_count;
1927  /**
1928  * prediction method (needed for huffyuv)
1929  * - encoding: Set by user.
1930  * - decoding: unused
1931  */
1933 #define FF_PRED_LEFT 0
1934 #define FF_PRED_PLANE 1
1935 #define FF_PRED_MEDIAN 2
1936 
1937  /**
1938  * slice offsets in the frame in bytes
1939  * - encoding: Set/allocated by libavcodec.
1940  * - decoding: Set/allocated by user (or NULL).
1941  */
1942  int *slice_offset;
1943 
1944  /**
1945  * sample aspect ratio (0 if unknown)
1946  * That is the width of a pixel divided by the height of the pixel.
1947  * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
1948  * - encoding: Set by user.
1949  * - decoding: Set by libavcodec.
1950  */
1952 
1953  /**
1954  * motion estimation comparison function
1955  * - encoding: Set by user.
1956  * - decoding: unused
1957  */
1958  int me_cmp;
1959  /**
1960  * subpixel motion estimation comparison function
1961  * - encoding: Set by user.
1962  * - decoding: unused
1963  */
1964  int me_sub_cmp;
1965  /**
1966  * macroblock comparison function (not supported yet)
1967  * - encoding: Set by user.
1968  * - decoding: unused
1969  */
1970  int mb_cmp;
1971  /**
1972  * interlaced DCT comparison function
1973  * - encoding: Set by user.
1974  * - decoding: unused
1975  */
1977 #define FF_CMP_SAD 0
1978 #define FF_CMP_SSE 1
1979 #define FF_CMP_SATD 2
1980 #define FF_CMP_DCT 3
1981 #define FF_CMP_PSNR 4
1982 #define FF_CMP_BIT 5
1983 #define FF_CMP_RD 6
1984 #define FF_CMP_ZERO 7
1985 #define FF_CMP_VSAD 8
1986 #define FF_CMP_VSSE 9
1987 #define FF_CMP_NSSE 10
1988 #define FF_CMP_W53 11
1989 #define FF_CMP_W97 12
1990 #define FF_CMP_DCTMAX 13
1991 #define FF_CMP_DCT264 14
1992 #define FF_CMP_CHROMA 256
1993 
1994  /**
1995  * ME diamond size & shape
1996  * - encoding: Set by user.
1997  * - decoding: unused
1998  */
1999  int dia_size;
2000 
2001  /**
2002  * amount of previous MV predictors (2a+1 x 2a+1 square)
2003  * - encoding: Set by user.
2004  * - decoding: unused
2005  */
2007 
2008  /**
2009  * prepass for motion estimation
2010  * - encoding: Set by user.
2011  * - decoding: unused
2012  */
2013  int pre_me;
2014 
2015  /**
2016  * motion estimation prepass comparison function
2017  * - encoding: Set by user.
2018  * - decoding: unused
2019  */
2020  int me_pre_cmp;
2021 
2022  /**
2023  * ME prepass diamond size & shape
2024  * - encoding: Set by user.
2025  * - decoding: unused
2026  */
2027  int pre_dia_size;
2028 
2029  /**
2030  * subpel ME quality
2031  * - encoding: Set by user.
2032  * - decoding: unused
2033  */
2034  int me_subpel_quality;
2035 
2036  /**
2037  * DTG active format information (additional aspect ratio
2038  * information only used in DVB MPEG-2 transport streams)
2039  * 0 if not set.
2040  *
2041  * - encoding: unused
2042  * - decoding: Set by decoder.
2043  */
2045 #define FF_DTG_AFD_SAME 8
2046 #define FF_DTG_AFD_4_3 9
2047 #define FF_DTG_AFD_16_9 10
2048 #define FF_DTG_AFD_14_9 11
2049 #define FF_DTG_AFD_4_3_SP_14_9 13
2050 #define FF_DTG_AFD_16_9_SP_14_9 14
2051 #define FF_DTG_AFD_SP_4_3 15
2052 
2053  /**
2054  * maximum motion estimation search range in subpel units
2055  * If 0 then no limit.
2056  *
2057  * - encoding: Set by user.
2058  * - decoding: unused
2059  */
2060  int me_range;
2061 
2062  /**
2063  * intra quantizer bias
2064  * - encoding: Set by user.
2065  * - decoding: unused
2066  */
2068 #define FF_DEFAULT_QUANT_BIAS 999999
2069 
2070  /**
2071  * inter quantizer bias
2072  * - encoding: Set by user.
2073  * - decoding: unused
2074  */
2075  int inter_quant_bias;
2076 
2077 #if FF_API_COLOR_TABLE_ID
2078  /**
2079  * color table ID
2080  * - encoding: unused
2081  * - decoding: Which clrtable should be used for 8bit RGB images.
2082  * Tables have to be stored somewhere. FIXME
2083  */
2084  attribute_deprecated int color_table_id;
2085 #endif
2086 
2087  /**
2088  * slice flags
2089  * - encoding: unused
2090  * - decoding: Set by user.
2091  */
2093 #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
2094 #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
2095 #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
2096 
2097  /**
2098  * XVideo Motion Acceleration
2099  * - encoding: forbidden
2100  * - decoding: set by decoder
2101  */
2102  int xvmc_acceleration;
2103 
2104  /**
2105  * macroblock decision mode
2106  * - encoding: Set by user.
2107  * - decoding: unused
2108  */
2110 #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
2111 #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
2112 #define FF_MB_DECISION_RD 2 ///< rate distortion
2113 
2114  /**
2115  * custom intra quantization matrix
2116  * - encoding: Set by user, can be NULL.
2117  * - decoding: Set by libavcodec.
2118  */
2119  uint16_t *intra_matrix;
2120 
2121  /**
2122  * custom inter quantization matrix
2123  * - encoding: Set by user, can be NULL.
2124  * - decoding: Set by libavcodec.
2125  */
2126  uint16_t *inter_matrix;
2127 
2128  /**
2129  * scene change detection threshold
2130  * 0 is default, larger means fewer detected scene changes.
2131  * - encoding: Set by user.
2132  * - decoding: unused
2133  */
2135 
2136  /**
2137  * noise reduction strength
2138  * - encoding: Set by user.
2139  * - decoding: unused
2140  */
2141  int noise_reduction;
2142 
2143 #if FF_API_INTER_THRESHOLD
2144  /**
2145  * @deprecated this field is unused
2146  */
2147  attribute_deprecated int inter_threshold;
2148 #endif
2149 
2150 #if FF_API_MPV_GLOBAL_OPTS
2151  /**
2152  * @deprecated use mpegvideo private options instead
2153  */
2154  attribute_deprecated int quantizer_noise_shaping;
2155 #endif
2156 
2157  /**
2158  * Motion estimation threshold below which no motion estimation is
2159  * performed, but instead the user specified motion vectors are used.
2160  *
2161  * - encoding: Set by user.
2162  * - decoding: unused
2163  */
2164  int me_threshold;
2165 
2166  /**
2167  * Macroblock threshold below which the user specified macroblock types will be used.
2168  * - encoding: Set by user.
2169  * - decoding: unused
2170  */
2171  int mb_threshold;
2172 
2173  /**
2174  * precision of the intra DC coefficient - 8
2175  * - encoding: Set by user.
2176  * - decoding: unused
2177  */
2178  int intra_dc_precision;
2179 
2180  /**
2181  * Number of macroblock rows at the top which are skipped.
2182  * - encoding: unused
2183  * - decoding: Set by user.
2184  */
2185  int skip_top;
2186 
2187  /**
2188  * Number of macroblock rows at the bottom which are skipped.
2189  * - encoding: unused
2190  * - decoding: Set by user.
2191  */
2192  int skip_bottom;
2193 
2194  /**
2195  * Border processing masking, raises the quantizer for mbs on the borders
2196  * of the picture.
2197  * - encoding: Set by user.
2198  * - decoding: unused
2199  */
2200  float border_masking;
2201 
2202  /**
2203  * minimum MB lagrange multipler
2204  * - encoding: Set by user.
2205  * - decoding: unused
2206  */
2207  int mb_lmin;
2208 
2209  /**
2210  * maximum MB lagrange multipler
2211  * - encoding: Set by user.
2212  * - decoding: unused
2213  */
2214  int mb_lmax;
2215 
2216  /**
2217  *
2218  * - encoding: Set by user.
2219  * - decoding: unused
2220  */
2222 
2223  /**
2224  *
2225  * - encoding: Set by user.
2226  * - decoding: unused
2227  */
2228  int bidir_refine;
2229 
2230  /**
2231  *
2232  * - encoding: Set by user.
2233  * - decoding: unused
2234  */
2235  int brd_scale;
2236 
2237  /**
2238  * minimum GOP size
2239  * - encoding: Set by user.
2240  * - decoding: unused
2241  */
2242  int keyint_min;
2243 
2244  /**
2245  * number of reference frames
2246  * - encoding: Set by user.
2247  * - decoding: Set by lavc.
2248  */
2249  int refs;
2250 
2251  /**
2252  * chroma qp offset from luma
2253  * - encoding: Set by user.
2254  * - decoding: unused
2255  */
2256  int chromaoffset;
2257 
2258  /**
2259  * Multiplied by qscale for each frame and added to scene_change_score.
2260  * - encoding: Set by user.
2261  * - decoding: unused
2262  */
2263  int scenechange_factor;
2264 
2265  /**
2266  *
2267  * Note: Value depends upon the compare function used for fullpel ME.
2268  * - encoding: Set by user.
2269  * - decoding: unused
2270  */
2271  int mv0_threshold;
2272 
2273  /**
2274  * Adjust sensitivity of b_frame_strategy 1.
2275  * - encoding: Set by user.
2276  * - decoding: unused
2277  */
2278  int b_sensitivity;
2279 
2280  /**
2281  * Chromaticity coordinates of the source primaries.
2282  * - encoding: Set by user
2283  * - decoding: Set by libavcodec
2284  */
2286 
2287  /**
2288  * Color Transfer Characteristic.
2289  * - encoding: Set by user
2290  * - decoding: Set by libavcodec
2291  */
2293 
2294  /**
2295  * YUV colorspace type.
2296  * - encoding: Set by user
2297  * - decoding: Set by libavcodec
2298  */
2299  enum AVColorSpace colorspace;
2300 
2301  /**
2302  * MPEG vs JPEG YUV range.
2303  * - encoding: Set by user
2304  * - decoding: Set by libavcodec
2305  */
2307 
2308  /**
2309  * This defines the location of chroma samples.
2310  * - encoding: Set by user
2311  * - decoding: Set by libavcodec
2312  */
2314 
2315  /**
2316  * Number of slices.
2317  * Indicates number of picture subdivisions. Used for parallelized
2318  * decoding.
2319  * - encoding: Set by user
2320  * - decoding: unused
2321  */
2322  int slices;
2323 
2324  /** Field order
2325  * - encoding: set by libavcodec
2326  * - decoding: Set by user.
2327  */
2329 
2330  /* audio only */
2331  int sample_rate; ///< samples per second
2332  int channels; ///< number of audio channels
2333 
2334  /**
2335  * audio sample format
2336  * - encoding: Set by user.
2337  * - decoding: Set by libavcodec.
2338  */
2339  enum AVSampleFormat sample_fmt; ///< sample format
2340 
2341  /* The following data should not be initialized. */
2342  /**
2343  * Number of samples per channel in an audio frame.
2344  *
2345  * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
2346  * except the last must contain exactly frame_size samples per channel.
2347  * May be 0 when the codec has CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
2348  * frame size is not restricted.
2349  * - decoding: may be set by some decoders to indicate constant frame size
2350  */
2351  int frame_size;
2352 
2353  /**
2354  * Frame counter, set by libavcodec.
2355  *
2356  * - decoding: total number of frames returned from the decoder so far.
2357  * - encoding: total number of frames passed to the encoder so far.
2358  *
2359  * @note the counter is not incremented if encoding/decoding resulted in
2360  * an error.
2361  */
2362  int frame_number;
2363 
2364  /**
2365  * number of bytes per packet if constant and known or 0
2366  * Used by some WAV based audio codecs.
2367  */
2368  int block_align;
2369 
2370  /**
2371  * Audio cutoff bandwidth (0 means "automatic")
2372  * - encoding: Set by user.
2373  * - decoding: unused
2374  */
2375  int cutoff;
2376 
2377 #if FF_API_REQUEST_CHANNELS
2378  /**
2379  * Decoder should decode to this many channels if it can (0 for default)
2380  * - encoding: unused
2381  * - decoding: Set by user.
2382  * @deprecated Deprecated in favor of request_channel_layout.
2383  */
2384  int request_channels;
2385 #endif
2386 
2387  /**
2388  * Audio channel layout.
2389  * - encoding: set by user.
2390  * - decoding: set by user, may be overwritten by libavcodec.
2391  */
2392  uint64_t channel_layout;
2393 
2394  /**
2395  * Request decoder to use this channel layout if it can (0 for default)
2396  * - encoding: unused
2397  * - decoding: Set by user.
2398  */
2399  uint64_t request_channel_layout;
2400 
2401  /**
2402  * Type of service that the audio stream conveys.
2403  * - encoding: Set by user.
2404  * - decoding: Set by libavcodec.
2405  */
2407 
2408  /**
2409  * desired sample format
2410  * - encoding: Not used.
2411  * - decoding: Set by user.
2412  * Decoder will decode to this format if it can.
2413  */
2415 
2416  /**
2417  * Called at the beginning of each frame to get a buffer for it.
2418  *
2419  * The function will set AVFrame.data[], AVFrame.linesize[].
2420  * AVFrame.extended_data[] must also be set, but it should be the same as
2421  * AVFrame.data[] except for planar audio with more channels than can fit
2422  * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as
2423  * many data pointers as it can hold.
2424  *
2425  * if CODEC_CAP_DR1 is not set then get_buffer() must call
2426  * avcodec_default_get_buffer() instead of providing buffers allocated by
2427  * some other means.
2428  *
2429  * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't
2430  * need it. avcodec_default_get_buffer() aligns the output buffer properly,
2431  * but if get_buffer() is overridden then alignment considerations should
2432  * be taken into account.
2433  *
2434  * @see avcodec_default_get_buffer()
2435  *
2436  * Video:
2437  *
2438  * If pic.reference is set then the frame will be read later by libavcodec.
2439  * avcodec_align_dimensions2() should be used to find the required width and
2440  * height, as they normally need to be rounded up to the next multiple of 16.
2441  *
2442  * If frame multithreading is used and thread_safe_callbacks is set,
2443  * it may be called from a different thread, but not from more than one at
2444  * once. Does not need to be reentrant.
2445  *
2446  * @see release_buffer(), reget_buffer()
2447  * @see avcodec_align_dimensions2()
2448  *
2449  * Audio:
2450  *
2451  * Decoders request a buffer of a particular size by setting
2452  * AVFrame.nb_samples prior to calling get_buffer(). The decoder may,
2453  * however, utilize only part of the buffer by setting AVFrame.nb_samples
2454  * to a smaller value in the output frame.
2455  *
2456  * Decoders cannot use the buffer after returning from
2457  * avcodec_decode_audio4(), so they will not call release_buffer(), as it
2458  * is assumed to be released immediately upon return. In some rare cases,
2459  * a decoder may need to call get_buffer() more than once in a single
2460  * call to avcodec_decode_audio4(). In that case, when get_buffer() is
2461  * called again after it has already been called once, the previously
2462  * acquired buffer is assumed to be released at that time and may not be
2463  * reused by the decoder.
2464  *
2465  * As a convenience, av_samples_get_buffer_size() and
2466  * av_samples_fill_arrays() in libavutil may be used by custom get_buffer()
2467  * functions to find the required data size and to fill data pointers and
2468  * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
2469  * since all planes must be the same size.
2470  *
2471  * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
2472  *
2473  * - encoding: unused
2474  * - decoding: Set by libavcodec, user can override.
2475  */
2476  int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
2477 
2478  /**
2479  * Called to release buffers which were allocated with get_buffer.
2480  * A released buffer can be reused in get_buffer().
2481  * pic.data[*] must be set to NULL.
2482  * May be called from a different thread if frame multithreading is used,
2483  * but not by more than one thread at once, so does not need to be reentrant.
2484  * - encoding: unused
2485  * - decoding: Set by libavcodec, user can override.
2486  */
2487  void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
2488 
2489  /**
2490  * Called at the beginning of a frame to get cr buffer for it.
2491  * Buffer type (size, hints) must be the same. libavcodec won't check it.
2492  * libavcodec will pass previous buffer in pic, function should return
2493  * same buffer or new buffer with old frame "painted" into it.
2494  * If pic.data[0] == NULL must behave like get_buffer().
2495  * if CODEC_CAP_DR1 is not set then reget_buffer() must call
2496  * avcodec_default_reget_buffer() instead of providing buffers allocated by
2497  * some other means.
2498  * - encoding: unused
2499  * - decoding: Set by libavcodec, user can override.
2500  */
2501  int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
2502 
2503 
2504  /* - encoding parameters */
2505  float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
2506  float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
2507 
2508  /**
2509  * minimum quantizer
2510  * - encoding: Set by user.
2511  * - decoding: unused
2512  */
2513  int qmin;
2514 
2515  /**
2516  * maximum quantizer
2517  * - encoding: Set by user.
2518  * - decoding: unused
2519  */
2520  int qmax;
2521 
2522  /**
2523  * maximum quantizer difference between frames
2524  * - encoding: Set by user.
2525  * - decoding: unused
2526  */
2527  int max_qdiff;
2528 
2529  /**
2530  * ratecontrol qmin qmax limiting method
2531  * 0-> clipping, 1-> use a nice continuous function to limit qscale wthin qmin/qmax.
2532  * - encoding: Set by user.
2533  * - decoding: unused
2534  */
2535  float rc_qsquish;
2538  int rc_qmod_freq;
2539 
2540  /**
2541  * decoder bitstream buffer size
2542  * - encoding: Set by user.
2543  * - decoding: unused
2544  */
2545  int rc_buffer_size;
2546 
2547  /**
2548  * ratecontrol override, see RcOverride
2549  * - encoding: Allocated/set/freed by user.
2550  * - decoding: unused
2551  */
2554 
2555  /**
2556  * rate control equation
2557  * - encoding: Set by user
2558  * - decoding: unused
2559  */
2560  const char *rc_eq;
2561 
2562  /**
2563  * maximum bitrate
2564  * - encoding: Set by user.
2565  * - decoding: unused
2566  */
2567  int rc_max_rate;
2568 
2569  /**
2570  * minimum bitrate
2571  * - encoding: Set by user.
2572  * - decoding: unused
2573  */
2574  int rc_min_rate;
2576  float rc_buffer_aggressivity;
2577 
2578  /**
2579  * initial complexity for pass1 ratecontrol
2580  * - encoding: Set by user.
2581  * - decoding: unused
2582  */
2583  float rc_initial_cplx;
2584 
2585  /**
2586  * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
2587  * - encoding: Set by user.
2588  * - decoding: unused.
2589  */
2591 
2592  /**
2593  * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
2594  * - encoding: Set by user.
2595  * - decoding: unused.
2596  */
2598 
2599  /**
2600  * Number of bits which should be loaded into the rc buffer before decoding starts.
2601  * - encoding: Set by user.
2602  * - decoding: unused
2603  */
2606 #define FF_CODER_TYPE_VLC 0
2607 #define FF_CODER_TYPE_AC 1
2608 #define FF_CODER_TYPE_RAW 2
2609 #define FF_CODER_TYPE_RLE 3
2610 #define FF_CODER_TYPE_DEFLATE 4
2611  /**
2612  * coder type
2613  * - encoding: Set by user.
2614  * - decoding: unused
2615  */
2616  int coder_type;
2617 
2618  /**
2619  * context model
2620  * - encoding: Set by user.
2621  * - decoding: unused
2622  */
2623  int context_model;
2624 
2625  /**
2626  * minimum Lagrange multipler
2627  * - encoding: Set by user.
2628  * - decoding: unused
2629  */
2630  int lmin;
2631 
2632  /**
2633  * maximum Lagrange multipler
2634  * - encoding: Set by user.
2635  * - decoding: unused
2636  */
2637  int lmax;
2638 
2639  /**
2640  * frame skip threshold
2641  * - encoding: Set by user.
2642  * - decoding: unused
2643  */
2645 
2646  /**
2647  * frame skip factor
2648  * - encoding: Set by user.
2649  * - decoding: unused
2650  */
2651  int frame_skip_factor;
2652 
2653  /**
2654  * frame skip exponent
2655  * - encoding: Set by user.
2656  * - decoding: unused
2657  */
2658  int frame_skip_exp;
2659 
2660  /**
2661  * frame skip comparison function
2662  * - encoding: Set by user.
2663  * - decoding: unused
2664  */
2665  int frame_skip_cmp;
2666 
2667  /**
2668  * trellis RD quantization
2669  * - encoding: Set by user.
2670  * - decoding: unused
2671  */
2672  int trellis;
2673 
2674  /**
2675  * - encoding: Set by user.
2676  * - decoding: unused
2677  */
2679 
2680  /**
2681  * - encoding: Set by user.
2682  * - decoding: unused
2683  */
2685 
2686  /**
2687  * GOP timecode frame start number
2688  * - encoding: Set by user, in non drop frame format
2689  * - decoding: Set by libavcodec (timecode in the 25 bits format, -1 if unset)
2690  */
2691  int64_t timecode_frame_start;
2692 
2693  /* The RTP callback: This function is called */
2694  /* every time the encoder has a packet to send. */
2695  /* It depends on the encoder if the data starts */
2696  /* with a Start Code (it should). H.263 does. */
2697  /* mb_nb contains the number of macroblocks */
2698  /* encoded in the RTP payload. */
2699  void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb);
2701  int rtp_payload_size; /* The size of the RTP payload: the coder will */
2702  /* do its best to deliver a chunk with size */
2703  /* below rtp_payload_size, the chunk will start */
2704  /* with a start code on some codecs like H.263. */
2705  /* This doesn't take account of any particular */
2706  /* headers inside the transmitted RTP payload. */
2707 
2708  /* statistics, used for 2-pass encoding */
2709  int mv_bits;
2713  int i_count;
2714  int p_count;
2716  int misc_bits;
2717 
2718  /**
2719  * number of bits used for the previously encoded frame
2720  * - encoding: Set by libavcodec.
2721  * - decoding: unused
2722  */
2723  int frame_bits;
2724 
2725  /**
2726  * pass1 encoding statistics output buffer
2727  * - encoding: Set by libavcodec.
2728  * - decoding: unused
2729  */
2730  char *stats_out;
2731 
2732  /**
2733  * pass2 encoding statistics input buffer
2734  * Concatenated stuff from stats_out of pass1 should be placed here.
2735  * - encoding: Allocated/set/freed by user.
2736  * - decoding: unused
2737  */
2738  char *stats_in;
2739 
2740  /**
2741  * Work around bugs in encoders which sometimes cannot be detected automatically.
2742  * - encoding: Set by user
2743  * - decoding: Set by user
2744  */
2746 #define FF_BUG_AUTODETECT 1 ///< autodetection
2747 #define FF_BUG_OLD_MSMPEG4 2
2748 #define FF_BUG_XVID_ILACE 4
2749 #define FF_BUG_UMP4 8
2750 #define FF_BUG_NO_PADDING 16
2751 #define FF_BUG_AMV 32
2752 #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default.
2753 #define FF_BUG_QPEL_CHROMA 64
2754 #define FF_BUG_STD_QPEL 128
2755 #define FF_BUG_QPEL_CHROMA2 256
2756 #define FF_BUG_DIRECT_BLOCKSIZE 512
2757 #define FF_BUG_EDGE 1024
2758 #define FF_BUG_HPEL_CHROMA 2048
2759 #define FF_BUG_DC_CLIP 4096
2760 #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders.
2761 #define FF_BUG_TRUNCATED 16384
2762 
2763  /**
2764  * strictly follow the standard (MPEG4, ...).
2765  * - encoding: Set by user.
2766  * - decoding: Set by user.
2767  * Setting this to STRICT or higher means the encoder and decoder will
2768  * generally do stupid things, whereas setting it to unofficial or lower
2769  * will mean the encoder might produce output that is not supported by all
2770  * spec-compliant decoders. Decoders don't differentiate between normal,
2771  * unofficial and experimental (that is, they always try to decode things
2772  * when they can) unless they are explicitly asked to behave stupidly
2773  * (=strictly conform to the specs)
2774  */
2776 #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software.
2777 #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences.
2778 #define FF_COMPLIANCE_NORMAL 0
2779 #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions
2780 #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things.
2781 
2782  /**
2783  * error concealment flags
2784  * - encoding: unused
2785  * - decoding: Set by user.
2786  */
2788 #define FF_EC_GUESS_MVS 1
2789 #define FF_EC_DEBLOCK 2
2790 
2791  /**
2792  * debug
2793  * - encoding: Set by user.
2794  * - decoding: Set by user.
2795  */
2796  int debug;
2797 #define FF_DEBUG_PICT_INFO 1
2798 #define FF_DEBUG_RC 2
2799 #define FF_DEBUG_BITSTREAM 4
2800 #define FF_DEBUG_MB_TYPE 8
2801 #define FF_DEBUG_QP 16
2802 #define FF_DEBUG_MV 32
2803 #define FF_DEBUG_DCT_COEFF 0x00000040
2804 #define FF_DEBUG_SKIP 0x00000080
2805 #define FF_DEBUG_STARTCODE 0x00000100
2806 #define FF_DEBUG_PTS 0x00000200
2807 #define FF_DEBUG_ER 0x00000400
2808 #define FF_DEBUG_MMCO 0x00000800
2809 #define FF_DEBUG_BUGS 0x00001000
2810 #define FF_DEBUG_VIS_QP 0x00002000
2811 #define FF_DEBUG_VIS_MB_TYPE 0x00004000
2812 #define FF_DEBUG_BUFFERS 0x00008000
2813 #define FF_DEBUG_THREADS 0x00010000
2814 
2815  /**
2816  * debug
2817  * - encoding: Set by user.
2818  * - decoding: Set by user.
2819  */
2821 #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
2822 #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
2823 #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
2824 
2825  /**
2826  * Error recognition; may misdetect some more or less valid parts as errors.
2827  * - encoding: unused
2828  * - decoding: Set by user.
2829  */
2831 #define AV_EF_CRCCHECK (1<<0)
2832 #define AV_EF_BITSTREAM (1<<1)
2833 #define AV_EF_BUFFER (1<<2)
2834 #define AV_EF_EXPLODE (1<<3)
2836 #define AV_EF_CAREFUL (1<<16)
2837 #define AV_EF_COMPLIANT (1<<17)
2838 #define AV_EF_AGGRESSIVE (1<<18)
2839 
2840 
2841  /**
2842  * opaque 64bit number (generally a PTS) that will be reordered and
2843  * output in AVFrame.reordered_opaque
2844  * @deprecated in favor of pkt_pts
2845  * - encoding: unused
2846  * - decoding: Set by user.
2847  */
2848  int64_t reordered_opaque;
2849 
2850  /**
2851  * Hardware accelerator in use
2852  * - encoding: unused.
2853  * - decoding: Set by libavcodec
2854  */
2855  struct AVHWAccel *hwaccel;
2856 
2857  /**
2858  * Hardware accelerator context.
2859  * For some hardware accelerators, a global context needs to be
2860  * provided by the user. In that case, this holds display-dependent
2861  * data FFmpeg cannot instantiate itself. Please refer to the
2862  * FFmpeg HW accelerator documentation to know how to fill this
2863  * is. e.g. for VA API, this is a struct vaapi_context.
2864  * - encoding: unused
2865  * - decoding: Set by user
2866  */
2867  void *hwaccel_context;
2868 
2869  /**
2870  * error
2871  * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR.
2872  * - decoding: unused
2873  */
2874  uint64_t error[AV_NUM_DATA_POINTERS];
2875 
2876  /**
2877  * DCT algorithm, see FF_DCT_* below
2878  * - encoding: Set by user.
2879  * - decoding: unused
2880  */
2882 #define FF_DCT_AUTO 0
2883 #define FF_DCT_FASTINT 1
2884 #define FF_DCT_INT 2
2885 #define FF_DCT_MMX 3
2886 #define FF_DCT_ALTIVEC 5
2887 #define FF_DCT_FAAN 6
2888 
2889  /**
2890  * IDCT algorithm, see FF_IDCT_* below.
2891  * - encoding: Set by user.
2892  * - decoding: Set by user.
2893  */
2895 #define FF_IDCT_AUTO 0
2896 #define FF_IDCT_INT 1
2897 #define FF_IDCT_SIMPLE 2
2898 #define FF_IDCT_SIMPLEMMX 3
2899 #define FF_IDCT_LIBMPEG2MMX 4
2900 #if FF_API_MMI
2901 #define FF_IDCT_MMI 5
2902 #endif
2903 #define FF_IDCT_ARM 7
2904 #define FF_IDCT_ALTIVEC 8
2905 #define FF_IDCT_SH4 9
2906 #define FF_IDCT_SIMPLEARM 10
2907 #define FF_IDCT_IPP 13
2908 #define FF_IDCT_XVIDMMX 14
2909 #define FF_IDCT_SIMPLEARMV5TE 16
2910 #define FF_IDCT_SIMPLEARMV6 17
2911 #define FF_IDCT_SIMPLEVIS 18
2912 #define FF_IDCT_FAAN 20
2913 #define FF_IDCT_SIMPLENEON 22
2914 #define FF_IDCT_SIMPLEALPHA 23
2915 #if FF_API_IDCT
2916 #define FF_IDCT_H264 11
2917 #define FF_IDCT_VP3 12
2918 #define FF_IDCT_CAVS 15
2919 #define FF_IDCT_WMV2 19
2920 #define FF_IDCT_EA 21
2921 #define FF_IDCT_BINK 24
2922 #endif
2923 
2924 #if FF_API_DSP_MASK
2925  /**
2926  * Unused.
2927  * @deprecated use av_set_cpu_flags_mask() instead.
2928  */
2929  attribute_deprecated unsigned dsp_mask;
2930 #endif
2931 
2932  /**
2933  * bits per sample/pixel from the demuxer (needed for huffyuv).
2934  * - encoding: Set by libavcodec.
2935  * - decoding: Set by user.
2936  */
2938 
2939  /**
2940  * Bits per sample/pixel of internal libavcodec pixel/sample format.
2941  * - encoding: set by user.
2942  * - decoding: set by libavcodec.
2943  */
2944  int bits_per_raw_sample;
2945 
2946  /**
2947  * low resolution decoding, 1-> 1/2 size, 2->1/4 size
2948  * - encoding: unused
2949  * - decoding: Set by user.
2950  */
2951  int lowres;
2952 
2953  /**
2954  * the picture in the bitstream
2955  * - encoding: Set by libavcodec.
2956  * - decoding: Set by libavcodec.
2957  */
2959 
2960  /**
2961  * thread count
2962  * is used to decide how many independent tasks should be passed to execute()
2963  * - encoding: Set by user.
2964  * - decoding: Set by user.
2965  */
2966  int thread_count;
2967 
2968  /**
2969  * Which multithreading methods to use.
2970  * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
2971  * so clients which cannot provide future frames should not use it.
2972  *
2973  * - encoding: Set by user, otherwise the default is used.
2974  * - decoding: Set by user, otherwise the default is used.
2975  */
2977 #define FF_THREAD_FRAME 1 ///< Decode more than one frame at once
2978 #define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once
2979 
2980  /**
2981  * Which multithreading methods are in use by the codec.
2982  * - encoding: Set by libavcodec.
2983  * - decoding: Set by libavcodec.
2984  */
2985  int active_thread_type;
2986 
2987  /**
2988  * Set by the client if its custom get_buffer() callback can be called
2989  * synchronously from another thread, which allows faster multithreaded decoding.
2990  * draw_horiz_band() will be called from other threads regardless of this setting.
2991  * Ignored if the default get_buffer() is used.
2992  * - encoding: Set by user.
2993  * - decoding: Set by user.
2994  */
2996 
2997  /**
2998  * The codec may call this to execute several independent things.
2999  * It will return only after finishing all tasks.
3000  * The user may replace this with some multithreaded implementation,
3001  * the default implementation will execute the parts serially.
3002  * @param count the number of things to execute
3003  * - encoding: Set by libavcodec, user can override.
3004  * - decoding: Set by libavcodec, user can override.
3005  */
3006  int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
3007 
3008  /**
3009  * The codec may call this to execute several independent things.
3010  * It will return only after finishing all tasks.
3011  * The user may replace this with some multithreaded implementation,
3012  * the default implementation will execute the parts serially.
3013  * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
3014  * @param c context passed also to func
3015  * @param count the number of things to execute
3016  * @param arg2 argument passed unchanged to func
3017  * @param ret return values of executed functions, must have space for "count" values. May be NULL.
3018  * @param func function that will be called count times, with jobnr from 0 to count-1.
3019  * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
3020  * two instances of func executing at the same time will have the same threadnr.
3021  * @return always 0 currently, but code should handle a future improvement where when any call to func
3022  * returns < 0 no further calls to func may be done and < 0 is returned.
3023  * - encoding: Set by libavcodec, user can override.
3024  * - decoding: Set by libavcodec, user can override.
3025  */
3026  int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count);
3027 
3028  /**
3029  * thread opaque
3030  * Can be used by execute() to store some per AVCodecContext stuff.
3031  * - encoding: set by execute()
3032  * - decoding: set by execute()
3033  */
3034  void *thread_opaque;
3035 
3036  /**
3037  * noise vs. sse weight for the nsse comparsion function
3038  * - encoding: Set by user.
3039  * - decoding: unused
3040  */
3041  int nsse_weight;
3042 
3043  /**
3044  * profile
3045  * - encoding: Set by user.
3046  * - decoding: Set by libavcodec.
3047  */
3048  int profile;
3049 #define FF_PROFILE_UNKNOWN -99
3050 #define FF_PROFILE_RESERVED -100
3052 #define FF_PROFILE_AAC_MAIN 0
3053 #define FF_PROFILE_AAC_LOW 1
3054 #define FF_PROFILE_AAC_SSR 2
3055 #define FF_PROFILE_AAC_LTP 3
3056 #define FF_PROFILE_AAC_HE 4
3057 #define FF_PROFILE_AAC_HE_V2 28
3058 #define FF_PROFILE_AAC_LD 22
3059 #define FF_PROFILE_AAC_ELD 38
3061 #define FF_PROFILE_DTS 20
3062 #define FF_PROFILE_DTS_ES 30
3063 #define FF_PROFILE_DTS_96_24 40
3064 #define FF_PROFILE_DTS_HD_HRA 50
3065 #define FF_PROFILE_DTS_HD_MA 60
3067 #define FF_PROFILE_MPEG2_422 0
3068 #define FF_PROFILE_MPEG2_HIGH 1
3069 #define FF_PROFILE_MPEG2_SS 2
3070 #define FF_PROFILE_MPEG2_SNR_SCALABLE 3
3071 #define FF_PROFILE_MPEG2_MAIN 4
3072 #define FF_PROFILE_MPEG2_SIMPLE 5
3074 #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
3075 #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
3077 #define FF_PROFILE_H264_BASELINE 66
3078 #define FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
3079 #define FF_PROFILE_H264_MAIN 77
3080 #define FF_PROFILE_H264_EXTENDED 88
3081 #define FF_PROFILE_H264_HIGH 100
3082 #define FF_PROFILE_H264_HIGH_10 110
3083 #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
3084 #define FF_PROFILE_H264_HIGH_422 122
3085 #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
3086 #define FF_PROFILE_H264_HIGH_444 144
3087 #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244
3088 #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
3089 #define FF_PROFILE_H264_CAVLC_444 44
3091 #define FF_PROFILE_VC1_SIMPLE 0
3092 #define FF_PROFILE_VC1_MAIN 1
3093 #define FF_PROFILE_VC1_COMPLEX 2
3094 #define FF_PROFILE_VC1_ADVANCED 3
3096 #define FF_PROFILE_MPEG4_SIMPLE 0
3097 #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1
3098 #define FF_PROFILE_MPEG4_CORE 2
3099 #define FF_PROFILE_MPEG4_MAIN 3
3100 #define FF_PROFILE_MPEG4_N_BIT 4
3101 #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5
3102 #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
3103 #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
3104 #define FF_PROFILE_MPEG4_HYBRID 8
3105 #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
3106 #define FF_PROFILE_MPEG4_CORE_SCALABLE 10
3107 #define FF_PROFILE_MPEG4_ADVANCED_CODING 11
3108 #define FF_PROFILE_MPEG4_ADVANCED_CORE 12
3109 #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
3110 #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14
3111 #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15
3112 
3113  /**
3114  * level
3115  * - encoding: Set by user.
3116  * - decoding: Set by libavcodec.
3117  */
3118  int level;
3119 #define FF_LEVEL_UNKNOWN -99
3120 
3121  /**
3122  *
3123  * - encoding: unused
3124  * - decoding: Set by user.
3125  */
3127 
3128  /**
3129  *
3130  * - encoding: unused
3131  * - decoding: Set by user.
3132  */
3133  enum AVDiscard skip_idct;
3134 
3135  /**
3136  *
3137  * - encoding: unused
3138  * - decoding: Set by user.
3139  */
3140  enum AVDiscard skip_frame;
3141 
3142  /**
3143  * Header containing style information for text subtitles.
3144  * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
3145  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
3146  * the Format line following. It shouldn't include any Dialogue line.
3147  * - encoding: Set/allocated/freed by user (before avcodec_open2())
3148  * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
3149  */
3152 
3153  /**
3154  * Simulates errors in the bitstream to test error concealment.
3155  * - encoding: Set by user.
3156  * - decoding: unused
3157  */
3158  int error_rate;
3159 
3160  /**
3161  * Current packet as passed into the decoder, to avoid having
3162  * to pass the packet into every function. Currently only valid
3163  * inside lavc and get/release_buffer callbacks.
3164  * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
3165  * - encoding: unused
3166  */
3167  AVPacket *pkt;
3168 
3169  /**
3170  * VBV delay coded in the last frame (in periods of a 27 MHz clock).
3171  * Used for compliant TS muxing.
3172  * - encoding: Set by libavcodec.
3173  * - decoding: unused.
3174  */
3175  uint64_t vbv_delay;
3176 
3177  /**
3178  * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
3179  * Code outside libavcodec should access this field using:
3180  * av_codec_{get,set}_pkt_timebase(avctx)
3181  * - encoding unused.
3182  * - decodimg set by user
3183  */
3185 
3186  /**
3187  * AVCodecDescriptor
3188  * Code outside libavcodec should access this field using:
3189  * av_codec_{get,set}_codec_descriptor(avctx)
3190  * - encoding: unused.
3191  * - decoding: set by libavcodec.
3192  */
3194 
3195  /**
3196  * Current statistics for PTS correction.
3197  * - decoding: maintained and used by libavcodec, not intended to be used by user apps
3198  * - encoding: unused
3199  */
3200  int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
3201  int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
3202  int64_t pts_correction_last_pts; /// PTS of the last frame
3203  int64_t pts_correction_last_dts; /// DTS of the last frame
3204 
3205  /**
3206  * Current frame metadata.
3207  * - decoding: maintained and used by libavcodec, not intended to be used by user apps
3208  * - encoding: unused
3209  */
3211 
3212  /**
3213  * Character encoding of the input subtitles file.
3214  * - decoding: set by user
3215  * - encoding: unused
3216  */
3217  char *sub_charenc;
3218 
3219  /**
3220  * Subtitles character encoding mode. Formats or codecs might be adjusting
3221  * this setting (if they are doing the conversion themselves for instance).
3222  * - decoding: set by libavcodec
3223  * - encoding: unused
3224  */
3226 #define FF_SUB_CHARENC_MODE_DO_NOTHING -1 ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance)
3227 #define FF_SUB_CHARENC_MODE_AUTOMATIC 0 ///< libavcodec will select the mode itself
3228 #define FF_SUB_CHARENC_MODE_PRE_DECODER 1 ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
3229 } AVCodecContext;
3230 
3233 
3236 
3237 /**
3238  * AVProfile.
3239  */
3240 typedef struct AVProfile {
3241  int profile;
3242  const char *name; ///< short name for the profile
3243 } AVProfile;
3244 
3245 typedef struct AVCodecDefault AVCodecDefault;
3246 
3247 struct AVSubtitle;
3248 
3249 /**
3250  * AVCodec.
3251  */
3252 typedef struct AVCodec {
3253  /**
3254  * Name of the codec implementation.
3255  * The name is globally unique among encoders and among decoders (but an
3256  * encoder and a decoder can share the same name).
3257  * This is the primary way to find a codec from the user perspective.
3258  */
3259  const char *name;
3260  /**
3261  * Descriptive name for the codec, meant to be more human readable than name.
3262  * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
3263  */
3264  const char *long_name;
3265  enum AVMediaType type;
3266  enum AVCodecID id;
3267  /**
3268  * Codec capabilities.
3269  * see CODEC_CAP_*
3270  */
3271  int capabilities;
3272  const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
3273  const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
3274  const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
3275  const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
3276  const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
3277  uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
3278  const AVClass *priv_class; ///< AVClass for the private context
3279  const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
3280 
3281  /*****************************************************************
3282  * No fields below this line are part of the public API. They
3283  * may not be used outside of libavcodec and can be changed and
3284  * removed at will.
3285  * New public fields should be added right above.
3286  *****************************************************************
3287  */
3288  int priv_data_size;
3289  struct AVCodec *next;
3290  /**
3291  * @name Frame-level threading support functions
3292  * @{
3293  */
3294  /**
3295  * If defined, called on thread contexts when they are created.
3296  * If the codec allocates writable tables in init(), re-allocate them here.
3297  * priv_data will be set to a copy of the original.
3298  */
3299  int (*init_thread_copy)(AVCodecContext *);
3300  /**
3301  * Copy necessary context variables from a previous thread context to the current one.
3302  * If not defined, the next thread will start automatically; otherwise, the codec
3303  * must call ff_thread_finish_setup().
3304  *
3305  * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
3306  */
3308  /** @} */
3309 
3310  /**
3311  * Private codec-specific defaults.
3312  */
3313  const AVCodecDefault *defaults;
3314 
3315  /**
3316  * Initialize codec static data, called from avcodec_register().
3317  */
3318  void (*init_static_data)(struct AVCodec *codec);
3321  int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
3322  const struct AVSubtitle *sub);
3323  /**
3324  * Encode data to an AVPacket.
3325  *
3326  * @param avctx codec context
3327  * @param avpkt output AVPacket (may contain a user-provided buffer)
3328  * @param[in] frame AVFrame containing the raw data to be encoded
3329  * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
3330  * non-empty packet was returned in avpkt.
3331  * @return 0 on success, negative error code on failure
3332  */
3333  int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
3334  int *got_packet_ptr);
3335  int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
3336  int (*close)(AVCodecContext *);
3337  /**
3338  * Flush buffers.
3339  * Will be called when seeking
3340  */
3341  void (*flush)(AVCodecContext *);
3342 } AVCodec;
3343 
3344 /**
3345  * AVHWAccel.
3346  */
3347 typedef struct AVHWAccel {
3348  /**
3349  * Name of the hardware accelerated codec.
3350  * The name is globally unique among encoders and among decoders (but an
3351  * encoder and a decoder can share the same name).
3352  */
3353  const char *name;
3354 
3355  /**
3356  * Type of codec implemented by the hardware accelerator.
3357  *
3358  * See AVMEDIA_TYPE_xxx
3359  */
3360  enum AVMediaType type;
3361 
3362  /**
3363  * Codec implemented by the hardware accelerator.
3364  *
3365  * See AV_CODEC_ID_xxx
3366  */
3367  enum AVCodecID id;
3368 
3369  /**
3370  * Supported pixel format.
3371  *
3372  * Only hardware accelerated formats are supported here.
3373  */
3374  enum AVPixelFormat pix_fmt;
3375 
3376  /**
3377  * Hardware accelerated codec capabilities.
3378  * see FF_HWACCEL_CODEC_CAP_*
3379  */
3380  int capabilities;
3382  struct AVHWAccel *next;
3383 
3384  /**
3385  * Called at the beginning of each frame or field picture.
3386  *
3387  * Meaningful frame information (codec specific) is guaranteed to
3388  * be parsed at this point. This function is mandatory.
3389  *
3390  * Note that buf can be NULL along with buf_size set to 0.
3391  * Otherwise, this means the whole frame is available at this point.
3392  *
3393  * @param avctx the codec context
3394  * @param buf the frame data buffer base
3395  * @param buf_size the size of the frame in bytes
3396  * @return zero if successful, a negative value otherwise
3397  */
3398  int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
3399 
3400  /**
3401  * Callback for each slice.
3402  *
3403  * Meaningful slice information (codec specific) is guaranteed to
3404  * be parsed at this point. This function is mandatory.
3405  *
3406  * @param avctx the codec context
3407  * @param buf the slice data buffer base
3408  * @param buf_size the size of the slice in bytes
3409  * @return zero if successful, a negative value otherwise
3410  */
3411  int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size);
3412 
3413  /**
3414  * Called at the end of each frame or field picture.
3415  *
3416  * The whole picture is parsed at this point and can now be sent
3417  * to the hardware accelerator. This function is mandatory.
3418  *
3419  * @param avctx the codec context
3420  * @return zero if successful, a negative value otherwise
3421  */
3422  int (*end_frame)(AVCodecContext *avctx);
3423 
3424  /**
3425  * Size of HW accelerator private data.
3426  *
3427  * Private data is allocated with av_mallocz() before
3428  * AVCodecContext.get_buffer() and deallocated after
3429  * AVCodecContext.release_buffer().
3430  */
3431  int priv_data_size;
3432 } AVHWAccel;
3433 
3434 /**
3435  * @defgroup lavc_picture AVPicture
3436  *
3437  * Functions for working with AVPicture
3438  * @{
3439  */
3440 
3441 /**
3442  * four components are given, that's all.
3443  * the last component is alpha
3444  */
3445 typedef struct AVPicture {
3447  int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line
3448 } AVPicture;
3449 
3450 /**
3451  * @}
3452  */
3455  SUBTITLE_NONE,
3457  SUBTITLE_BITMAP, ///< A bitmap, pict will be set
3458 
3459  /**
3460  * Plain text, the text field must be set by the decoder and is
3461  * authoritative. ass and pict fields may contain approximations.
3462  */
3463  SUBTITLE_TEXT,
3464 
3465  /**
3466  * Formatted text, the ass field must be set by the decoder and is
3467  * authoritative. pict and text fields may contain approximations.
3468  */
3469  SUBTITLE_ASS,
3470 };
3472 #define AV_SUBTITLE_FLAG_FORCED 0x00000001
3474 typedef struct AVSubtitleRect {
3475  int x; ///< top left corner of pict, undefined when pict is not set
3476  int y; ///< top left corner of pict, undefined when pict is not set
3477  int w; ///< width of pict, undefined when pict is not set
3478  int h; ///< height of pict, undefined when pict is not set
3479  int nb_colors; ///< number of colors in pict, undefined when pict is not set
3480 
3481  /**
3482  * data+linesize for the bitmap of this subtitle.
3483  * can be set for text/ass as well once they where rendered
3484  */
3486  enum AVSubtitleType type;
3488  char *text; ///< 0 terminated plain UTF-8 text
3489 
3490  /**
3491  * 0 terminated ASS/SSA compatible event line.
3492  * The presentation of this is unaffected by the other values in this
3493  * struct.
3494  */
3495  char *ass;
3497  int flags;
3498 } AVSubtitleRect;
3500 typedef struct AVSubtitle {
3501  uint16_t format; /* 0 = graphics */
3502  uint32_t start_display_time; /* relative to packet pts, in ms */
3503  uint32_t end_display_time; /* relative to packet pts, in ms */
3504  unsigned num_rects;
3506  int64_t pts; ///< Same as packet pts, in AV_TIME_BASE
3507 } AVSubtitle;
3508 
3509 /**
3510  * If c is NULL, returns the first registered codec,
3511  * if c is non-NULL, returns the next registered codec after c,
3512  * or NULL if c is the last one.
3513  */
3514 AVCodec *av_codec_next(const AVCodec *c);
3515 
3516 /**
3517  * Return the LIBAVCODEC_VERSION_INT constant.
3518  */
3519 unsigned avcodec_version(void);
3520 
3521 /**
3522  * Return the libavcodec build-time configuration.
3523  */
3524 const char *avcodec_configuration(void);
3525 
3526 /**
3527  * Return the libavcodec license.
3528  */
3529 const char *avcodec_license(void);
3530 
3531 /**
3532  * Register the codec codec and initialize libavcodec.
3533  *
3534  * @warning either this function or avcodec_register_all() must be called
3535  * before any other libavcodec functions.
3536  *
3537  * @see avcodec_register_all()
3538  */
3540 
3541 /**
3542  * Register all the codecs, parsers and bitstream filters which were enabled at
3543  * configuration time. If you do not call this function you can select exactly
3544  * which formats you want to support, by using the individual registration
3545  * functions.
3546  *
3547  * @see avcodec_register
3548  * @see av_register_codec_parser
3549  * @see av_register_bitstream_filter
3550  */
3551 void avcodec_register_all(void);
3552 
3553 
3554 #if FF_API_ALLOC_CONTEXT
3555 /**
3556  * Allocate an AVCodecContext and set its fields to default values. The
3557  * resulting struct can be deallocated by simply calling av_free().
3558  *
3559  * @return An AVCodecContext filled with default values or NULL on failure.
3560  * @see avcodec_get_context_defaults
3561  *
3562  * @deprecated use avcodec_alloc_context3()
3563  */
3565 AVCodecContext *avcodec_alloc_context(void);
3566 
3567 /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3568  * we WILL change its arguments and name a few times! */
3570 AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
3571 
3572 /**
3573  * Set the fields of the given AVCodecContext to default values.
3574  *
3575  * @param s The AVCodecContext of which the fields should be set to default values.
3576  * @deprecated use avcodec_get_context_defaults3
3577  */
3579 void avcodec_get_context_defaults(AVCodecContext *s);
3580 
3581 /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3582  * we WILL change its arguments and name a few times! */
3584 void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
3585 #endif
3586 
3587 /**
3588  * Allocate an AVCodecContext and set its fields to default values. The
3589  * resulting struct can be deallocated by calling avcodec_close() on it followed
3590  * by av_free().
3591  *
3592  * @param codec if non-NULL, allocate private data and initialize defaults
3593  * for the given codec. It is illegal to then call avcodec_open2()
3594  * with a different codec.
3595  * If NULL, then the codec-specific defaults won't be initialized,
3596  * which may result in suboptimal default settings (this is
3597  * important mainly for encoders, e.g. libx264).
3598  *
3599  * @return An AVCodecContext filled with default values or NULL on failure.
3600  * @see avcodec_get_context_defaults
3601  */
3603 
3604 /**
3605  * Set the fields of the given AVCodecContext to default values corresponding
3606  * to the given codec (defaults may be codec-dependent).
3607  *
3608  * Do not call this function if a non-NULL codec has been passed
3609  * to avcodec_alloc_context3() that allocated this AVCodecContext.
3610  * If codec is non-NULL, it is illegal to call avcodec_open2() with a
3611  * different codec on this AVCodecContext.
3612  */
3614 
3615 /**
3616  * Get the AVClass for AVCodecContext. It can be used in combination with
3617  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
3618  *
3619  * @see av_opt_find().
3620  */
3621 const AVClass *avcodec_get_class(void);
3622 
3623 /**
3624  * Get the AVClass for AVFrame. It can be used in combination with
3625  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
3626  *
3627  * @see av_opt_find().
3628  */
3629 const AVClass *avcodec_get_frame_class(void);
3630 
3631 /**
3632  * Get the AVClass for AVSubtitleRect. It can be used in combination with
3633  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
3634  *
3635  * @see av_opt_find().
3636  */
3638 
3639 /**
3640  * Copy the settings of the source AVCodecContext into the destination
3641  * AVCodecContext. The resulting destination codec context will be
3642  * unopened, i.e. you are required to call avcodec_open2() before you
3643  * can use this AVCodecContext to decode/encode video/audio data.
3644  *
3645  * @param dest target codec context, should be initialized with
3646  * avcodec_alloc_context3(), but otherwise uninitialized
3647  * @param src source codec context
3648  * @return AVERROR() on error (e.g. memory allocation error), 0 on success
3649  */
3650 int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src);
3651 
3652 /**
3653  * Allocate an AVFrame and set its fields to default values. The resulting
3654  * struct must be freed using avcodec_free_frame().
3655  *
3656  * @return An AVFrame filled with default values or NULL on failure.
3657  * @see avcodec_get_frame_defaults
3658  */
3660 
3661 /**
3662  * Set the fields of the given AVFrame to default values.
3663  *
3664  * @param frame The AVFrame of which the fields should be set to default values.
3665  */
3667 
3668 /**
3669  * Free the frame and any dynamically allocated objects in it,
3670  * e.g. extended_data.
3671  *
3672  * @param frame frame to be freed. The pointer will be set to NULL.
3673  *
3674  * @warning this function does NOT free the data buffers themselves
3675  * (it does not know how, since they might have been allocated with
3676  * a custom get_buffer()).
3677  */
3679 
3680 #if FF_API_AVCODEC_OPEN
3681 /**
3682  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3683  * function the context has to be allocated.
3684  *
3685  * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
3686  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
3687  * retrieving a codec.
3688  *
3689  * @warning This function is not thread safe!
3690  *
3691  * @code
3692  * avcodec_register_all();
3693  * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
3694  * if (!codec)
3695  * exit(1);
3696  *
3697  * context = avcodec_alloc_context3(codec);
3698  *
3699  * if (avcodec_open(context, codec) < 0)
3700  * exit(1);
3701  * @endcode
3702  *
3703  * @param avctx The context which will be set up to use the given codec.
3704  * @param codec The codec to use within the context.
3705  * @return zero on success, a negative value on error
3706  * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
3707  *
3708  * @deprecated use avcodec_open2
3709  */
3711 int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
3712 #endif
3713 
3714 /**
3715  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
3716  * function the context has to be allocated with avcodec_alloc_context3().
3717  *
3718  * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
3719  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
3720  * retrieving a codec.
3721  *
3722  * @warning This function is not thread safe!
3723  *
3724  * @code
3725  * avcodec_register_all();
3726  * av_dict_set(&opts, "b", "2.5M", 0);
3727  * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
3728  * if (!codec)
3729  * exit(1);
3730  *
3731  * context = avcodec_alloc_context3(codec);
3732  *
3733  * if (avcodec_open2(context, codec, opts) < 0)
3734  * exit(1);
3735  * @endcode
3736  *
3737  * @param avctx The context to initialize.
3738  * @param codec The codec to open this context for. If a non-NULL codec has been
3739  * previously passed to avcodec_alloc_context3() or
3740  * avcodec_get_context_defaults3() for this context, then this
3741  * parameter MUST be either NULL or equal to the previously passed
3742  * codec.
3743  * @param options A dictionary filled with AVCodecContext and codec-private options.
3744  * On return this object will be filled with options that were not found.
3745  *
3746  * @return zero on success, a negative value on error
3747  * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
3748  * av_dict_set(), av_opt_find().
3749  */
3751 
3752 /**
3753  * Close a given AVCodecContext and free all the data associated with it
3754  * (but not the AVCodecContext itself).
3755  *
3756  * Calling this function on an AVCodecContext that hasn't been opened will free
3757  * the codec-specific data allocated in avcodec_alloc_context3() /
3758  * avcodec_get_context_defaults3() with a non-NULL codec. Subsequent calls will
3759  * do nothing.
3760  */
3761 int avcodec_close(AVCodecContext *avctx);
3762 
3763 /**
3764  * Free all allocated data in the given subtitle struct.
3765  *
3766  * @param sub AVSubtitle to free.
3767  */
3768 void avsubtitle_free(AVSubtitle *sub);
3769 
3770 /**
3771  * @}
3772  */
3773 
3774 /**
3775  * @addtogroup lavc_packet
3776  * @{
3777  */
3778 
3779 /**
3780  * Default packet destructor.
3781  */
3783 
3784 /**
3785  * Initialize optional fields of a packet with default values.
3786  *
3787  * Note, this does not touch the data and size members, which have to be
3788  * initialized separately.
3789  *
3790  * @param pkt packet
3791  */
3792 void av_init_packet(AVPacket *pkt);
3793 
3794 /**
3795  * Allocate the payload of a packet and initialize its fields with
3796  * default values.
3797  *
3798  * @param pkt packet
3799  * @param size wanted payload size
3800  * @return 0 if OK, AVERROR_xxx otherwise
3801  */
3802 int av_new_packet(AVPacket *pkt, int size);
3803 
3804 /**
3805  * Reduce packet size, correctly zeroing padding
3806  *
3807  * @param pkt packet
3808  * @param size new size
3809  */
3810 void av_shrink_packet(AVPacket *pkt, int size);
3811 
3812 /**
3813  * Increase packet size, correctly zeroing padding
3814  *
3815  * @param pkt packet
3816  * @param grow_by number of bytes by which to increase the size of the packet
3817  */
3818 int av_grow_packet(AVPacket *pkt, int grow_by);
3819 
3820 /**
3821  * @warning This is a hack - the packet memory allocation stuff is broken. The
3822  * packet is allocated if it was not really allocated.
3823  */
3824 int av_dup_packet(AVPacket *pkt);
3825 
3826 /**
3827  * Copy packet, including contents
3828  *
3829  * @return 0 on success, negative AVERROR on fail
3830  */
3831 int av_copy_packet(AVPacket *dst, AVPacket *src);
3832 
3833 /**
3834  * Free a packet.
3835  *
3836  * @param pkt packet to free
3837  */
3838 void av_free_packet(AVPacket *pkt);
3839 
3840 /**
3841  * Allocate new information of a packet.
3842  *
3843  * @param pkt packet
3844  * @param type side information type
3845  * @param size side information size
3846  * @return pointer to fresh allocated data or NULL otherwise
3847  */
3849  int size);
3850 
3851 /**
3852  * Shrink the already allocated side data buffer
3853  *
3854  * @param pkt packet
3855  * @param type side information type
3856  * @param size new side information size
3857  * @return 0 on success, < 0 on failure
3858  */
3860  int size);
3861 
3862 /**
3863  * Get side information from packet.
3864  *
3865  * @param pkt packet
3866  * @param type desired side information type
3867  * @param size pointer for side information size to store (optional)
3868  * @return pointer to data if present or NULL otherwise
3869  */
3871  int *size);
3872 
3874 
3876 
3877 
3878 /**
3879  * @}
3880  */
3881 
3882 /**
3883  * @addtogroup lavc_decoding
3884  * @{
3885  */
3886 
3887 /**
3888  * Find a registered decoder with a matching codec ID.
3889  *
3890  * @param id AVCodecID of the requested decoder
3891  * @return A decoder if one was found, NULL otherwise.
3892  */
3894 
3895 /**
3896  * Find a registered decoder with the specified name.
3897  *
3898  * @param name name of the requested decoder
3899  * @return A decoder if one was found, NULL otherwise.
3900  */
3902 
3906 
3907 /**
3908  * Return the amount of padding in pixels which the get_buffer callback must
3909  * provide around the edge of the image for codecs which do not have the
3910  * CODEC_FLAG_EMU_EDGE flag.
3911  *
3912  * @return Required padding in pixels.
3913  */
3914 unsigned avcodec_get_edge_width(void);
3915 
3916 /**
3917  * Modify width and height values so that they will result in a memory
3918  * buffer that is acceptable for the codec if you do not use any horizontal
3919  * padding.
3920  *
3921  * May only be used if a codec with CODEC_CAP_DR1 has been opened.
3922  * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
3923  * according to avcodec_get_edge_width() before.
3924  */
3926 
3927 /**
3928  * Modify width and height values so that they will result in a memory
3929  * buffer that is acceptable for the codec if you also ensure that all
3930  * line sizes are a multiple of the respective linesize_align[i].
3931  *
3932  * May only be used if a codec with CODEC_CAP_DR1 has been opened.
3933  * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased
3934  * according to avcodec_get_edge_width() before.
3935  */
3937  int linesize_align[AV_NUM_DATA_POINTERS]);
3938 
3939 #if FF_API_OLD_DECODE_AUDIO
3940 /**
3941  * Wrapper function which calls avcodec_decode_audio4.
3942  *
3943  * @deprecated Use avcodec_decode_audio4 instead.
3944  *
3945  * Decode the audio frame of size avpkt->size from avpkt->data into samples.
3946  * Some decoders may support multiple frames in a single AVPacket, such
3947  * decoders would then just decode the first frame. In this case,
3948  * avcodec_decode_audio3 has to be called again with an AVPacket that contains
3949  * the remaining data in order to decode the second frame etc.
3950  * If no frame
3951  * could be outputted, frame_size_ptr is zero. Otherwise, it is the
3952  * decompressed frame size in bytes.
3953  *
3954  * @warning You must set frame_size_ptr to the allocated size of the
3955  * output buffer before calling avcodec_decode_audio3().
3956  *
3957  * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
3958  * the actual read bytes because some optimized bitstream readers read 32 or 64
3959  * bits at once and could read over the end.
3960  *
3961  * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that
3962  * no overreading happens for damaged MPEG streams.
3963  *
3964  * @warning You must not provide a custom get_buffer() when using
3965  * avcodec_decode_audio3(). Doing so will override it with
3966  * avcodec_default_get_buffer. Use avcodec_decode_audio4() instead,
3967  * which does allow the application to provide a custom get_buffer().
3968  *
3969  * @note You might have to align the input buffer avpkt->data and output buffer
3970  * samples. The alignment requirements depend on the CPU: On some CPUs it isn't
3971  * necessary at all, on others it won't work at all if not aligned and on others
3972  * it will work but it will have an impact on performance.
3973  *
3974  * In practice, avpkt->data should have 4 byte alignment at minimum and
3975  * samples should be 16 byte aligned unless the CPU doesn't need it
3976  * (AltiVec and SSE do).
3977  *
3978  * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
3979  * between input and output, these need to be fed with avpkt->data=NULL,
3980  * avpkt->size=0 at the end to return the remaining frames.
3981  *
3982  * @param avctx the codec context
3983  * @param[out] samples the output buffer, sample type in avctx->sample_fmt
3984  * If the sample format is planar, each channel plane will
3985  * be the same size, with no padding between channels.
3986  * @param[in,out] frame_size_ptr the output buffer size in bytes
3987  * @param[in] avpkt The input AVPacket containing the input buffer.
3988  * You can create such packet with av_init_packet() and by then setting
3989  * data and size, some decoders might in addition need other fields.
3990  * All decoders are designed to use the least fields possible though.
3991  * @return On error a negative value is returned, otherwise the number of bytes
3992  * used or zero if no frame data was decompressed (used) from the input AVPacket.
3993  */
3994 attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
3995  int *frame_size_ptr,
3996  AVPacket *avpkt);
3997 #endif
3998 
3999 /**
4000  * Decode the audio frame of size avpkt->size from avpkt->data into frame.
4001  *
4002  * Some decoders may support multiple frames in a single AVPacket. Such
4003  * decoders would then just decode the first frame. In this case,
4004  * avcodec_decode_audio4 has to be called again with an AVPacket containing
4005  * the remaining data in order to decode the second frame, etc...
4006  * Even if no frames are returned, the packet needs to be fed to the decoder
4007  * with remaining data until it is completely consumed or an error occurs.
4008  *
4009  * @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE
4010  * larger than the actual read bytes because some optimized bitstream
4011  * readers read 32 or 64 bits at once and could read over the end.
4012  *
4013  * @note You might have to align the input buffer. The alignment requirements
4014  * depend on the CPU and the decoder.
4015  *
4016  * @param avctx the codec context
4017  * @param[out] frame The AVFrame in which to store decoded audio samples.
4018  * Decoders request a buffer of a particular size by setting
4019  * AVFrame.nb_samples prior to calling get_buffer(). The
4020  * decoder may, however, only utilize part of the buffer by
4021  * setting AVFrame.nb_samples to a smaller value in the
4022  * output frame.
4023  * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
4024  * non-zero.
4025  * @param[in] avpkt The input AVPacket containing the input buffer.
4026  * At least avpkt->data and avpkt->size should be set. Some
4027  * decoders might also require additional fields to be set.
4028  * @return A negative error code is returned if an error occurred during
4029  * decoding, otherwise the number of bytes consumed from the input
4030  * AVPacket is returned.
4031  */
4033  int *got_frame_ptr, const AVPacket *avpkt);
4034 
4035 /**
4036  * Decode the video frame of size avpkt->size from avpkt->data into picture.
4037  * Some decoders may support multiple frames in a single AVPacket, such
4038  * decoders would then just decode the first frame.
4039  *
4040  * @warning The input buffer must be FF_INPUT_BUFFER_PADDING_SIZE larger than
4041  * the actual read bytes because some optimized bitstream readers read 32 or 64
4042  * bits at once and could read over the end.
4043  *
4044  * @warning The end of the input buffer buf should be set to 0 to ensure that
4045  * no overreading happens for damaged MPEG streams.
4046  *
4047  * @note You might have to align the input buffer avpkt->data.
4048  * The alignment requirements depend on the CPU: on some CPUs it isn't
4049  * necessary at all, on others it won't work at all if not aligned and on others
4050  * it will work but it will have an impact on performance.
4051  *
4052  * In practice, avpkt->data should have 4 byte alignment at minimum.
4053  *
4054  * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay
4055  * between input and output, these need to be fed with avpkt->data=NULL,
4056  * avpkt->size=0 at the end to return the remaining frames.
4057  *
4058  * @param avctx the codec context
4059  * @param[out] picture The AVFrame in which the decoded video frame will be stored.
4060  * Use avcodec_alloc_frame to get an AVFrame, the codec will
4061  * allocate memory for the actual bitmap.
4062  * with default get/release_buffer(), the decoder frees/reuses the bitmap as it sees fit.
4063  * with overridden get/release_buffer() (needs CODEC_CAP_DR1) the user decides into what buffer the decoder
4064  * decodes and the decoder tells the user once it does not need the data anymore,
4065  * the user app can at this point free/reuse/keep the memory as it sees fit.
4066  *
4067  * @param[in] avpkt The input AVpacket containing the input buffer.
4068  * You can create such packet with av_init_packet() and by then setting
4069  * data and size, some decoders might in addition need other fields like
4070  * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
4071  * fields possible.
4072  * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
4073  * @return On error a negative value is returned, otherwise the number of bytes
4074  * used or zero if no frame could be decompressed.
4075  */
4076 int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
4077  int *got_picture_ptr,
4078  const AVPacket *avpkt);
4079 
4080 /**
4081  * Decode a subtitle message.
4082  * Return a negative value on error, otherwise return the number of bytes used.
4083  * If no subtitle could be decompressed, got_sub_ptr is zero.
4084  * Otherwise, the subtitle is stored in *sub.
4085  * Note that CODEC_CAP_DR1 is not available for subtitle codecs. This is for
4086  * simplicity, because the performance difference is expect to be negligible
4087  * and reusing a get_buffer written for video codecs would probably perform badly
4088  * due to a potentially very different allocation pattern.
4089  *
4090  * @param avctx the codec context
4091  * @param[out] sub The AVSubtitle in which the decoded subtitle will be stored, must be
4092  freed with avsubtitle_free if *got_sub_ptr is set.
4093  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
4094  * @param[in] avpkt The input AVPacket containing the input buffer.
4095  */
4097  int *got_sub_ptr,
4098  AVPacket *avpkt);
4099 
4100 /**
4101  * @defgroup lavc_parsing Frame parsing
4102  * @{
4103  */
4105 typedef struct AVCodecParserContext {
4106  void *priv_data;
4107  struct AVCodecParser *parser;
4108  int64_t frame_offset; /* offset of the current frame */
4109  int64_t cur_offset; /* current offset
4110  (incremented by each av_parser_parse()) */
4111  int64_t next_frame_offset; /* offset of the next frame */
4112  /* video info */
4113  int pict_type; /* XXX: Put it back in AVCodecContext. */
4114  /**
4115  * This field is used for proper frame duration computation in lavf.
4116  * It signals, how much longer the frame duration of the current frame
4117  * is compared to normal frame duration.
4118  *
4119  * frame_duration = (1 + repeat_pict) * time_base
4120  *
4121  * It is used by codecs like H.264 to display telecined material.
4122  */
4123  int repeat_pict; /* XXX: Put it back in AVCodecContext. */
4124  int64_t pts; /* pts of the current frame */
4125  int64_t dts; /* dts of the current frame */
4126 
4127  /* private data */
4128  int64_t last_pts;
4129  int64_t last_dts;
4130  int fetch_timestamp;
4132 #define AV_PARSER_PTS_NB 4
4133  int cur_frame_start_index;
4134  int64_t cur_frame_offset[AV_PARSER_PTS_NB];
4135  int64_t cur_frame_pts[AV_PARSER_PTS_NB];
4136  int64_t cur_frame_dts[AV_PARSER_PTS_NB];
4138  int flags;
4139 #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
4140 #define PARSER_FLAG_ONCE 0x0002
4141 /// Set if the parser has a valid file offset
4142 #define PARSER_FLAG_FETCHED_OFFSET 0x0004
4143 #define PARSER_FLAG_USE_CODEC_TS 0x1000
4145  int64_t offset; ///< byte offset from starting packet start
4146  int64_t cur_frame_end[AV_PARSER_PTS_NB];
4147 
4148  /**
4149  * Set by parser to 1 for key frames and 0 for non-key frames.
4150  * It is initialized to -1, so if the parser doesn't set this flag,
4151  * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
4152  * will be used.
4153  */
4154  int key_frame;
4155 
4156  /**
4157  * Time difference in stream time base units from the pts of this
4158  * packet to the point at which the output from the decoder has converged
4159  * independent from the availability of previous frames. That is, the
4160  * frames are virtually identical no matter if decoding started from
4161  * the very first frame or from this keyframe.
4162  * Is AV_NOPTS_VALUE if unknown.
4163  * This field is not the display duration of the current frame.
4164  * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
4165  * set.
4166  *
4167  * The purpose of this field is to allow seeking in streams that have no
4168  * keyframes in the conventional sense. It corresponds to the
4169  * recovery point SEI in H.264 and match_time_delta in NUT. It is also
4170  * essential for some types of subtitle streams to ensure that all
4171  * subtitles are correctly displayed after seeking.
4172  */
4173  int64_t convergence_duration;
4174 
4175  // Timestamp generation support:
4176  /**
4177  * Synchronization point for start of timestamp generation.
4178  *
4179  * Set to >0 for sync point, 0 for no sync point and <0 for undefined
4180  * (default).
4181  *
4182  * For example, this corresponds to presence of H.264 buffering period
4183  * SEI message.
4184  */
4185  int dts_sync_point;
4186 
4187  /**
4188  * Offset of the current timestamp against last timestamp sync point in
4189  * units of AVCodecContext.time_base.
4190  *
4191  * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
4192  * contain a valid timestamp offset.
4193  *
4194  * Note that the timestamp of sync point has usually a nonzero
4195  * dts_ref_dts_delta, which refers to the previous sync point. Offset of
4196  * the next frame after timestamp sync point will be usually 1.
4197  *
4198  * For example, this corresponds to H.264 cpb_removal_delay.
4199  */
4200  int dts_ref_dts_delta;
4201 
4202  /**
4203  * Presentation delay of current frame in units of AVCodecContext.time_base.
4204  *
4205  * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
4206  * contain valid non-negative timestamp delta (presentation time of a frame
4207  * must not lie in the past).
4208  *
4209  * This delay represents the difference between decoding and presentation
4210  * time of the frame.
4211  *
4212  * For example, this corresponds to H.264 dpb_output_delay.
4213  */
4214  int pts_dts_delta;
4215 
4216  /**
4217  * Position of the packet in file.
4218  *
4219  * Analogous to cur_frame_pts/dts
4220  */
4221  int64_t cur_frame_pos[AV_PARSER_PTS_NB];
4222 
4223  /**
4224  * Byte position of currently parsed frame in stream.
4225  */
4226  int64_t pos;
4227 
4228  /**
4229  * Previous frame byte position.
4230  */
4231  int64_t last_pos;
4232 
4233  /**
4234  * Duration of the current frame.
4235  * For audio, this is in units of 1 / AVCodecContext.sample_rate.
4236  * For all other types, this is in units of AVCodecContext.time_base.
4237  */
4238  int duration;
4241 typedef struct AVCodecParser {
4242  int codec_ids[5]; /* several codec IDs are permitted */
4243  int priv_data_size;
4244  int (*parser_init)(AVCodecParserContext *s);
4245  int (*parser_parse)(AVCodecParserContext *s,
4246  AVCodecContext *avctx,
4247  const uint8_t **poutbuf, int *poutbuf_size,
4248  const uint8_t *buf, int buf_size);
4249  void (*parser_close)(AVCodecParserContext *s);
4250  int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
4251  struct AVCodecParser *next;
4252 } AVCodecParser;
4253 
4255 
4258 
4259 /**
4260  * Parse a packet.
4261  *
4262  * @param s parser context.
4263  * @param avctx codec context.
4264  * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished.
4265  * @param poutbuf_size set to size of parsed buffer or zero if not yet finished.
4266  * @param buf input buffer.
4267  * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output).
4268  * @param pts input presentation timestamp.
4269  * @param dts input decoding timestamp.
4270  * @param pos input byte position in stream.
4271  * @return the number of bytes of the input bitstream used.
4272  *
4273  * Example:
4274  * @code
4275  * while(in_len){
4276  * len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
4277  * in_data, in_len,
4278  * pts, dts, pos);
4279  * in_data += len;
4280  * in_len -= len;
4281  *
4282  * if(size)
4283  * decode_frame(data, size);
4284  * }
4285  * @endcode
4286  */
4288  AVCodecContext *avctx,
4289  uint8_t **poutbuf, int *poutbuf_size,
4290  const uint8_t *buf, int buf_size,
4291  int64_t pts, int64_t dts,
4292  int64_t pos);
4293 
4294 /**
4295  * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
4296  * @deprecated use AVBitstreamFilter
4297  */
4299  AVCodecContext *avctx,
4300  uint8_t **poutbuf, int *poutbuf_size,
4301  const uint8_t *buf, int buf_size, int keyframe);
4303 
4304 /**
4305  * @}
4306  * @}
4307  */
4308 
4309 /**
4310  * @addtogroup lavc_encoding
4311  * @{
4312  */
4313 
4314 /**
4315  * Find a registered encoder with a matching codec ID.
4316  *
4317  * @param id AVCodecID of the requested encoder
4318  * @return An encoder if one was found, NULL otherwise.
4319  */
4321 
4322 /**
4323  * Find a registered encoder with the specified name.
4324  *
4325  * @param name name of the requested encoder
4326  * @return An encoder if one was found, NULL otherwise.
4327  */
4329 
4330 #if FF_API_OLD_ENCODE_AUDIO
4331 /**
4332  * Encode an audio frame from samples into buf.
4333  *
4334  * @deprecated Use avcodec_encode_audio2 instead.
4335  *
4336  * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large.
4337  * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user
4338  * will know how much space is needed because it depends on the value passed
4339  * in buf_size as described below. In that case a lower value can be used.
4340  *
4341  * @param avctx the codec context
4342  * @param[out] buf the output buffer
4343  * @param[in] buf_size the output buffer size
4344  * @param[in] samples the input buffer containing the samples
4345  * The number of samples read from this buffer is frame_size*channels,
4346  * both of which are defined in avctx.
4347  * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of
4348  * samples read from samples is equal to:
4349  * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id))
4350  * This also implies that av_get_bits_per_sample() must not return 0 for these
4351  * codecs.
4352  * @return On error a negative value is returned, on success zero or the number
4353  * of bytes used to encode the data read from the input buffer.
4354  */
4355 int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx,
4356  uint8_t *buf, int buf_size,
4357  const short *samples);
4358 #endif
4359 
4360 /**
4361  * Encode a frame of audio.
4362  *
4363  * Takes input samples from frame and writes the next output packet, if
4364  * available, to avpkt. The output packet does not necessarily contain data for
4365  * the most recent frame, as encoders can delay, split, and combine input frames
4366  * internally as needed.
4367  *
4368  * @param avctx codec context
4369  * @param avpkt output AVPacket.
4370  * The user can supply an output buffer by setting
4371  * avpkt->data and avpkt->size prior to calling the
4372  * function, but if the size of the user-provided data is not
4373  * large enough, encoding will fail. If avpkt->data and
4374  * avpkt->size are set, avpkt->destruct must also be set. All
4375  * other AVPacket fields will be reset by the encoder using
4376  * av_init_packet(). If avpkt->data is NULL, the encoder will
4377  * allocate it. The encoder will set avpkt->size to the size
4378  * of the output packet.
4379  *
4380  * If this function fails or produces no output, avpkt will be
4381  * freed using av_free_packet() (i.e. avpkt->destruct will be
4382  * called to free the user supplied buffer).
4383  * @param[in] frame AVFrame containing the raw audio data to be encoded.
4384  * May be NULL when flushing an encoder that has the
4385  * CODEC_CAP_DELAY capability set.
4386  * If CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
4387  * can have any number of samples.
4388  * If it is not set, frame->nb_samples must be equal to
4389  * avctx->frame_size for all frames except the last.
4390  * The final frame may be smaller than avctx->frame_size.
4391  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
4392  * output packet is non-empty, and to 0 if it is
4393  * empty. If the function returns an error, the
4394  * packet can be assumed to be invalid, and the
4395  * value of got_packet_ptr is undefined and should
4396  * not be used.
4397  * @return 0 on success, negative error code on failure
4398  */
4399 int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
4400  const AVFrame *frame, int *got_packet_ptr);
4401 
4402 #if FF_API_OLD_ENCODE_VIDEO
4403 /**
4404  * @deprecated use avcodec_encode_video2() instead.
4405  *
4406  * Encode a video frame from pict into buf.
4407  * The input picture should be
4408  * stored using a specific format, namely avctx.pix_fmt.
4409  *
4410  * @param avctx the codec context
4411  * @param[out] buf the output buffer for the bitstream of encoded frame
4412  * @param[in] buf_size the size of the output buffer in bytes
4413  * @param[in] pict the input picture to encode
4414  * @return On error a negative value is returned, on success zero or the number
4415  * of bytes used from the output buffer.
4416  */
4418 int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
4419  const AVFrame *pict);
4420 #endif
4421 
4422 /**
4423  * Encode a frame of video.
4424  *
4425  * Takes input raw video data from frame and writes the next output packet, if
4426  * available, to avpkt. The output packet does not necessarily contain data for
4427  * the most recent frame, as encoders can delay and reorder input frames
4428  * internally as needed.
4429  *
4430  * @param avctx codec context
4431  * @param avpkt output AVPacket.
4432  * The user can supply an output buffer by setting
4433  * avpkt->data and avpkt->size prior to calling the
4434  * function, but if the size of the user-provided data is not
4435  * large enough, encoding will fail. All other AVPacket fields
4436  * will be reset by the encoder using av_init_packet(). If
4437  * avpkt->data is NULL, the encoder will allocate it.
4438  * The encoder will set avpkt->size to the size of the
4439  * output packet. The returned data (if any) belongs to the
4440  * caller, he is responsible for freeing it.
4441  *
4442  * If this function fails or produces no output, avpkt will be
4443  * freed using av_free_packet() (i.e. avpkt->destruct will be
4444  * called to free the user supplied buffer).
4445  * @param[in] frame AVFrame containing the raw video data to be encoded.
4446  * May be NULL when flushing an encoder that has the
4447  * CODEC_CAP_DELAY capability set.
4448  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
4449  * output packet is non-empty, and to 0 if it is
4450  * empty. If the function returns an error, the
4451  * packet can be assumed to be invalid, and the
4452  * value of got_packet_ptr is undefined and should
4453  * not be used.
4454  * @return 0 on success, negative error code on failure
4455  */
4456 int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt,
4457  const AVFrame *frame, int *got_packet_ptr);
4458 
4459 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
4460  const AVSubtitle *sub);
4461 
4462 
4463 /**
4464  * @}
4465  */
4466 
4467 #if FF_API_AVCODEC_RESAMPLE
4468 /**
4469  * @defgroup lavc_resample Audio resampling
4470  * @ingroup libavc
4471  * @deprecated use libswresample instead
4472  *
4473  * @{
4474  */
4475 struct ReSampleContext;
4476 struct AVResampleContext;
4477 
4478 typedef struct ReSampleContext ReSampleContext;
4479 
4480 /**
4481  * Initialize audio resampling context.
4482  *
4483  * @param output_channels number of output channels
4484  * @param input_channels number of input channels
4485  * @param output_rate output sample rate
4486  * @param input_rate input sample rate
4487  * @param sample_fmt_out requested output sample format
4488  * @param sample_fmt_in input sample format
4489  * @param filter_length length of each FIR filter in the filterbank relative to the cutoff frequency
4490  * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
4491  * @param linear if 1 then the used FIR filter will be linearly interpolated
4492  between the 2 closest, if 0 the closest will be used
4493  * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
4494  * @return allocated ReSampleContext, NULL if error occurred
4495  */
4497 ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
4498  int output_rate, int input_rate,
4499  enum AVSampleFormat sample_fmt_out,
4500  enum AVSampleFormat sample_fmt_in,
4501  int filter_length, int log2_phase_count,
4502  int linear, double cutoff);
4503 
4505 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
4506 
4507 /**
4508  * Free resample context.
4509  *
4510  * @param s a non-NULL pointer to a resample context previously
4511  * created with av_audio_resample_init()
4512  */
4514 void audio_resample_close(ReSampleContext *s);
4515 
4516 
4517 /**
4518  * Initialize an audio resampler.
4519  * Note, if either rate is not an integer then simply scale both rates up so they are.
4520  * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq
4521  * @param log2_phase_count log2 of the number of entries in the polyphase filterbank
4522  * @param linear If 1 then the used FIR filter will be linearly interpolated
4523  between the 2 closest, if 0 the closest will be used
4524  * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate
4525  */
4527 struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff);
4528 
4529 /**
4530  * Resample an array of samples using a previously configured context.
4531  * @param src an array of unconsumed samples
4532  * @param consumed the number of samples of src which have been consumed are returned here
4533  * @param src_size the number of unconsumed samples available
4534  * @param dst_size the amount of space in samples available in dst
4535  * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
4536  * @return the number of samples written in dst or -1 if an error occurred
4537  */
4539 int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx);
4540 
4541 
4542 /**
4543  * Compensate samplerate/timestamp drift. The compensation is done by changing
4544  * the resampler parameters, so no audible clicks or similar distortions occur
4545  * @param compensation_distance distance in output samples over which the compensation should be performed
4546  * @param sample_delta number of output samples which should be output less
4547  *
4548  * example: av_resample_compensate(c, 10, 500)
4549  * here instead of 510 samples only 500 samples would be output
4550  *
4551  * note, due to rounding the actual compensation might be slightly different,
4552  * especially if the compensation_distance is large and the in_rate used during init is small
4553  */
4555 void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance);
4557 void av_resample_close(struct AVResampleContext *c);
4558 
4559 /**
4560  * @}
4561  */
4562 #endif
4563 
4564 /**
4565  * @addtogroup lavc_picture
4566  * @{
4567  */
4568 
4569 /**
4570  * Allocate memory for a picture. Call avpicture_free() to free it.
4571  *
4572  * @see avpicture_fill()
4573  *
4574  * @param picture the picture to be filled in
4575  * @param pix_fmt the format of the picture
4576  * @param width the width of the picture
4577  * @param height the height of the picture
4578  * @return zero if successful, a negative value if not
4579  */
4580 int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height);
4581 
4582 /**
4583  * Free a picture previously allocated by avpicture_alloc().
4584  * The data buffer used by the AVPicture is freed, but the AVPicture structure
4585  * itself is not.
4586  *
4587  * @param picture the AVPicture to be freed
4588  */
4589 void avpicture_free(AVPicture *picture);
4590 
4591 /**
4592  * Fill in the AVPicture fields, always assume a linesize alignment of
4593  * 1.
4594  *
4595  * @see av_image_fill_arrays()
4596  */
4597 int avpicture_fill(AVPicture *picture, const uint8_t *ptr,
4598  enum AVPixelFormat pix_fmt, int width, int height);
4599 
4600 /**
4601  * Copy pixel data from an AVPicture into a buffer, always assume a
4602  * linesize alignment of 1.
4603  *
4604  * @see av_image_copy_to_buffer()
4605  */
4606 int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt,
4607  int width, int height,
4608  unsigned char *dest, int dest_size);
4609 
4610 /**
4611  * Calculate the size in bytes that a picture of the given width and height
4612  * would occupy if stored in the given picture format.
4613  * Always assume a linesize alignment of 1.
4614  *
4615  * @see av_image_get_buffer_size().
4616  */
4618 
4619 #if FF_API_DEINTERLACE
4620 /**
4621  * deinterlace - if not supported return -1
4622  *
4623  * @deprecated - use yadif (in libavfilter) instead
4624  */
4626 int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
4627  enum AVPixelFormat pix_fmt, int width, int height);
4628 #endif
4629 /**
4630  * Copy image src to dst. Wraps av_image_copy().
4631  */
4632 void av_picture_copy(AVPicture *dst, const AVPicture *src,
4633  enum AVPixelFormat pix_fmt, int width, int height);
4634 
4635 /**
4636  * Crop image top and left side.
4637  */
4638 int av_picture_crop(AVPicture *dst, const AVPicture *src,
4639  enum AVPixelFormat pix_fmt, int top_band, int left_band);
4640 
4641 /**
4642  * Pad image.
4643  */
4644 int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum AVPixelFormat pix_fmt,
4645  int padtop, int padbottom, int padleft, int padright, int *color);
4646 
4647 /**
4648  * @}
4649  */
4650 
4651 /**
4652  * @defgroup lavc_misc Utility functions
4653  * @ingroup libavc
4654  *
4655  * Miscellaneous utility functions related to both encoding and decoding
4656  * (or neither).
4657  * @{
4658  */
4659 
4660 /**
4661  * @defgroup lavc_misc_pixfmt Pixel formats
4662  *
4663  * Functions for working with pixel formats.
4664  * @{
4665  */
4666 
4667 /**
4668  * Utility function to access log2_chroma_w log2_chroma_h from
4669  * the pixel format AVPixFmtDescriptor.
4670  *
4671  * This function asserts that pix_fmt is valid. See av_pix_fmt_get_chroma_sub_sample
4672  * for one that returns a failure code and continues in case of invalid
4673  * pix_fmts.
4674  *
4675  * @param[in] pix_fmt the pixel format
4676  * @param[out] h_shift store log2_chroma_h
4677  * @param[out] v_shift store log2_chroma_w
4678  *
4679  * @see av_pix_fmt_get_chroma_sub_sample
4680  */
4681 
4682 void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift);
4683 
4684 /**
4685  * Return a value representing the fourCC code associated to the
4686  * pixel format pix_fmt, or 0 if no associated fourCC code can be
4687  * found.
4688  */
4691 #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */
4692 #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */
4693 #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */
4694 #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */
4695 #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */
4696 #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */
4697 
4698 /**
4699  * Compute what kind of losses will occur when converting from one specific
4700  * pixel format to another.
4701  * When converting from one pixel format to another, information loss may occur.
4702  * For example, when converting from RGB24 to GRAY, the color information will
4703  * be lost. Similarly, other losses occur when converting from some formats to
4704  * other formats. These losses can involve loss of chroma, but also loss of
4705  * resolution, loss of color depth, loss due to the color space conversion, loss
4706  * of the alpha bits or loss due to color quantization.
4707  * avcodec_get_fix_fmt_loss() informs you about the various types of losses
4708  * which will occur when converting from one pixel format to another.
4709  *
4710  * @param[in] dst_pix_fmt destination pixel format
4711  * @param[in] src_pix_fmt source pixel format
4712  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
4713  * @return Combination of flags informing you what kind of losses will occur
4714  * (maximum loss for an invalid dst_pix_fmt).
4715  */
4716 int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
4717  int has_alpha);
4718 
4719 #if FF_API_FIND_BEST_PIX_FMT
4720 /**
4721  * @deprecated use avcodec_find_best_pix_fmt_of_2() instead.
4722  *
4723  * Find the best pixel format to convert to given a certain source pixel
4724  * format. When converting from one pixel format to another, information loss
4725  * may occur. For example, when converting from RGB24 to GRAY, the color
4726  * information will be lost. Similarly, other losses occur when converting from
4727  * some formats to other formats. avcodec_find_best_pix_fmt() searches which of
4728  * the given pixel formats should be used to suffer the least amount of loss.
4729  * The pixel formats from which it chooses one, are determined by the
4730  * pix_fmt_mask parameter.
4731  *
4732  * Note, only the first 64 pixel formats will fit in pix_fmt_mask.
4733  *
4734  * @code
4735  * src_pix_fmt = AV_PIX_FMT_YUV420P;
4736  * pix_fmt_mask = (1 << AV_PIX_FMT_YUV422P) | (1 << AV_PIX_FMT_RGB24);
4737  * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss);
4738  * @endcode
4739  *
4740  * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from
4741  * @param[in] src_pix_fmt source pixel format
4742  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
4743  * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
4744  * @return The best pixel format to convert to or -1 if none was found.
4745  */
4747 enum AVPixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum AVPixelFormat src_pix_fmt,
4748  int has_alpha, int *loss_ptr);
4749 #endif /* FF_API_FIND_BEST_PIX_FMT */
4750 
4751 /**
4752  * Find the best pixel format to convert to given a certain source pixel
4753  * format. When converting from one pixel format to another, information loss
4754  * may occur. For example, when converting from RGB24 to GRAY, the color
4755  * information will be lost. Similarly, other losses occur when converting from
4756  * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of
4757  * the given pixel formats should be used to suffer the least amount of loss.
4758  * The pixel formats from which it chooses one, are determined by the
4759  * pix_fmt_list parameter.
4760  *
4761  *
4762  * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
4763  * @param[in] src_pix_fmt source pixel format
4764  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
4765  * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
4766  * @return The best pixel format to convert to or -1 if none was found.
4767  */
4769  enum AVPixelFormat src_pix_fmt,
4770  int has_alpha, int *loss_ptr);
4771 
4772 /**
4773  * Find the best pixel format to convert to given a certain source pixel
4774  * format and a selection of two destination pixel formats. When converting from
4775  * one pixel format to another, information loss may occur. For example, when converting
4776  * from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when
4777  * converting from some formats to other formats. avcodec_find_best_pix_fmt_of_2() selects which of
4778  * the given pixel formats should be used to suffer the least amount of loss.
4779  *
4780  * If one of the destination formats is AV_PIX_FMT_NONE the other pixel format (if valid) will be
4781  * returned.
4782  *
4783  * @code
4784  * src_pix_fmt = AV_PIX_FMT_YUV420P;
4785  * dst_pix_fmt1= AV_PIX_FMT_RGB24;
4786  * dst_pix_fmt2= AV_PIX_FMT_GRAY8;
4787  * dst_pix_fmt3= AV_PIX_FMT_RGB8;
4788  * loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored.
4789  * dst_pix_fmt = avcodec_find_best_pix_fmt_of_2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss);
4790  * dst_pix_fmt = avcodec_find_best_pix_fmt_of_2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss);
4791  * @endcode
4792  *
4793  * @param[in] dst_pix_fmt1 One of the two destination pixel formats to choose from
4794  * @param[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from
4795  * @param[in] src_pix_fmt Source pixel format
4796  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
4797  * @param[in, out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e.
4798  * NULL or value of zero means we care about all losses. Out: the loss
4799  * that occurs when converting from src to selected dst pixel format.
4800  * @return The best pixel format to convert to or -1 if none was found.
4801  */
4802 enum AVPixelFormat avcodec_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
4803  enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
4804 
4806 #if AV_HAVE_INCOMPATIBLE_FORK_ABI
4808  enum AVPixelFormat src_pix_fmt,
4809  int has_alpha, int *loss_ptr);
4810 #else
4811 enum AVPixelFormat avcodec_find_best_pix_fmt2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2,
4812  enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr);
4813 #endif
4814 
4815 
4817 
4818 /**
4819  * @}
4820  */
4821 
4823 
4824 /**
4825  * Put a string representing the codec tag codec_tag in buf.
4826  *
4827  * @param buf_size size in bytes of buf
4828  * @return the length of the string that would have been generated if
4829  * enough space had been available, excluding the trailing null
4830  */
4831 size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag);
4832 
4833 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
4834 
4835 /**
4836  * Return a name for the specified profile, if available.
4837  *
4838  * @param codec the codec that is searched for the given profile
4839  * @param profile the profile value for which a name is requested
4840  * @return A name for the profile if found, NULL otherwise.
4841  */
4842 const char *av_get_profile_name(const AVCodec *codec, int profile);
4843 
4844 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
4845 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
4846 //FIXME func typedef
4847 
4848 /**
4849  * Fill AVFrame audio data and linesize pointers.
4850  *
4851  * The buffer buf must be a preallocated buffer with a size big enough
4852  * to contain the specified samples amount. The filled AVFrame data
4853  * pointers will point to this buffer.
4854  *
4855  * AVFrame extended_data channel pointers are allocated if necessary for
4856  * planar audio.
4857  *
4858  * @param frame the AVFrame
4859  * frame->nb_samples must be set prior to calling the
4860  * function. This function fills in frame->data,
4861  * frame->extended_data, frame->linesize[0].
4862  * @param nb_channels channel count
4863  * @param sample_fmt sample format
4864  * @param buf buffer to use for frame data
4865  * @param buf_size size of buffer
4866  * @param align plane size sample alignment (0 = default)
4867  * @return >=0 on success, negative error code on failure
4868  * @todo return the size in bytes required to store the samples in
4869  * case of success, at the next libavutil bump
4870  */
4872  enum AVSampleFormat sample_fmt, const uint8_t *buf,
4873  int buf_size, int align);
4874 
4875 /**
4876  * Flush buffers, should be called when seeking or when switching to a different stream.
4877  */
4879 
4881 
4882 /**
4883  * Return codec bits per sample.
4884  *
4885  * @param[in] codec_id the codec
4886  * @return Number of bits per sample or zero if unknown for the given codec.
4887  */
4889 
4890 /**
4891  * Return the PCM codec associated with a sample format.
4892  * @param be endianness, 0 for little, 1 for big,
4893  * -1 (or anything else) for native
4894  * @return AV_CODEC_ID_PCM_* or AV_CODEC_ID_NONE
4895  */
4896 enum AVCodecID av_get_pcm_codec(enum AVSampleFormat fmt, int be);
4897 
4898 /**
4899  * Return codec bits per sample.
4900  * Only return non-zero if the bits per sample is exactly correct, not an
4901  * approximation.
4902  *
4903  * @param[in] codec_id the codec
4904  * @return Number of bits per sample or zero if unknown for the given codec.
4905  */
4907 
4908 /**
4909  * Return audio frame duration.
4910  *
4911  * @param avctx codec context
4912  * @param frame_bytes size of the frame, or 0 if unknown
4913  * @return frame duration, in samples, if known. 0 if not able to
4914  * determine.
4915  */
4916 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
4917 
4920  void *priv_data;
4925 
4927 typedef struct AVBitStreamFilter {
4928  const char *name;
4929  int priv_data_size;
4930  int (*filter)(AVBitStreamFilterContext *bsfc,
4931  AVCodecContext *avctx, const char *args,
4932  uint8_t **poutbuf, int *poutbuf_size,
4933  const uint8_t *buf, int buf_size, int keyframe);
4935  struct AVBitStreamFilter *next;
4937 
4941  AVCodecContext *avctx, const char *args,
4942  uint8_t **poutbuf, int *poutbuf_size,
4943  const uint8_t *buf, int buf_size, int keyframe);
4945 
4947 
4948 /* memory */
4949 
4950 /**
4951  * Reallocate the given block if it is not large enough, otherwise do nothing.
4952  *
4953  * @see av_realloc
4954  */
4955 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
4956 
4957 /**
4958  * Allocate a buffer, reusing the given one if large enough.
4959  *
4960  * Contrary to av_fast_realloc the current buffer contents might not be
4961  * preserved and on error the old buffer is freed, thus no special
4962  * handling to avoid memleaks is necessary.
4963  *
4964  * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
4965  * @param size size of the buffer *ptr points to
4966  * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
4967  * *size 0 if an error occurred.
4968  */
4969 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
4970 
4971 /**
4972  * Same behaviour av_fast_malloc but the buffer has additional
4973  * FF_INPUT_BUFFER_PADDING_SIZE at the end which will will always be 0.
4974  *
4975  * In addition the whole buffer will initially and after resizes
4976  * be 0-initialized so that no uninitialized data will ever appear.
4977  */
4978 void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
4979 
4980 /**
4981  * Same behaviour av_fast_padded_malloc except that buffer will always
4982  * be 0-initialized after call.
4983  */
4984 void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
4985 
4986 /**
4987  * Encode extradata length to a buffer. Used by xiph codecs.
4988  *
4989  * @param s buffer to write to; must be at least (v/255+1) bytes long
4990  * @param v size of extradata in bytes
4991  * @return number of bytes written to the buffer.
4992  */
4993 unsigned int av_xiphlacing(unsigned char *s, unsigned int v);
4994 
4995 /**
4996  * Log a generic warning message about a missing feature. This function is
4997  * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
4998  * only, and would normally not be used by applications.
4999  * @param[in] avc a pointer to an arbitrary struct of which the first field is
5000  * a pointer to an AVClass struct
5001  * @param[in] feature string containing the name of the missing feature
5002  * @param[in] want_sample indicates if samples are wanted which exhibit this feature.
5003  * If want_sample is non-zero, additional verbage will be added to the log
5004  * message which tells the user how to report samples to the development
5005  * mailing list.
5006  */
5007 void av_log_missing_feature(void *avc, const char *feature, int want_sample);
5008 
5009 /**
5010  * Log a generic warning message asking for a sample. This function is
5011  * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.)
5012  * only, and would normally not be used by applications.
5013  * @param[in] avc a pointer to an arbitrary struct of which the first field is
5014  * a pointer to an AVClass struct
5015  * @param[in] msg string containing an optional message, or NULL if no message
5016  */
5017 void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3);
5018 
5019 /**
5020  * Register the hardware accelerator hwaccel.
5021  */
5023 
5024 /**
5025  * If hwaccel is NULL, returns the first registered hardware accelerator,
5026  * if hwaccel is non-NULL, returns the next registered hardware accelerator
5027  * after hwaccel, or NULL if hwaccel is the last one.
5028  */
5030 
5031 
5032 /**
5033  * Lock operation used by lockmgr
5034  */
5035 enum AVLockOp {
5036  AV_LOCK_CREATE, ///< Create a mutex
5037  AV_LOCK_OBTAIN, ///< Lock the mutex
5038  AV_LOCK_RELEASE, ///< Unlock the mutex
5039  AV_LOCK_DESTROY, ///< Free mutex resources
5040 };
5041 
5042 /**
5043  * Register a user provided lock manager supporting the operations
5044  * specified by AVLockOp. mutex points to a (void *) where the
5045  * lockmgr should store/get a pointer to a user allocated mutex. It's
5046  * NULL upon AV_LOCK_CREATE and != NULL for all other ops.
5047  *
5048  * @param cb User defined callback. Note: FFmpeg may invoke calls to this
5049  * callback during the call to av_lockmgr_register().
5050  * Thus, the application must be prepared to handle that.
5051  * If cb is set to NULL the lockmgr will be unregistered.
5052  * Also note that during unregistration the previously registered
5053  * lockmgr callback may also be invoked.
5054  */
5055 int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op));
5056 
5057 /**
5058  * Get the type of the given codec.
5059  */
5061 
5062 /**
5063  * Get the name of a codec.
5064  * @return a static string identifying the codec; never NULL
5065  */
5066 const char *avcodec_get_name(enum AVCodecID id);
5067 
5068 /**
5069  * @return a positive value if s is open (i.e. avcodec_open2() was called on it
5070  * with no corresponding avcodec_close()), 0 otherwise.
5071  */
5073 
5074 /**
5075  * @return a non-zero number if codec is an encoder, zero otherwise
5076  */
5077 int av_codec_is_encoder(const AVCodec *codec);
5078 
5079 /**
5080  * @return a non-zero number if codec is a decoder, zero otherwise
5081  */
5082 int av_codec_is_decoder(const AVCodec *codec);
5083 
5084 /**
5085  * @return descriptor for given codec ID or NULL if no descriptor exists.
5086  */
5088 
5089 /**
5090  * Iterate over all codec descriptors known to libavcodec.
5091  *
5092  * @param prev previous descriptor. NULL to get the first descriptor.
5093  *
5094  * @return next descriptor or NULL after the last descriptor
5095  */
5097 
5098 /**
5099  * @return codec descriptor with the given name or NULL if no such descriptor
5100  * exists.
5101  */
5103 
5104 /**
5105  * @}
5106  */
5107 
5108 #endif /* AVCODEC_AVCODEC_H */